Excel Workbooks in Headers and Footers | |
PdfExcelSection puts an Excel workbook into the header or footer band of a converted document, the way PdfHtmlSection puts html there. The workbook is given as a file path or a stream, in any format the Excel converter reads. It is rendered once, every sheet laid out on a page the size of the band with no margins of its own - the band is the paper - and the first rendered page is drawn on every page that shows the band, scaled to the band's width and cut at its height, never stretched. Its web links stay clickable on every page.
A band shows one page, so the sheet is fitted onto it by default: Layout is FitSheetOnOnePage. Worksheets picks the sheet and PageRanges the rendered page the band shows.
A section is independent of the converter it heads: an Excel band can head the pages of an ExcelToPdf conversion or of an HtmlToPdf, Word or PowerPoint one, and any other band can head an Excel conversion.
PdfExcelSection is available only in the full commercial SelectPdf library. |
A one-sheet summary workbook as the header of an Excel conversion, and a page-number footer:
ExcelToPdf converter = new ExcelToPdf(); converter.Options.DisplayHeader = true; converter.Header.Height = 60; PdfExcelSection totals = new PdfExcelSection("totals.xlsx"); totals.Worksheets = "Totals"; converter.Header.Add(totals); converter.Options.DisplayFooter = true; converter.Footer.Height = 30; converter.Footer.Add(new PdfTextSection(0, 10, 500, "Page {page_number} of {total_pages}", PdfFont.CreateStandardFont(PdfStandardFont.Helvetica, 9), new PdfColor(80, 80, 80))); PdfDocument doc = converter.ConvertFile("sales.xlsx"); doc.Save("sales.pdf"); doc.Close();
The same band heading an html conversion, placed at the right of the band:
HtmlToPdf htmlConverter = new HtmlToPdf(); htmlConverter.Options.DisplayHeader = true; htmlConverter.Header.Height = 60; htmlConverter.Header.Add(new PdfExcelSection(300, 0, 230, "totals.xlsx")); PdfDocument page = htmlConverter.ConvertUrl("https://selectpdf.com"); page.Save("page.pdf"); page.Close();
The sheets' own page margins are not kept: a band a few dozen points high cannot hold them, and the content would land outside it. Place the content inside the band with X, Y, Width and Height instead.