C# CONCEPTS

OpenXml SDK (Brief Guide C#)

Programmatically work with excel files using OpenXml SDK.

Sukhpinder Singh | .Net Developer
The Startup
Published in
4 min readSep 1, 2020

--

Photo by Lukas Blazek on Unsplash

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.

Available document types enum in…

--

--

Sukhpinder Singh | .Net Developer
The Startup

Programmer by heart | C# | .Net 6 | .Net 8 | dotnet | dotnetcore | Kubernetes | Angular | AWS | Remember to 👏 Linktree: https://linktr.ee/sukhpindersingh