当前位置:   article > 正文

NPOI导出Excel时文件格式出错!The maximum column width for an individual cell is 255 characters._nopi的the maximum column width for an individual ce

nopi的the maximum column width for an individual cell is 255 characters

                                由于列宽ColumnWidth的限制,导致导出的Excel文件格式出错无法打开,需要进行列宽的判断调整。

  1.                                 foreach (DataColumn column in dtSource.Columns)
  2. {
  3. headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
  4. headerRow.GetCell(column.Ordinal).CellStyle = headStyle;
  5. //设置列宽
  6. //sheet.SetColumnWidth(column.Ordinal, (arrColWidth[column.Ordinal] + 1) * 256);
  7. int colWidth = (arrColWidth[column.Ordinal] + 1) * 256;
  8. if (colWidth < 255 * 256)
  9. {
  10. sheet.SetColumnWidth(column.Ordinal, colWidth < 3000 ? 3000 : colWidth);
  11. }
  12. else
  13. {
  14. sheet.SetColumnWidth(column.Ordinal, 6000);
  15. }
  16. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/216096
推荐阅读
相关标签
  

闽ICP备14008679号