I'm using JXLS 2.3.0 with apache poi implementation.
And I use following code to create excel :
try{
InputStream is = ObjectCollectionDemo.class.getResourceAsStream("/template.xls")
OutputStream os = new FileOutputStream("target/output.xls")
Context context = new Context();
context.putVar("employees", employees);
JxlsHelper.getInstance().processTemplate(is, os, context);
}
my generated excel file looks like next :
As above screenshot shows, the first 'Name' value only display partial.
But what I want is :
That is the content in excel cell can be wrapped and the row height can auto fit the cell content.
How can I do that? Thanks in advance.
-------------- Updated -----------------
the solution is:
wrap text
in your template filewe can found that the }
of ${a.name}
is on the new line,
change it to:
that is make ${a.name}
is on one line, then all content can be shown.
I know this post is quite old, but i stumbled upon it as one of the first Google hits, and want to share my solution.
I implemented the auto-row-height feature for MS Excel 2010 in 3 steps.
public class AutoRowHeightCommand extends AbstractCommand {
// ... left out boilerplate
@Override
public Size applyAt(CellRef cellRef, Context context) {
Size size = this.area.applyAt(cellRef, context);
PoiTransformer transformer = (PoiTransformer) area.getTransformer();
Row row = transformer.getWorkbook().getSheet(cellRef.getSheetName()).getRow(cellRef.getRow());
row.setHeight((short) -1);
return size;
}
}
// static method call:
XlsCommentAreaBuilder.addCommandMapping("autoRowHeight", AutoRowHeightCommand.class);
JxlsHelper.getInstance().processTemplate(is, os, context);
In the template.xlsx file edit the cell-comment that already contains the loop-command, and add the autoRowHeight command as a new line, e.g.:
jx:each(items="myitems", var="i", lastCell="B4")
jx:autoRowHeight(lastCell="B4")
Thanks to Leonid Vysochyn and Franz Frühwirth, who lead me to this solution.