Excel to pdf conversion mismatch outputs

Hi, I am converting an excel to pdf and observed that the data contained into excel cells not fully converted instead few letters. I have enclosed both the files and below is code snippet i used. Please help to resolve this issue.

		// set aspose license
		setAsposeExcelLicense();
		Workbook excelWb = new Workbook(destExcelPath.toFile().getAbsolutePath());

		addEmptyRowsForLogoAndFilters(excelWb,
				OutputUtils.getColumnHeaders(submitHeader.getColumnProperties()).length, showFilters,
				filtersSheetName);

		StyleFlag flag = new StyleFlag();
		flag.setWrapText(true);
		PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
		if (pdfPageOrientation == PageOrientationType.LANDSCAPE)
			pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);

		// prepare excel for pdf conversion
		int visibleIndex = 1;
		int filesIndex = 0;
		if (null != additionalDetails && Boolean.FALSE.equals(additionalDetails.getShowDataSheet())) {
			visibleIndex = 2;
			filesIndex = 1;
		}
		int sheetCount = excelWb.getWorksheets().getCount();
		for (; visibleIndex < sheetCount; visibleIndex++) {
			excelWb.getWorksheets().get(visibleIndex).setVisible(false);
		}

		// generate pdf's of each sheet
		List<String> pdfFiles = new ArrayList<>();
		for (; filesIndex < sheetCount; filesIndex++) {
			Worksheet sheet = excelWb.getWorksheets().get(filesIndex);

			if (!sheet.getName().startsWith(filtersSheetName)) {
				String pdfFileName = outputFolderPath + reportName + "-" + sheet.getName().replace(" ", "-")
						+ ".pdf";
				pdfFiles.add(pdfFileName);
				if (!Files.exists(Paths.get(pdfFileName))) {
					if (sheet.getPivotTables().getCount() > 0) {
						sheet.refreshPivotTables();
						for (int j = 0; j < sheet.getPivotTables().getCount(); j++) {
							CellArea area = sheet.getPivotTables().get(j).getTableRange2();
							Range range = sheet.getCells().createRange(area.StartRow, area.StartColumn,
									area.EndRow - area.StartRow + 1, area.EndColumn - area.StartColumn + 1);
							range.setOutlineBorders(CellBorderType.THIN, com.aspose.cells.Color.getBlack());
						}
					}
					sheet.getPageSetup().setOrientation(pdfPageOrientation);
					sheet.autoFitRows();
					sheet.getPageSetup().setFitToPagesWide(filesIndex);
					sheet.getPageSetup().setFitToPagesTall(0);

					for (int colCount = 0; colCount < sheet.getCells().getColumns().getCount(); colCount++) {
						Column col = sheet.getCells().getColumns().get(colCount);
						Style columnStyle = col.getStyle();
						columnStyle.setTextWrapped(true);
						col.applyStyle(columnStyle, flag);
					}

					excelWb.calculateFormula(true);
					excelWb.save(pdfFileName, pdfSaveOptions);
					pdfOutputGeneratorHelper.addLogoAndFilters(pdfFileName, title, requestedDate, showFilters,
							reportFilters, font);
				}
				if (filesIndex < sheetCount - 1) {
					excelWb.getWorksheets().get(filesIndex + 1).setVisible(true);
					excelWb.getWorksheets().get(filesIndex).setVisible(false);
				}
			}
		}

Item_Transaction_Default_Subinventories.zip (29.3 KB)

@koteswaragunda,

I tried to execute your code snippet but it has some unresolved methods, objects, variables and other attributes for which I am not sure about it. Anyways, I checked your template Excel file. If you could open your Excel file into MS Excel manually, you will also notice data in the cells (of different columns) are not fully displayed. I think you may try some options as follows:

  1. Call autoFitColumns() method of Worksheet at the end in code just before rendering to PDF.
  2. Extend columns’ width a bit and then apply your defined style (with wrapping text on) to the columns. Finally call autoFitRows() of the sheet.

If you still could not make it work (after implementing/incorporating all the suggestions), kindly do provide standalone (console) Java program (complete source code without compilation errors) using Aspose.Cells for Java API only. We will evaluate your code snippet and assist you to accomplish your task accordingly.

Hi @amjad.sahi

seems autoFitColumns() resolved the issue. thank you for your quick help

@koteswaragunda,

You’re welcome. I’m glad the suggested operation/option meets your needs. Please don’t hesitate to reach out if you have any other questions or comments.