NPOI是Java POI项目的.NET端口,允许用户读取和写入Microsoft Excel文档(以及其他Office格式).NPOI 1.2.2引入了对"自动调整大小"列的支持,其中列设置为列中最宽单元格条目的宽度.但是,有许多报道说这不起作用.那有可能吗?
Yel*_*fog 30
我发布这个只是为了回答它,以便提供一个记录.这是可能使使用NPOI自动调整大小列,但你要添加的所有数据列,而不是行.将所有单元格添加到@ columnIndex列后,然后调用
mySheet.AutoSizeColumn(columnIndex)
Run Code Online (Sandbox Code Playgroud)
并转到下一列.我找不到其他方法来使这个功能工作.
小智 5
正如 Yellowfog 已经指出的那样,以下将起作用
mySheet.AutoSizeColumn(columnIndex)
Run Code Online (Sandbox Code Playgroud)
然而,帖子中出现了一些歧义。这似乎是一种只有在您完成输入数据、样式等之后才有效的方法。这样就可以了
ISheet mySheet = hssfworkbook.CreateSheet("sheet1");
IRow row = mySheet.CreateRow(0);
ICell cell = row.CreateCell(0);
cell.SetCellValue("foo");
mySheet.AutoSizeColumn(0);
Run Code Online (Sandbox Code Playgroud)
但以下将不起作用(因为它没有自动调整大小的信息)
ISheet mySheet = hssfworkbook.CreateSheet("sheet1");
mySheet.AutoSizeColumn(0);
IRow row = mySheet.CreateRow(0);
ICell cell = row.CreateCell(0);
cell.SetCellValue("foo");
Run Code Online (Sandbox Code Playgroud)