In DsExcel Java, you can use the setLeftHeader, setRightHeader, setLeftFooter, setRightFooter, setCenterHeader and setCenterFooter methods of the IPageSetup interface in order to configure header and footer for a page.
Java |
Copy Code |
---|---|
// Configure PageHeader and PageFooter // Set header for the page worksheet.getPageSetup().setLeftHeader("&\"Arial,Italic\"LeftHeader"); worksheet.getPageSetup().setCenterHeader("&P"); // Set header and footer graphic for the page worksheet.getPageSetup().setCenterFooter("&G"); InputStream stream = ClassLoader.getSystemResourceAsStream("logo.png"); worksheet.getPageSetup().getCenterFooterPicture().setGraphicStream(stream, ImageType.PNG); |
For special settings, you can also perform the following tasks in order to customize the configuration of the header and footer of your page:
If you want a different header and footer in your first page, you first need to set the setDifferentFirstPageHeaderFooter method of the IPageSetup interface to true. When this is done, you can use the method of the IPageSetup interface in order to configure the first page header and footer.
Java |
Copy Code |
---|---|
//Set first page header and footer worksheet.getPageSetup().setDifferentFirstPageHeaderFooter(true); worksheet.getPageSetup().getFirstPage().getCenterHeader().setText("&T"); worksheet.getPageSetup().getFirstPage().getRightFooter().setText("&D"); //Set first page header and footer graphic worksheet.getPageSetup().getFirstPage().getLeftFooter().setText("&G"); InputStream stream = ClassLoader.getSystemResourceAsStream("logo.png"); worksheet.getPageSetup().getFirstPage().getLeftFooter().getPicture().setGraphicStream(stream, ImageType.PNG); worksheet.getPageSetup().getFirstPage().getLeftFooter().getPicture().setWidth(100); worksheet.getPageSetup().getFirstPage().getLeftFooter().getPicture().setHeight(13); |
If you want a different header and footer for all the even pages, you first need to set the setOddAndEvenPagesHeaderFooter method to true. When this is done, you can use other methods of the IPageSetup interface in order to configure the even page header and footer.
Java |
Copy Code |
---|---|
// Set even page header and footer worksheet.getPageSetup().setOddAndEvenPagesHeaderFooter(true); worksheet.getPageSetup().getEvenPage().getCenterHeader().setText("&T"); worksheet.getPageSetup().getEvenPage().getRightFooter().setText("&D"); // Set even page header and footer graphic worksheet.getPageSetup().getEvenPage().getLeftFooter().setText("&G"); InputStream stream = ClassLoader.getSystemResourceAsStream("logo.png"); worksheet.getPageSetup().getEvenPage().getLeftFooter().getPicture().setGraphicStream(stream, ImageType.PNG); |