Posted on 03/08/2020 21:32:55
Hi Adrian,
yes, as Xml. Maybe you can use Xml ->DataTable->Excel generation.
Xml to Datatable: https://stackoverflow.com/questions/7801646/xml-string-to-datatable-in-c-sharp
DataTable to Excel using EppPlus:
public void GenerateExcel()
{
FileInfo newFileInfo = new FileInfo(path + destinationPath);
using (ExcelPackage pck = new ExcelPackage(newFileInfo))
{
foreach (DataTable table in setForExcel.Tables)
{
List<ExcelWorksheet> workSheetsToRemove = new List<ExcelWorksheet>();
foreach (var worksheet in pck.Workbook.Worksheets)
{
if (worksheet.Name.Equals(table.TableName, StringComparison.OrdinalIgnoreCase))
{
workSheetsToRemove.Add(worksheet);
}
}
foreach (var worksheet in workSheetsToRemove)
{
pck.Workbook.Worksheets.Delete(worksheet);
}
ExcelWorksheet ws = pck.Workbook.Worksheets.Add(table.TableName);
ws.Cells["A1"].LoadFromDataTable(table, true);
if (logger != null)
{
logger.Log("Added table: " + table.TableName + " Rows: " + table.Rows.Count);
}
}
pck.Save();
if (logger != null)
{
logger.Log("Writing to " + destinationPath + " is saved and finished");
}
}
}
Regards, Dmitrij