Hi,
For...
Is this supposed to get rid of the error message in Excel...
"The number in this cell is formatted as text or preceded by an apostrophe"
?
Well, I think while importing data into an excel sheet, it might be possible that your so called numeric data stored in the datatable, is actually coming from string fields(columns).. Well, you may try the following overloaded method:
public int ImportDataTable(
DataTable dataTable,
bool isFieldNameShown,
int firstRow,
byte firstColumn,
bool insertRows,
bool convertStringToNumber
);
I write the following coding example (C#), kindly check it for your need as it works fine:
DataSet ds = new DataSet();
System.Data.DataTable dt = new DataTable("MyTable");
dt.Columns.Add("Field1", typeof(string));
for (int i = 1; i<=40;i++)
{
System.Data.DataRow dr = dt.NewRow();
dr["Field1"]=i*2;
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Cells.ImportDataTable(ds.Tables[0], true, 0, 0,false,true);
sheet.Cells.Columns[0].Style.Number = 1;
workbook.Save("d:\\test\\numberedcols.xls", FileFormatType.Excel2000);
For ....
workbook.Worksheets[0].Cells.Columns[2].Style.Number = 1;
workbook.Worksheets[0].Cells.Columns[2].ApplyStyle(style, flag)
Well, both are equal and works ok.
If you still find some problems, could you create a simple example with an output template file and post us here. so that we may sort out your issue soon.
Thank you.