ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; string inputPath = GetFullTemplatePath("Sample.xlsx"); IWorkbook workbook = application.Workbooks.Open(inputPath, ExcelOpenType.Automatic); //Byte Array of Input file. byte[] excel = System.IO.File.ReadAllBytes(inputPath); //Byte Array of Csv file converted from excel byte array. byte[] csv = ConvertExcelToCSV(excel);
public byte[] ConvertExcelToCSV(byte[] buffer) { ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; MemoryStream stream = new MemoryStream(buffer); IWorkbook workbook = application.Workbooks.Open(stream); MemoryStream csvStream = new MemoryStream(); //Saving the file as csv workbook.SaveAs(csvStream, ","); csvStream.Seek(0, SeekOrigin.Begin); return csvStream.ToArray(); workbook.Close(); excelEngine.Dispose(); |
public byte[] ConvertExcelToCSV(byte[] buffer) { ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; using (MemoryStream stream = new MemoryStream(buffer)) { IWorkbook workbook = application.Workbooks.Open(stream); MemoryStream csvStream = new MemoryStream(); workbook.SaveAs(csvStream, ","); workbook.Close(); excelEngine.Dispose(); csvStream.Seek(0, SeekOrigin.Begin); buffer = csvStream.ToArray(); } return buffer; } |