Free Support Forum - aspose.com

ImportDataTable overwriting data

I apologise if this has been asked before. When importing a dataset using ImportDataTable, for some reason the cells to the right of where the data is placed are overwritten with a blank.

For instance, if a dataset consisting of two columns is imported at position A1 (therefore columns 1 and 2 are populated), cells 3+ are being overwritten with blanks.

Is anyone aware of a way to stop this?

Hi,

Thanks for considering Aspose.

Kindly use Cells.ImportDataTable (dataTable, isFieldNameShown, firstRow, firstColumn, insertRows) overloaded version of the method and specify false to the last parameter.

Sample code:

OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=d:\\test\\Northwind.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("Select CustomerID, City from Customers where city='London'",con);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds,"Customers");

Workbook wb = new Workbook();
wb.Open("d:\\test\\datatableBook1.xls");
Worksheet sheet1 = wb.Worksheets[0];
Cells cells = sheet1.Cells;
//Import the datatable
cells.ImportDataTable(ds.Tables["Customers"],true,0,0,false);
wb.Save("d:\\test\\datatable_outBook1.xls");

Attached are the input and output files for your reference.

Thank you.