Closed GoogleCodeExporter closed 8 years ago
You can create you own version of CreateWorkbook checking for null values and
changing to blanks.
See code below
public static void CreateWorkbook(String filePath, DataSet dataset)
{
if (dataset.Tables.Count == 0)
throw new ArgumentException("DataSet needs to have at least one DataTable", "dataset");
Workbook workbook = new Workbook();
foreach (DataTable dt in dataset.Tables)
{
Worksheet worksheet = new Worksheet(dt.TableName);
for (int i = 0; i < dt.Columns.Count; i++)
{
// Add column header
worksheet.Cells[0, i] = new Cell(dt.Columns[i].ColumnName);
// Populate row data
for (int j = 0; j < dt.Rows.Count; j++)
//See here??
worksheet.Cells[j + 1, i] = new Cell(dt.Rows[j][i] == DBNull.Value ? "" :
dt.Rows[j][i]);
}
workbook.Worksheets.Add(worksheet);
}
workbook.Save(filePath);
}
Original comment by regisbsb...@gmail.com
on 30 Jul 2011 at 3:02
I had to add a .ToString() at the end of dt.Rows[j][i] to get rid of "Invalid
cell value" error finally :)
Original comment by paronik...@gmail.com
on 26 Jan 2012 at 4:39
I also received this error when the dataset has an item with an Int64. I am
just converting ToString()
Original comment by CurlyHai...@gmail.com
on 29 Aug 2013 at 3:16
Original issue reported on code.google.com by
gregvick...@googlemail.com
on 1 Jul 2011 at 8:29