/// <summary>
/// 设置表页的列宽度自适应
/// </summary>
/// <param name="sheet">worksheet对象</param>
void setColumnWithAuto(Worksheet sheet)
{
Cells cells = sheet.Cells;
int columnCount = cells.MaxColumn; //获取表页的最大列数
int rowCount = cells.MaxRow; //获取表页的最大行数 for (int col = ; col < columnCount; col++)
{
sheet.AutoFitColumn(col, , rowCount);
}
for (int col = ; col < columnCount; col++)
{
cells.SetColumnWidthPixel(col, cells.GetColumnWidthPixel(col) + );
}
}

在调用Aspose.Cells的过程中,开始的时候以为sheet.Cells.Rows.Count获取到的是表页的总行数,这样在循环的时候就可以作为上限,结果用这个属性获取到的值是0,很奇怪,这个属性获取到的值是错误的,于是试着用其他方法获取总行数.用了一些折中的方法,解决了问题,后来在使用时候发现了

cells.MaxRow这个属性能获取到最大的行数,这个行数跟总行数的值应该是一样的.

cells.MaxDataRow;获取到的是最大的数据行(有数据的行的最大值--这个属性解释起来比较麻烦,慢慢理解一下)
112233445566778899    
          
 
cells.MaxRow的值是2;
cells.MaxDataRow的值是1;
对于列也有同样的属性可以调用.
 
04-23 07:16
查看更多