开发者

Is it possible to set the column width for a XSSF worksheet using Apache POI API?

I need to generate a MS Excel 2007+ file from my application according to a given pattern provided by management. Most of the work is done, but I have to set the column width to 11,34 centimeters. I开发者_C百科 tried to use the setColumnWidth(int columnIndex, int width) method, but regardless of the value I provide it does not work. JavaDoc says:

Set the width (in units of 1/256th of a character width)

The maximum column width for an individual cell is 255 characters. This value represents the number of characters that can be displayed in a cell that is formatted with the standard font.

How to do this?


Ok, I think I understand your problem now, your business requirements state that you must set the width of the column based on standard Excel font character width.

The way I would approach this would be to use the Print Screen key on an example in Excel, then paste into Paint or a similar program and count pixel width. I would then use the ruler tool to measure pixels/cm and use the resulting number as my fixed column width.

This will probably involve a little bit of trial and error to get right.

Now with that said I will share my personal opinion that I feel this a LAZY and WEAK business requirement. What is "standard font"? Which version of Excel? This requirement is open to entirely too much developer interpretation.


Actually, I was mistaken from the very beggining! My (terrible!) bad! Width columns were already being set, but thought not! All it took as a simple "rule of three" and I was set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜