Pdf Excel Element | |
PdfExcelElement draws an Excel workbook into a region of a pdf page, the way PdfWordElement draws a Word document there. The workbook is given as a file path or a stream, in any format the Excel converter reads, and is rendered in-process at render time with every sheet laid out on pages the size of the region and no margins of its own - the region is the paper. Its links stay clickable, and each sheet becomes an entry in the outline of the host document (SheetBookmarks).
Coordinates and sizes are in the page's client-area coordinate system, relative to the top-left corner of the writable area inside the page margins. Width defaults to the client width minus X; Height decides how the content flows:
A fixed height that fits its page draws the first rendered page, cut at the box.
The default, -1, lets the content flow onto the pages that follow, using the document's next page when there is one and appending one when there is not.
A fixed height taller than what is left of the page continues on the pages that follow, the same way, until that much height has been drawn.
Layout, GridLines, Worksheets, Password, Format and PageRanges work as on the converter.
PdfExcelElement is available only in the full commercial SelectPdf library. |
A title drawn from code, then a workbook flowing from below it onto the pages that follow.
PdfDocument doc = new PdfDocument(); PdfPage page = doc.AddPage(); PdfFont titleFont = PdfFont.CreateStandardFont(PdfStandardFont.HelveticaBold, 20); page.Add(new PdfTextElement(0, 0, "Annex B - the sales figures", titleFont, new PdfColor(44, 62, 80))); // from 60pt down the page, all the columns on the width of the page PdfExcelElement sales = new PdfExcelElement(0, 60, "sales.xlsx"); sales.Layout = ExcelLayout.FitAllColumnsOnOnePage; PdfRenderingResult result = page.Add(sales); // where each rendered page landed, and the page the region ended on SelectPdf.Universal.Drawing.RectangleF[] slices = sales.PdfPagesRectangles; int lastPage = result.PdfPageLastIndex; doc.Save("annex.pdf"); doc.Close();
A fixed rectangle shows one sheet, fitted on the first rendered page:
Added to a header, footer or stamp template (Templates), the element draws the first rendered page on every page the template applies to and re-creates its web links on each of them; the outline is not carried, since a band has no single place in a reading order.
On a page of a tagged document the region carries its own structure: the workbook's tables, charts, pictures and links join the host document's logical structure, in the reading order, at the place the region was drawn - so a document declaring PDF/UA-1 or PDF/UA-2 stays conformant with an Excel region on it. Tagged asks for that structure on a document that is not tagged itself. Set Artifact to declare the whole region decorative instead.
In a header, footer or stamp the element is refused on a tagged document unless it is decorative: a band repeats on every page, so its content has no single place in a reading order.