Skip to main content
A newer version of this page is available. .

How to: Create a New Document

To create a new document using the Excel Export API, do the following.

  1. Use the XlExport.CreateExporter method to create an object exposing the IXlExporter interface to perform an export to the specified file format.
  2. Call the IXlExporter.CreateDocument method to create a new document and to write it to the specified file stream.

// Create an exporter instance. 
IXlExporter exporter = XlExport.CreateExporter(XlDocumentFormat.Xlsx);
// Create the FileStream object with the specified file path. 
using (FileStream stream = new FileStream("Document.xlsx", FileMode.Create, FileAccess.ReadWrite))
{

    // Create a new document and write it to the specified stream. 
    using (IXlDocument document = exporter.CreateDocument(stream))
    {
        // Specify the document culture.
        document.Options.Culture = CultureInfo.CurrentCulture;
    }
}

After a workbook is generated, you can create other spreadsheet elements, such as worksheets, rows and columns, and cells.

See Also