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.
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 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 -
"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.
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);
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.