Problem with dates using CarlosAg.ExcelXmlWriter

I am using CarlosAg.ExcelXmlWriter library to create an Excel file in C #. If I process all the data as strings, everything works fine, but I need some cells that Excel will recognize as date fields. When I try to set the data type accordingly, the resulting Excel file does not open in Excel 2003 (or Excel 2007, for that matter).

In Excel 2003, I get the following error when loading:

Problems occurred in the following area during boot: Table

I use the following code to generate DateTime cells that cause the problem:

string val = DateTime.Now.ToString("MM/dd/yyyy");     
row.Cells.Add(new WorksheetCell(val, DataType.DateTime));

Thanks.

+3
source share
2 answers

. , .

WorksheetStyle, dateStyle, NumberFormat Excel:

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets.Add("myWorksheet");

WorksheetStyle dateStyle = book.Styles.Add("dateStyle");
dateStyle.NumberFormat = "Dd Mmm Yy";

WorksheetRow row = book.Worksheets[0].Table.Rows.Add();

.NET :

string val = DateTime.Now.ToString("s");
row.Cells.Add(val, DataType.DateTime, "dateStyle");
+3

, Excel. , , . Excel .

, . . Excel Date in Numbers. WorksheetStyle.NumberFormat.

+1

Source: https://habr.com/ru/post/1718037/


All Articles