Aspose.Cells设置自动列宽(最佳列宽)及一些方法总结

        /// <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 = 0; col < columnCount; col++)
            {
                sheet.AutoFitColumn(col, 0, rowCount);
            }
            for (int col = 0; col < columnCount; col++)
            {
                cells.SetColumnWidthPixel(col, cells.GetColumnWidthPixel(col) + 30);
            }
        }

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

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

cells.MaxDataRow;获取到的是最大的数据行(有数据的行的最大值--这个属性解释起来比较麻烦,慢慢理解一下)

11 22 33 44 55 66 77 88 99     
                   
 
cells.MaxRow的值是2;
cells.MaxDataRow的值是1;
对于列也有同样的属性可以调用.
 
原文地址:https://www.cnblogs.com/kdkler/p/4508134.html