# spreadsheet-exporting

> Spreadsheet populated from a workbook and exported page by page to PDF using ExcelToPDFConverter with header and footer text.

**Framework:** winforms  **Component:** Spreadsheet  **Variant:** exporting

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/winforms/spreadsheet-exporting.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Spreadsheet.Windows
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/spreadsheet-exporting/spreadsheet.Designer.cs

```cs
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Syncfusion.Windows.Forms.Spreadsheet;

namespace SpreadsheetExporting
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.exportGroupBox = new GroupBox();
            this.htmlRadioButton = new RadioButton();
            this.imageRadioButton = new RadioButton();
            this.pdfRadioButton = new RadioButton();
            this.exportButton = new Button();
            this.spreadsheet = new Spreadsheet();
            this.spreadsheetPanel = new Panel();
            this.exportGroupBox.SuspendLayout();
            this.spreadsheetPanel.SuspendLayout();
            this.SuspendLayout();
            //
            // exportGroupBox
            //
            this.exportGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                         | System.Windows.Forms.AnchorStyles.Right));
            this.exportGroupBox.Controls.Add(this.htmlRadioButton);
            this.exportGroupBox.Controls.Add(this.imageRadioButton);
            this.exportGroupBox.Controls.Add(this.pdfRadioButton);
            this.exportGroupBox.Controls.Add(this.exportButton);
            this.exportGroupBox.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.exportGroupBox.Location = new System.Drawing.Point(575, 1);
            this.exportGroupBox.Name = "exportGroupBox";
            this.exportGroupBox.Size = new System.Drawing.Size(180, 360);
            this.exportGroupBox.TabIndex = 3;
            this.exportGroupBox.TabStop = false;
            this.exportGroupBox.Text = "Export Options";
            //
            // htmlRadioButton
            //
            this.htmlRadioButton.Location = new System.Drawing.Point(10, 35);
            this.htmlRadioButton.Name = "htmlRadioButton";
            this.htmlRadioButton.Size = new System.Drawing.Size(150, 35);
            this.htmlRadioButton.TabIndex = 0;
            this.htmlRadioButton.Text = "Export to HTML";
            //
            // imageRadioButton
            //
            this.imageRadioButton.Location = new System.Drawing.Point(10, 90);
            this.imageRadioButton.Name = "imageRadioButton";
            this.imageRadioButton.Size = new System.Drawing.Size(150, 35);
            this.imageRadioButton.TabIndex = 1;
            this.imageRadioButton.Text = "Export to Image";
            //
            // pdfRadioButton
            //
            this.pdfRadioButton.Checked = true;
            this.pdfRadioButton.Location = new System.Drawing.Point(10, 150);
            this.pdfRadioButton.Name = "pdfRadioButton";
            this.pdfRadioButton.Size = new System.Drawing.Size(150, 35);
            this.pdfRadioButton.TabIndex = 2;
            this.pdfRadioButton.Text = "Export to PDF";
            //
            // exportButton
            //
            this.exportButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.exportButton.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(22)))), ((int)(((byte)(165)))), ((int)(((byte)(220)))));
            this.exportButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.exportButton.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.exportButton.ForeColor = System.Drawing.Color.White;
            this.exportButton.Location = new System.Drawing.Point(50, 220);
            this.exportButton.Name = "exportButton";
            this.exportButton.Size = new System.Drawing.Size(100, 35);
            this.exportButton.TabIndex = 4;
            this.exportButton.Text = "Export";
            this.exportButton.UseVisualStyleBackColor = false;
            this.exportButton.Click += new System.EventHandler(this.exportButton_Click);
            //
            // spreadsheet
            //
            this.spreadsheet.AllowCellContextMenu = true;
            this.spreadsheet.AllowExtendRowColumnCount = true;
            this.spreadsheet.AllowFormulaRangeSelection = true;
            this.spreadsheet.AllowTabItemContextMenu = true;
            this.spreadsheet.AllowZooming = true;
            this.spreadsheet.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                         | System.Windows.Forms.AnchorStyles.Left)
                         | System.Windows.Forms.AnchorStyles.Right)));
            this.spreadsheet.DefaultColumnCount = 101;
            this.spreadsheet.DefaultRowCount = 101;
            this.spreadsheet.FormulaBarVisibility = false;
            this.spreadsheet.Location = new System.Drawing.Point(0, 0);
            this.spreadsheet.Name = "spreadsheet";
            this.spreadsheet.Size = new System.Drawing.Size(560, 376);
            this.spreadsheet.TabIndex = 0;
            this.spreadsheet.Text = "spreadsheet";
            //
            // spreadsheetPanel
            //
            this.spreadsheetPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                         | System.Windows.Forms.AnchorStyles.Left)
                         | System.Windows.Forms.AnchorStyles.Right)));
            this.spreadsheetPanel.BackColor = System.Drawing.Color.White;
            this.spreadsheetPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.spreadsheetPanel.Controls.Add(this.spreadsheet);
            this.spreadsheetPanel.ForeColor = System.Drawing.Color.DarkGray;
            this.spreadsheetPanel.Location = new System.Drawing.Point(10, 0);
            this.spreadsheetPanel.Name = "spreadsheetPanel";
            this.spreadsheetPanel.Size = new System.Drawing.Size(560, 376);
            this.spreadsheetPanel.TabIndex = 5;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.ClientSize = new System.Drawing.Size(793, 403);
            this.Controls.Add(this.exportGroupBox);
            this.Controls.Add(this.spreadsheetPanel);
            this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Icon = new System.Drawing.Icon(SpreadsheetExportingDataSource.GetIconPath());
            this.MinimumSize = new System.Drawing.Size(600, 350);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Exporting";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.spreadsheetPanel.ResumeLayout(false);
            this.exportGroupBox.ResumeLayout(false);
            this.exportGroupBox.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion
    }
}

```

### src/components/spreadsheet-exporting/spreadsheet.cs

```cs
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using Syncfusion.ExcelToPdfConverter;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;
using Syncfusion.XlsIO.Implementation;
using Syncfusion.Windows.Forms.Spreadsheet;

namespace SpreadsheetExporting
{
    /// <summary>
    /// Demonstrates exporting a Syncfusion Spreadsheet to HTML, an image and PDF.
    /// </summary>
    public partial class Form1 : Form
    {
        private Spreadsheet spreadsheet;
        private GroupBox exportGroupBox;
        private RadioButton htmlRadioButton;
        private RadioButton imageRadioButton;
        private RadioButton pdfRadioButton;
        private Button exportButton;
        private Panel spreadsheetPanel;

        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Exports the spreadsheet using the currently selected export option.
        /// </summary>
        private void exportButton_Click(object sender, EventArgs e)
        {
            if (this.pdfRadioButton.Checked)
            {
                ExportToPDF(this.spreadsheet);
            }
            else if (this.htmlRadioButton.Checked)
            {
                ExportWorkbookToHTML(this.spreadsheet);
            }
            else if (this.imageRadioButton.Checked)
            {
                ExportWorksheetToBitmap(this.spreadsheet);
            }
        }

        /// <summary>
        /// Opens the workbook that ships with this sample.
        /// </summary>
        private void Form1_Load(object sender, EventArgs e)
        {
            string workbookPath = SpreadsheetExportingDataSource.GetWorkbookPath();
            if (System.IO.File.Exists(workbookPath))
            {
                this.spreadsheet.Open(workbookPath);
            }
        }

        #region PDF

        /// <summary>
        /// Converts the workbook into a PDF document.
        /// </summary>
        private static void ExportToPDF(Spreadsheet spreadsheetControl)
        {
            ExcelToPdfConverter converter = new ExcelToPdfConverter(spreadsheetControl.Workbook);
            PdfDocument pdfDoc = new PdfDocument();

            ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
            settings.LayoutOptions = LayoutOptions.NoScaling;
            settings.TemplateDocument = pdfDoc;
            settings.DisplayGridLines = GridLinesDisplayStyle.Invisible;

            pdfDoc = converter.Convert(settings);
            pdfDoc.Save(SpreadsheetExportingDataSource.PdfOutputFileName);
        }

        #endregion

        #region Image

        /// <summary>
        /// Renders the used range of the active worksheet into a bitmap.
        /// </summary>
        private static void ExportWorksheetToBitmap(Spreadsheet spreadsheetControl)
        {
            IWorksheet sheet = spreadsheetControl.Workbook.ActiveSheet;
            sheet.UsedRangeIncludesFormatting = false;
            int lastRow = sheet.UsedRange.LastRow + 1;
            int lastColumn = sheet.UsedRange.LastColumn + 1;
            using (Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null))
            {
                img.Save(SpreadsheetExportingDataSource.ImageOutputFileName, ImageFormat.Png);
            }
        }

        #endregion

        #region HTML

        /// <summary>
        /// Saves the workbook as an HTML document.
        /// </summary>
        private static void ExportWorkbookToHTML(Spreadsheet spreadsheetControl)
        {
            spreadsheetControl.Workbook.SaveAsHtml(SpreadsheetExportingDataSource.HtmlOutputFileName, HtmlSaveOptions.Default);
        }

        #endregion
    }
}

```
