在使用NPOI创建的Excel文档中如何将列设置为“自动调整”? [英] How can columns be set to 'autosize' in Excel documents created with NPOI?

查看:451
本文介绍了在使用NPOI创建的Excel文档中如何将列设置为“自动调整”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NPOI 是Java POI项目的.NET端口,允许用户读取和写入Microsoft Excel文件(以及其他Office格式)。 NPOI 1.2.2引入了对自动调整列的支持,其中列被设置为列中最宽的单元格条目的宽度。但是,有很多报告说这不行。那么可以吗?

NPOI is a .NET port of the Java POI project, which allows one to read and write Microsoft Excel documents (as well as other Office formats). NPOI 1.2.2 has introduced support for 'autosizing' columns, whereby the column is set to the width of the widest cell entry in the column. However, there are many reports that this does not work. So is it possible?

推荐答案

我已经发布了这个只是为了回答它,以便提供一个记录。它可以使用NPOI自动调整列,但是您必须将列中的所有数据添加到列中,而不是以行的形式添加。一旦所有的单元格都添加到列columnIndex列中,然后调用

I've posted this just to answer it, so as to provide a record. It is possible to make columns autosized using NPOI, but you have to add all the data in columns, rather than in rows. Once all the cells have been added to a column @ columnIndex you then call

mySheet.AutoSizeColumn(columnIndex)

并转到下一列。我没有找到任何其他方法来使此功能正常工作。

and move to the next column. I have found no other way to make this functionality work.

这篇关于在使用NPOI创建的Excel文档中如何将列设置为“自动调整”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆