小编snu*_*rre的帖子

使用xlrd读取excel文件

我在读取由我无法控制的Perl脚本编写的.xls文件时遇到问题.这些文件包含单元格内的一些格式和换行符.

filename = '/home/shared/testfile.xls'
book = xlrd.open_workbook(filename)
sheet = book.sheet_by_index(0)
for rowIndex in xrange(1, sheet.nrows):
    row = sheet.row(rowIndex)
Run Code Online (Sandbox Code Playgroud)

这会引发以下错误:

_locate_stream(Workbook): seen
    0  5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
   20  4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
172480= 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 …
Run Code Online (Sandbox Code Playgroud)

python excel xlrd

9
推荐指数
5
解决办法
9481
查看次数

当源对象可能没有给定属性时如何处理绑定?

我有两个具有不同属性的类,但都继承了其他一些基类:

public class BaseClass { }

public class ClassA : BaseClass
{
    public string PropertyA { get; set; }
}

public class ClassB : BaseClass
{
    public string PropertyB { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

代码隐藏:

public ObservableCollection<BaseClass> Items { get; set; }

public MainWindow()
{
    Items = new ObservableCollection<BaseClass>
        {
            new ClassA {PropertyA = "A"},
            new ClassB {PropertyB = "B"}
        };
}
Run Code Online (Sandbox Code Playgroud)

我的XAML看起来像这样:

<ListView ItemsSource="{Binding Items}">
    <ListView.View>
        <GridView>
            <GridViewColumn DisplayMemberBinding="{Binding PropertyA, FallbackValue=''}"/>
            <GridViewColumn DisplayMemberBinding="{Binding PropertyB, FallbackValue={x:Null}}"/>
        </GridView>
    </ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)

在调试模式下运行时,输出窗口显示: …

c# wpf binding fallbackvalue

7
推荐指数
1
解决办法
4133
查看次数

WPF ListView:对齐选定列中的文本

<ListView ItemsSource="{Binding MyData}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="col1" DisplayMemberBinding="{Binding Path=value1}">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <TextBlock TextAlignment="Right" Text="{Binding Path=value1}"/>
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn Header="col2">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <TextBlock TextAlignment="Center" Text="{Binding Path=value2}"/>
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn Header="col3" DisplayMemberBinding="{Binding Path=value3}"/>
    </GridView>
  </ListView.View>
<ListView ItemsSource="{Binding MyData}">
Run Code Online (Sandbox Code Playgroud)

col1应该是右对齐的.(不工作)
col2应该是居中对齐的.(工作)
col3应该是左对齐的.(工作)

DisplayMemberBinding是否有理由重写CellTemplate?如果是这样,是否有一个修复(仍然使用DisplayMemberBinding)?

编辑:我结束了实施像这样:

<Window xmlns:util="clr-namespace:TestProject.Util">
  <Window.Resources>
    <Style TargetType="ListViewItem">
      <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
    <Style TargetType="GridViewColumnHeader">
      <Setter Property="HorizontalContentAlignment" Value="Left"/>
    </Style>
    <DataTemplate x:Key="value1Template">
      <TextBlock TextAlignment="Right" Text="{Binding Path=value1}"/>
    </DataTemplate>
    <DataTemplate x:Key="value2Template">
      <TextBlock TextAlignment="Right" Text="{Binding Path=value2}"/>
    </DataTemplate>
  </Window.Resources>
  <Grid>
    <ListView ItemsSource="{Binding MyData}" IsSynchronizedWithCurrentItem="True" …
Run Code Online (Sandbox Code Playgroud)

c# wpf listview gridview

5
推荐指数
1
解决办法
9745
查看次数

标签 统计

c# ×2

wpf ×2

binding ×1

excel ×1

fallbackvalue ×1

gridview ×1

listview ×1

python ×1

xlrd ×1