I’m trying to insert a Header and a Footer into Excel document. However, it only works if the input excel already have a header and a footer. Am I missing something?
final WorksheetCollection collection = workbook.getWorksheets();
final InputStream inFile = DocumentBuilderBase.class.getClassLoader().getResourceAsStream(“Watermark.png”);
final byte[] picData = IOUtils.toByteArray(inFile);
for (int i = 0; i < collection.getCount(); i++) {
final Worksheet sheet = workbook.getWorksheets().get(i);
final com.aspose.cells.PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setHeader(1, "&G");
pageSetup.setHeaderPicture(1, picData);
pageSetup.setFooter(1, "&Arial&" + FONT_SIZE + WATERMARK_TEXT);
}
The picture will be visible when you will set the PAGE_LAYOUT_VIEW. Please see the following sample code and its output Excel file as well as screenshot for a reference.
1- My footer is: &Arial&18Evaluation only. Created with a Trial Version.
But when the output shows: IssuesrialEvaluation only. Created with a Trial Version of Xporter.
I’ve noticed that “Issues” is the name of the sheet. It’s possible to delete the “Issuesrial”?
2- Every time I insert a header or a footer, the excel splits the sheet in two, as you can see on your screenshot. It’s possible to show the document as “normal”?
Please share with us your sample code, sample Excel file(s) and screenshots showing the error. Please note, when you set the page layout view, only then you will see header and it will always split the sheet into number of pages. The other way is to render the Excel to Pdf and then header will appear on every page.
Please open the DEMO-24 (3).xlsx in Microsoft Excel and fix it manually and provide it back to us. We need your expected Excel file. Please also provide the picture you used in the expected Excel file.
Besides, you provided the sample code in a screenshot, provide it in text as you did earlier. We will examine your expected Excel file and provide you a sample code so that you could test it at your end.
You may create your desired header and footer manually using Microsoft Excel and save it on disk. Then you load the saved Excel file in Aspose.Cells APIs and retrieve the header and footer script using the following code. This will give you idea what script you are to use in your program/code.
Hi,
Thank you for your help, I’m almost there. Just one more question, if I execute the code I’ve sent to you and save the document as .csv, footer and header are empty. See this example: CSVExperiment.zip (6.3 KB)
CSV format is a very simple and text-based format. It is a comma separated file. Except commas, it does not have any sophisticated meta data. Just create Header & Footer in Microsoft Excel and save it in CSV format and then open it again in Microsoft Excel, you will see, Header & Footer information is lost. Then open it in Notepad and you will see, there is no Header & Footer information inside the CSV file. It means, CSV file does not and cannot support Header & Footer information.