Save as PDF - Gridlines not showing

Hello,

I have an xls template that i use to create reports. One such report needs to be saved as PDF which works great. The only problem is the resulting PDF does not show any gridlines and that makes the report difficult to read. However, in the template, in the Page Setup options (File menu -> Page Setup), under Sheet tab, i have checked the GridLines property. I am using -

Workbook.Save (FilePath, FileFormatType.Pdf)

to save as PDF.

When i save the file (through the program) as excel file, and then Convert to Adobe PDF, the resulting PDF file shows the gridlines. But when i save the file (through the program) as PDF directly, the gridlines do not show up. When i print it also, the gridlines are not there. Is there someway to have the gridlines show up when saving as PDF.

I have to also say that in the Sheet tab, under Print Titles property, i have selected Rows 1 through 4 to repeat at every page (column headers). I dont know if this would have any bearing on the above problem. The reason i mentioned this is when i converted the excel file to PDF manually, i got a message as -

Acrobat PDFMaker cannot create Tags, Bookmarks, Comments and Links for Worksheets with Print Titles. Clear the Print Titles field in the Page Setup dialog to get these features. Do you want to proceed and create a PDF file without Tags?

If i click Yes, the PDF is created with gridlines. If i click No, the PDF is not generated.

Awaiting your response at the earliest. If we cant get the gridlines to show up, we may have to scratch this report off, and generate it using some other components, and i dont want to start over again. Please help.

Thank you,

Sreejith

Hi Sreejith,

Thank you for considering Aspose.

Well, I am afraid your desired feature (Gridlines in XLS2PDF) is not supported at the moment. We have added your requested feature as New Feature in our internal issue tracking system with issue id CELLSNET-14383. We will look into the feasibility of the feature and get back to you soon. As a workaround, you may add the borders to the cells and it will be easily readable and behave like gridlines in the generated PDF file. Please see the following sample code in this regard:

//Instantiating a Workbook object
Workbook workbook = new Workbook();

workbook.Open("d:\\Test_Temp\\Book1.xls");

Style style = workbook.Styles[workbook.Styles.Add()];
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Hair;
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Hair;
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Hair;
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Hair;

Cells cells = workbook.Worksheets[0].Cells;

foreach (Aspose.Cells.Cell cell in cells)
{
    cell.SetStyle(style);
}

//Saving the Excel file as PDF
workbook.Save("d:\\Test_Temp\\PDF_Format.PDF", FileFormatType.Pdf);

Thank you & Best Regards,

Thank you Nausherwan for your prompt response. I greatly appreciate it. And the solution you gave me works very well. However there was one small hitch, but I fixed it. In my template, i have a lot of formattings set for the cells (each cell has its own style), and when i added the logic provided by you, i was losing all those formattings.

So all i had to do was set each cell's style to the style object, then add the Border style recommended by you to that same style object and associate the cell's style to this object, like this -

foreach (Aspose.Cells.Cell cell in cells)
{
style = cell.style;
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Hair;
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Hair;
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Hair;
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Hair;

cell.SetStyle(style);
}

Thank you again for you prompt help.

Sreejith

Hi Sreejith,

Please try the attached latest version of Aspose.Cells. We have supported to show gridlines in XLS2PDF conversion.

Thank You & Best Regards

I am having the same issue.

I downloaded the attached zip.

The gridlines are now displaying but they are overriding existing borders.

Hi,

"The gridlines are now displaying but they are overriding existing borders."

Please check your excel file's print preview in MS Excel, the generated pdf file should be same with it. If you find any difference, kindly post your template excel file(or code) and output pdf file here, we will check it soon.

Thank you.

Here are the sample files you requested.

My code is very simple:

Dim cellsLicense = New Aspose.Cells.License

cellsLicense.SetLicense("Aspose.Cells.lic")

'Opening the Excel file through the file stream

wb.Open(TestFile)

'Save the Excel file

wb.Save(vPDFFileName, FileFormatType.Pdf)

Hi,

Thanks for providing us the template xlsx file.

We have found the issue after an initial test as you have described. We will figure it out soon.

Your issue has been logged into our issue tracking system with an issue id: CELLSNET-15741.
We will inform you when it is sorted out.

Thank you.

The issues you have found earlier (filed as 14383) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi,

Please try the attached version, we have figured out the issue regarding grid lines are not showing in the pdf file.

The issues you have found earlier (filed as 15741) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Why “open()” method is not there in 8.9 release.

Hi Mukesh Kumar,


Well, in newer versions (e.g v8.9.0), you will use Workbook constructor(s) to open an Excel spreadsheet, see the sample lines of code for your reference:
e.g
Sample code:

i) Workbook workbook = new Workbook(“Book1.xlsx”);
ii) Workbook workbook = new Workbook(“test1.xls”, new LoadOptions(LoadFormat.Excel97To2003));
iii) LoadOptions loadOptions = new LoadOptions(LoadFormat.CSV);
Workbook workbook = new Workbook(“e:\test2\myfile.csv”, loadOptions);
etc.

See the document for your complete reference:
http://www.aspose.com/docs/display/cellsnet/Opening+Files

Also, please see the Aspose.Cells for .NET API Reference pages:
http://www.aspose.com/api/net/cells

Thank you.