Multiple ImportDataTable() calls = odd data positioning

I have a System.Data.DataSet with a collection of DataTables. I am using the ImportDataTable method to import these DataTables one by one to an Excel worksheet. Each time I insert a table, I increment a column counter so that the tables are inserted next to each other.

The header rows of the tables export correctly; they all appear in the first row of the worksheet. The data rows however are “pushed” down on the sheet instead of beginning one row directly below the header row.

This is the call I make:

sheet.Cells.ImportDataTable(ds.Tables[dtIndex], true, cells[commodityStartRow, commodityStartColumn].Name);

Call 1: { dtIndex = 0, commodityStartRow = 0, commodityStartColumn = 0 }
Call 2: { dtIndex = 1, commodityStartRow = 0, commodityStartColumn = 7 }
Call 3: { dtIndex = 2, commodityStartRow = 0, commodityStartColumn = 14 }

The call then repeats for another two worksheets, but it is the first worksheet I am interested in.

When I open the worksheet, the data rows of the third table are correctly positioned. However, the data rows of the second table are “pushed” down 3 rows, and then the data rows of the first table are “pushed” down 13 rows.

I want the data rows of each table to be directly below the column headers. How do I fix this?

Thank you!

I figured out what was causing this - I needed to specify “false” for the “bool insertRows” parameter.

Admittedly, I am not exactly sure what this parameter specifies or why using false solves my issue. I read about the ImporDataTable() function on this page:

Aspose.Total Product Family

But I did not see mention of this parameter. Could someone perhaps point me to the documentation of this function?

Hi,

Yes, you did right. Well, by default, when you use the overloaded version of ImportDataTable method i.e. ImportDataTable(DataTable dt, bool isFieldNameShown, int firstrow, int firstcol), extra rows would be inserted every time based on the number of rows contained in the datatable. The insertRows boolean parameter in the method e.g ImportDataTable(DataTable dt, bool isFieldNameShown, int firstrow, int firstcol, bool insertRows) specifies that there will be no extra rows inserted for the import operation, Aspose.Cells for .NET will use the existing rows, so the problem of positioning of existing data would not happen when importing multiple datatables for your scenario.

Please check the API reference: http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/aspose.cells.cells.importdatatable_overload_4.html

Thank you.

Thank you for the explanation and for the reference link.