I want to save some strings in excel format.
It's simple, but it doesn't work.
try
{
list.Clear();
list.Add(new string[] { "A", "B", "C", "D", "E", "F", "G" });
list.Add(new string[] { "A", "B", "C", "D", "E", "F", "G" });
list.Add(new string[] { "A", "B", "C", "D", "E", "F", "G" });
WriteExcel();
Console.WriteLine("Success");
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
}
static void WriteExcel()
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Set the default application version as Excel 2016
excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016;
//Create a workbook with a worksheet
IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1);
//Access first worksheet from the workbook instance
IWorksheet worksheet = workbook.Worksheets[0];
//Insert sample text into cell “A1”
//worksheet.Range["A1"].Text = "Hello World";
worksheet.ImportData(list,1,1,true);
//Save the workbook to disk in xlsx format
Stream stm = System.IO.File.Create("filelist.xlsx");
workbook.SaveAs(stm);
stm.Close();
}
}