Convert XLSX to CSV in C#

XlsxToCsvConverter exports one sheet of a workbook as RFC 4180 CSV. The output does not depend on the machine's regional settings, so 1234.5 never becomes 1234,5.

using DocToolkit;

byte[] xlsx = File.ReadAllBytes("input.xlsx");
string csv = XlsxToCsvConverter.Convert(xlsx, "Sheet1");
File.WriteAllText("output.csv", csv);

What it needs

  • No browser, headless or otherwise.
  • No Office install, and no LibreOffice.
  • No native files: managed code only.
  • No network at runtime, unless you ask for it.

Good to know

  • Synchronous: Convert takes the workbook as a byte[] and a sheet name, and returns a string. One sheet at a time, named by you; WorkbookEditor.SheetNames lists them.
  • Numbers are culture-invariant, dates are ISO 8601, and a formula cell exports its computed value.
  • Records end in CRLF, and a field is quoted only when it has to be.
  • Formula injection is not guarded against: a field starting with =, +, - or @ is written as is. Sanitise the CSV of an untrusted workbook before Excel opens it.

Install

dotnet add package Ank.DocToolkit

NuGetDocumentationGitHub