Excel sheet lines are not in generated PDF

Hi

When we convert an excel file to PDF using aspose.Total.Java, the generated PDF file doesn’t contain the lines. The code snippet which we are using is:
License license = new License();
try {
license.setLicense("…/Aspose.Total.Java.lic");
} catch (Exception e) {
e.printStackTrace();
}

	Workbook workbook = new Workbook(DocPath);
	workbook.calculateFormula();
	
	//saving excel into pdf
	PdfSaveOptions opts = new PdfSaveOptions();
    opts.setAllColumnsInOnePagePerSheet(true);
    opts.setCheckFontCompatibility(true);

    workbook.getWorksheets().get(0).getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);
    workbook.getWorksheets().get(0).getCells().setDefaultRowHeightMatched(true);
    workbook.getWorksheets().get(0).autoFitRows();
	workbook.getWorksheets().get(0).autoFitColumns();
    workbook.save(PDFPath, opts);

We wanted the excel sheet lines also to be there in PDF

Thanks in advance

@sheoran531994,

Thanks for the code segment and details.

Do you need to render gridlines in the output PDF file format? If so, kindly do add a line of code (in bold) to your code segment:
e.g
Sample code:


Workbook workbook = new Workbook(DocPath);
workbook.calculateFormula();

//saving excel into pdf
PdfSaveOptions opts = new PdfSaveOptions();
opts.setAllColumnsInOnePagePerSheet(true);
opts.setCheckFontCompatibility(true);

workbook.getWorksheets().get(0).getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);
workbook.getWorksheets().get(0).getCells().setDefaultRowHeightMatched(true);
workbook.getWorksheets().get(0).autoFitRows();

workbook.getWorksheets().get(0).autoFitColumns();
workbook.getWorksheets().get(0).getPageSetup().setPrintGridlines(true);
workbook.save(PDFPath, opts);

Hope, this helps a bit.

In this case lines are dotted. we want complete line.

@sheoran531994,

Well, gridlines are shown as dotted lines when taking print preview of the sheet, you may confirm this in MS Excel when setting the “Sheet|Gridlines” option in the Page Setup dialog for the sheet in Ms Excel.

If you need complete thin/tick lines, you may adopt the following approach instead. You can apply borders to your data range in the sheet for your needs. See the following code segment which you can use for your reference:
e.g
Sample code:

.........
 Worksheet worksheet = workbook.getWorksheets().get(0);
            
            int maxRow = worksheet.getCells().getMaxDataRow();
            int maxCol = worksheet.getCells().getMaxDataColumn();
            
	    Range range = worksheet.getCells().getMaxDisplayRange();	
             
Style style = workbook.createStyle();
                        
            style.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
            style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
            style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
            style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());

	    StyleFlag flag = new StyleFlag();
            //Set borders on 
           flag.setBorders(true);	

            //apply the style to the range (which contains all the data cells in the worksheet)
            range.applyStyle(style, flag); 
........

Hope, this helps a bit.