设置Apache POI中的列宽 [英] Setting Column width in Apache POI
问题描述
是否有一个公式将点转换为Excel预期的宽度?有没有人这样做?
有一个 setRowHeightInPoints()
方法虽然:(但没有列。 / p>
PS:输入的XML是ExcelML格式,我必须转换为MS Excel。
不幸的是,只有函数 class Sheet 的%29rel =noreferrer> setColumnWidth(int columnIndex,
int width);其中宽度是多个字符在标准字体(工作簿中的第一个字体)中,如果您的字体正在更改,则无法使用。
解释了如何计算字体大小的函数宽度,公式为:$ {pre $ p $ width = 256
您可以随时使用 autoSizeColumn(int column,boolean useMergedCells)
输入表格中的数据
。
希望有帮助。 / p>
I am writing a tool in Java using Apache POI API to convert an XML to MS Excel. In my XML input, 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)
Is there a formula for converting points to the width as expected by Excel? Has anyone done this before?
There is a setRowHeightInPoints()
method though :( but none for column.
P.S.: The input XML is in ExcelML format which I have to convert to MS Excel.
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
You can always use autoSizeColumn(int column, boolean useMergedCells)
after inputting the data in your Sheet
.
Hope it helped.
这篇关于设置Apache POI中的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!