I would like to give you just an example of a working solution. Assume that excel worksheets have a header and are in the specified range.
Code below exports data to CSV with the filename of the worksheet.
using (var package = new ExcelPackage(new FileInfo("myBook.xlsx")))
{
foreach (var worksheet in package.Workbook.Worksheets)
{
worksheet
.Cells["A1:B3"]
.SaveToText(
new FileInfo($"{worksheet}.csv"),
new ExcelOutputTextFormat());
}
}
As you can imagine, you can do whatever you want, export with or without headers, customize your ranges, export specific worksheets, combine data from all worksheets, and so on. But this is another thing. It really depends on your requirements.
There is also ToText()
method, so you can process it further.
Reading and Writing Data