在Apache的POI设置列宽 [英] Setting Column width in Apache POI

查看:159
本文介绍了在Apache的POI设置列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写使用Apache POI API转换为XML到MS Excel在java中的一个工具。在我输入XML我收到分列的宽度。但在Apache POI API有根据字体大小等设置列宽略有奇怪的逻辑(参见<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html#setColumnWidth%28int,%20int%29\">API文档)

I m writing a tool in java using Apache POI api to convert an xml to MS Excel. In my input xml I receive the column width in points. But the Apache POI api has a slightly queer logic for setting column width based on font size etc. (refer API docs)

有没有用Excel作为预期转换点宽度的公式?有没有人这样做过?

Is there any formula for converting points to the width as expected by Excel? Has any one done this before?

有一个setRowHeightInPoints()方法,虽然:(但没有列。

There is a setRowHeightInPoints() method though :( but none for column.

P.S:输入XML是ExcelML格式,我必须转换到MS Excel

P.S.: The input xml is in ExcelML format which i have to convert to MS Excel

推荐答案

不幸的是,只有功能<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Sheet.html#setColumnWidth%28int,%20int%29\"相对=nofollow> setColumnWidth(INT参数:columnIndex,
                    int width)将来自类表 ;其中宽度为多位的标准字体(在工作簿中第一个字体)的,如果你的字体变化,你不能使用它的字符。
有解释如何计算字体大小的功能宽度。其计算公式为:

Unfortunately there is only the function setColumnWidth(int columnIndex, int width) from class Sheet; in which width is a number of characters in the standard font (first font in the workbook) if your fonts are changing you cannot use it. There is explained how to calculate the width in function of a font size. The formula is:

width = Truncate([{NumOfVisibleChar} * {MaxDigitWidth} + {5PixelPadding}] / {MaxDigitWidth}*256) / 256

您可以随时使用<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Sheet.html#autoSizeColumn(int,%20boolean)\"相对=nofollow> autoSizeColumn(INT列,布尔useMergedCells)表输入数据后

希望它帮助。

这篇关于在Apache的POI设置列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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