Thanks for the amazing library. Really appreciate it.
I am using ClosedXML 0.75.0
I looked at the following documentation on how text with numbers can correctly show up in Excel without the error "Number in the cell is formatted as text or preceded by an apostrophe".
Documentation Go Text with numbers are getting converted to numbers, what's up with that?:
https://closedxml.codeplex.com/wikipage?title=Text%20with%20numbers%20are%20getting%20converted%20to%20numbers%2c%20what%27s%20up%20with%20that%3f&referringTitle=Documentation#
I tried all the options but still when the Excel file is opened the cells that have numbers show the error - "Number in the cell is formatted as text or preceded by an apostrophe".
How can I avoid it.
I used following codes but did not work:
sheet1.Cell("B6").SetValue("123").SetDataType(XLCellValues.Text);
sheet1.Cell("B6").Value = "'123"
In my code, I am actually populating the sheet from a DataTable, which has some numbers.
I tried doing this so avoid the error from Excel but in vain.
Option 1:
IXLWorksheet sheet = _workBook.Worksheets.Add(dt);
IXLRange range = sheet.RangeUsed();
range.Style.NumberFormat.Format = "@";
foreach (IXLCell cell in range.Cells())
{
cell.SetDataType(XLCellValues.Text);
}
Option 2:
IXLWorksheet sheet = _workBook.Worksheets.Add(dt.TableName);
IXLTable mainTable = sheet.Cell(1, 1).InsertTable(dt, false);
foreach (IXLRangeColumn col in mainTable.Columns())
col.DataType = XLCellValues.Text;
For cells with numbers, I an still getting the error from Excel - "Number in the cell is formatted as text or preceded by an apostrophe".
Is there a fix this?
I have attached the spreadsheets generated.
Option 1.xlsx is generated by the code shown in Option 1
Thanks for all your help.
Comments: Optin 2.xlsx is generated from code in Option 2
I am using ClosedXML 0.75.0
I looked at the following documentation on how text with numbers can correctly show up in Excel without the error "Number in the cell is formatted as text or preceded by an apostrophe".
Documentation Go Text with numbers are getting converted to numbers, what's up with that?:
https://closedxml.codeplex.com/wikipage?title=Text%20with%20numbers%20are%20getting%20converted%20to%20numbers%2c%20what%27s%20up%20with%20that%3f&referringTitle=Documentation#
I tried all the options but still when the Excel file is opened the cells that have numbers show the error - "Number in the cell is formatted as text or preceded by an apostrophe".
How can I avoid it.
I used following codes but did not work:
sheet1.Cell("B6").SetValue("123").SetDataType(XLCellValues.Text);
sheet1.Cell("B6").Value = "'123"
In my code, I am actually populating the sheet from a DataTable, which has some numbers.
I tried doing this so avoid the error from Excel but in vain.
Option 1:
IXLWorksheet sheet = _workBook.Worksheets.Add(dt);
IXLRange range = sheet.RangeUsed();
range.Style.NumberFormat.Format = "@";
foreach (IXLCell cell in range.Cells())
{
cell.SetDataType(XLCellValues.Text);
}
Option 2:
IXLWorksheet sheet = _workBook.Worksheets.Add(dt.TableName);
IXLTable mainTable = sheet.Cell(1, 1).InsertTable(dt, false);
foreach (IXLRangeColumn col in mainTable.Columns())
col.DataType = XLCellValues.Text;
For cells with numbers, I an still getting the error from Excel - "Number in the cell is formatted as text or preceded by an apostrophe".
Is there a fix this?
I have attached the spreadsheets generated.
Option 1.xlsx is generated by the code shown in Option 1
Thanks for all your help.
Comments: Optin 2.xlsx is generated from code in Option 2