C# CONCEPTS
OpenXml SDK (Brief Guide C#)
Programmatically work with excel files using OpenXml SDK.
Published in
4 min readSep 1, 2020
The articles demonstrate how to play with Excel Document in C# Console Application programmatically.
Prerequisites
Install below packages from NuGet
DocumentFormat.OpenXml
Following “Assembly Directives” are used to compile the code
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
Create a Spreadsheet Document
To build an Excel document, construct an instance of the “SpreadsheetDocument” class.
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create
(
filepath,
SpreadsheetDocumentType.Workbook
);
There are many constructor overloads for SpreadsheetDocument, but the above instance takes two arguments.
- File Path: The destination path to save the final excel file.
- SpreadSheetDocumentType: It specifies the type of excel document.