Is there any way to specify column names to be imported into a cell using ImportDataTable

Hello,

I have some data in a data table to be imported into a cell. The same datatable is be used in other functions in the website, so I can not alter the original datatable. How do I specify the columns that I want to be imported into a cell? The code below only imports the entire datatable.

Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

sheet.Name = "importing a datatable";

sheet.Cells.ImportDataTable(dtData, false, "A8");

Hi,

Well, I think you may try to utilize Cells.ImportDataColumn for your task. Here is an example, kindly consult it.

Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];
sheet.Cells["A1"].PutValue("Import a DataColumn");
sheet.Cells["A1"].Style.Font.IsBold = true;
DataTable dataTable = new DataTable("Products");
dataTable.Columns.Add("Product ID", typeof(Int32));
dataTable.Columns.Add("Product Name", typeof(string));
dataTable.Columns.Add("Units In Stock", typeof(Int32));

DataRow dr = dataTable.NewRow();
dr[0] = 1;
dr[1] = "Aniseed Syrup";
dr[2] = 15;
dataTable.Rows.Add(dr);

dr = dataTable.NewRow();
dr[0] = 2;
dr[1] = "Boston Crab Meat";
dr[2] = 123;
dataTable.Rows.Add(dr);
//It imports the second column (Product Name), import starts at A8 cell.
sheet.Cells.ImportDataColumn(dataTable, true, 7, 0, 1, false);
workbook.Save("d:\\test\\importingcolumns.xls");

Thank you.