Is there a Aspose.Cells.PdfSaveOptions property to convert an Excel document's cell borders exactly as is?

I am trying to convert Excel documents to PDF, exactly “as is”: (Aspose version 22.2.0.0)

        // Open the template excel file
        Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(inputPath);

        // create explicit SaveOptions
        Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
        pdfSaveOptions.OnePagePerSheet = true;
        pdfSaveOptions.AllColumnsInOnePagePerSheet = true;
        pdfSaveOptions.ExportDocumentStructure = true;
        //pdfSaveOptions.GridlineType = GridlineType.Hair;
        
        // Save the pdf file.
        string outputFile = Path.GetFileNameWithoutExtension(inputPath) + "_out.pdf";
        string outputPath = System.IO.Path.Combine(_outDir, outputFile);
        wb.Save(outputPath, pdfSaveOptions);
        return outputFile;

Now I notice that, in the output pdf, every cell has a border, even if it didn’t have one in the original Excel document! My Excel file has a hierarchical structure, so on the left side columns many cells are without border. Is there an option to preserve the exact borders of the original?

@fransbloemen,

Thanks for the details.

Could you please zip and attach your template Excel file. We will check your issue soon.

See the second worksheet of this Excel file:

borders.zip (203.6 KB)

Compliments!

@fransbloemen,

Thanks for the template file.

I evaluated your issue using your template file. I opened the file into MS Excel manually and found “Gridlines” option was on in Page Setup|Sheet tab, you may confirm this. That’s why you are seeing those gridlines everywhere in the rendered PDF pages for different sheets. Even you may take the print preview of the sheets (in MS Excel) and can notice those gridlines for confirmation. You got to set the Gridlines option off. You may easily do that using Aspose.Cells APIs before rendering to PDF. See the sample code segment for your reference.
e.g.
Sample code:

// Open the template excel file
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(inputPath);

// Set the print gridlines option off
foreach (Worksheet worksheet in wb.Worksheets)
{
      worksheet.PageSetup.PrintGridlines = false;
}

// create explicit SaveOptions
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true;
pdfSaveOptions.AllColumnsInOnePagePerSheet = true;
pdfSaveOptions.ExportDocumentStructure = true;
......

Let us know if you still find any issue.

Thanks for your evaluation, Amjad. Setting the .PrintGridLines property helps a little too well: on the second worksheet (“PT mit Details”) many vertical lines have dissapeared, together with the horizontal ones so it looks quite different than the original excel file. Can you explain why this happens? VERKAUF_Pivot_Excel2010_out.zip (170.0 KB)

@fransbloemen,

Thanks for the sample document.

Please notice, I am able to reproduce the issue as you mentioned (after adding my suggested lines of code segment) with your template file. I found some vertical lines (for the second sheet “PT mit Details”) are missing for the pivot table in the output PDF file format. The issue might be due to the fact that your datasource refers to external source/database connection. Anyways, we have to evaluate it thoroughly on our end. I have logged a ticket with an id “CELLSNET-50778” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

The issues you have found earlier (filed as CELLSNET-50778) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi