Bulding a table as excel and saving it as PDF loses text wrapping and just truncates

I am building a pretty big table with a number of worksheets. I am using the excel protion of the Aspose to that. Then at the end of the function I am saving as a PDF. Works great except for one thing. All the wrapped text is truncated after the first line. I have tried using workseeht.autoFitRows(); and worksheet.autoFitRows(true); but those things seem to have no effect on the PDF output. Please advise on how I can get this to wrap text saving as a PDF.

Hi David,


Thanks for your inquiry. As your request pertains to Aspose.Cells, So I’m moving it to related forum. There one of my colleague will guide you properly.

Best Regards,

Hi David,

Thanks for your posting and using Aspose.Cells for Java.

Please provide us your source file which you are converting to pdf and the sample code to replicate this issue with the latest version. We will look into it and update you asap.

Please also download and try the latest version: Aspose.Cells
for Java v7.6.0.3
and see if it resolves your issue.

There is no source file. I am building the excel sheet from scratch. Also I can't post in the whole functions, they are very long. I have pasted in the relevant code. tagNames is a very long list of values and it just truncates instead of wrapping. I do hope yo can make sens of what I have posted.

// Creating a file input stream to reference the license file
// Create a License object
com.aspose.cells.License lic = new com.aspose.cells.License();
ServletContext sc = session.getServletContext();
String basePath = sc.getRealPath("/");
// Set the license of Aspose.Cells
lic.setLicense(new FileInputStream(new File(basePath
+ "\\resources\\Aspose.Total.Java.lic")));
// Instantiate a Workbook object that represents Excel file.
Workbook wb = new Workbook();

int styleIdx = wb.getStyles().add();
Style tableHeadStyle = wb.getStyles().get(styleIdx);
tableHeadStyle.getFont().setColor(com.aspose.cells.Color.getBlack());
tableHeadStyle.getFont().setBold(true);
tableHeadStyle.setPattern(BackgroundType.SOLID);
tableHeadStyle.setForegroundColor(com.aspose.cells.Color.getLightGray());
tableHeadStyle.setHorizontalAlignment(TextAlignmentType.LEFT);
tableHeadStyle.setTextWrapped(true);
tableHeadStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
tableHeadStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
tableHeadStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
tableHeadStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
styleIdx = wb.getStyles().add();
Style tableDataStyle = wb.getStyles().get(styleIdx);
tableDataStyle.setHorizontalAlignment(TextAlignmentType.LEFT);
tableDataStyle.setTextWrapped(true);
tableDataStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
tableDataStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
tableDataStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
tableDataStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
String tagN = tagNames.toString();
tagN = tagN.replace("[", "");
tagN = tagN.replace("]", "");

// Note when you create a new workbook, a default worksheet
// "Sheet1" is added (by default) to the workbook.
// Access the first worksheet "Sheet1" in the book.
Worksheet sheet = wb.getWorksheets().get(0);
sheet.setName("Order Entry Report");
sheet.setGridlinesVisible(true);
PageSetup ps = sheet.getPageSetup();
String script1 = "&\"Arial, Bold\"&14&K1F69AA&A";
ps.setHeader(0, script1);
ps.setFooter(0, "&G");
FileInputStream fis = new FileInputStream(basePath + "\\resources\\images\\driSteem_logo_footer.png");
byte[] picData = new byte[fis.available()];
fis.read(picData);
ps.setFooterPicture(0, picData);
String footString = "Generated by driCalc® software, Version 4.00.00 on &D-&T";
ps.setFooter(2, "&\"Arial\"&K222222&8 " + footString + " &\"Arial\"&K1F69AA&8 | &P of &N");
sheet.setGridlinesVisible(true);
sheet.autoFitRows(true);
Cells cells = sheet.getCells();
cells.setColumnWidth(0, 25f);
cells.setColumnWidth(1, 60f);
sheet.autoFitRows(true);
WorksheetCollection worksheets = wb.getWorksheets();

int sheetIndex;
int counter = 0;
int i = 0;
for(Integer systemId : systemList)
{
oe = dao.findById(systemId);
counter++;
if(oe != null && counter == 1)
{
i = populateProjectInformtaion(cells, oe, tableHeadStyle, tableDataStyle, unitOfMeasure, tagN);
}
sheetIndex = worksheets.add();
sheet = worksheets.get(sheetIndex);
if(oe != null && oe.getTagName() != null && oe.getTagName().length() <= 27)
{
sheet.setName("OER " + oe.getTagName());
}
else if(oe != null && oe.getTagName() != null)
{
sheet.setName("OER " + oe.getTagName().substring(0, 26));
}
sheet.setGridlinesVisible(true);
sheet.autoFitRows(true);
ps = sheet.getPageSetup();
ps.setHeader(0, script1);
ps.setFooter(0, "&G");
fis.read(picData);
ps.setFooterPicture(0, picData);
ps.setFooter(2, "&\"Arial\"&K222222&8 " + footString + " &\"Arial\"&K1F69AA&8 | &P of &N");
sheet.setGridlinesVisible(true);
cells = sheet.getCells();
cells.setColumnWidth(0, 20f);
cells.setColumnWidth(1, 15f);
cells.setColumnWidth(2, 5f);
cells.setColumnWidth(3, 12f);
cells.setColumnWidth(4, 12f);
cells.setColumnWidth(5, 4f);
cells.setColumnWidth(6, 10f);
sheet.autoFitRows();

.................................................

private int populateProjectInformtaion(Cells cells, OrderEntry oe, Style tableHeadStyle, Style tableDataStyle, String unitOfMeasure, String tagNames)
{
int i = 1;
Cell cell = cells.get("A" + i);
cell.setStyle(tableHeadStyle);
Style tempStyle = cell.getStyle();
tempStyle.getFont().setBold(true);
cell.setStyle(tempStyle);
cell.setValue(msgSrc.getMessage("report.information", null, loc));
cell = cells.get("B" + i);
cell.setStyle(tableHeadStyle);
i++;
cell = cells.get("A" + i);
cell.setStyle(tableDataStyle);
cell.setValue(msgSrc.getMessage("report.generatedDate", null, loc));
cell = cells.get("B" + i);
cell.setStyle(tableDataStyle);
DateFormat dateFormat = new SimpleDateFormat("yyy/MM/dd HH:mm:ss");
cell.setValue(dateFormat.format(new Date()));
i++;
cell = cells.get("A" + i);
cell.setStyle(tableDataStyle);
cell.setValue(msgSrc.getMessage("system.tags", null, loc));
cell = cells.get("B" + i);
cell.setStyle(tableDataStyle);
cell.setValue(tagNames);
i++;
..............................................................................

Then at the end of the function I output a pdf as


response.setContentType(“application/pdf”);
response.addHeader(“Content-Disposition”, “attachment;Filename= orderEntry.pdf”);
wb.save(outs, FileFormatType.PDF);

At thend of the ifle I am saving a PDF as


response.setContentType(“application/pdf”);
response.addHeader(“Content-Disposition”, “attachment;Filename= orderEntry.pdf”);
wb.save(outs, FileFormatType.PDF);

I got it to work using autoFitRows on the worksheet. What I was missing is you need to do it after you populate the rows. Now that I am doing it after, it works great.

Hi David,

Thanks for your posting and using Aspose.Cells.

Yes, you need to call autoFitRows after populating the rows. It is good to know that you were able to sort out this issue. If you encounter any other issue, please feel free to post, we will be glad to help you.