ExportDataTable with columns int array specified not working

Hello,


I’ve been trying to get the ExportDataTable feature working for quite some time now and have absolutely no clue what I’m doing wrong but the overloaded form of this method with the column indexes doesn’t seem to work.

My sample code is:
// Same order as the Excel sheet has
DataTable data = new DataTable();
data.Columns.Add(“Name”);
data.Columns.Add(“Num”);
data.Columns.Add(“Date”);

int[] cols = {2}; // changing this value does nothing

worksheet.Cells.ExportDataTable(data, 0, cols, 100, false);

When the code runs, the DataTable data contains only the first column of Data from the excel table, but I specified the index 2, so shouldn’t it just be Date? I’ve tried several variations of this code and it always seems to just ignore the column indexes and return the first n columns. Any help would be appreciated. For now I’ll just be copying the entire data set, then filtering manually. Thanks!

Hi,


I can notice the issue as you have mentioned by using the following sample code.

Sample code:

Workbook wb = new Workbook();
Worksheet worksheet = wb.Worksheets[0];

for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 3; j++)
{
worksheet.Cells[i, j].PutValue("Test: " + i.ToString() + “,” + j.ToString());

}
}



// Same order as the Excel sheet has
DataTable data = new DataTable();
data.Columns.Add(“Name”);
data.Columns.Add(“Num”);
data.Columns.Add(“Date”);

int[] cols = { 2 }; // changing this value does nothing

worksheet.Cells.ExportDataTable(data, 0, cols, 100, false);

Worksheet sheet2 = wb.Worksheets[wb.Worksheets.Add()];
sheet2.Cells.ImportDataTable(data, false, “A1”);

wb.Save(“e:\test2\output.xls”);

Note: the second sheet only displays the first column values.


I have logged a ticket with an id:CELLSNET-40894. We will look into it to figure it out soon.


By the way, if you need to get only one column in the data table, you may try:

Workbook wb = new Workbook();
Worksheet worksheet = wb.Worksheets[0];

for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 3; j++)
{
worksheet.Cells[i, j].PutValue("Test: " + i.ToString() + “,” + j.ToString());

}
}



// Same order as the Excel sheet has
DataTable data = new DataTable();
data.Columns.Add(“Date”);

int cols = 2;

worksheet.Cells.ExportDataTable(data, 0, cols, 100, false);

Worksheet sheet2 = wb.Worksheets[wb.Worksheets.Add()];
sheet2.Cells.ImportDataTable(data, false, “A1”);

wb.Save(“e:\test2\outputcol.xls”);

Thanks for the response. I have a workaround that I’ll use. I had another question but I’ll just post it rather than go off-topic from original post. Thanks again!

Hi,

Thanks for your posting and using Aspose.Cells.

Yes, it’s a good idea, please create newer threads for your newer questions. It will helpful for other forum users too.

Please feel free to post whatever question or issue you face, we will be glad to help you asap.

Hi,

Please download and try this fix: Aspose.Cells for .NET (Latest Version)

We have fixed your issue

Thanks,