ExportTableOptions.Indexes property used in ExportDataTable() method causes "Index was outside the bounds of the array exception"

Could you please provide some sample how to use this property? i had tried many values in int[] but it always give me Index was outside the bounds of the array exception.

I want to export specific columns from my excelsheet by matching the names from first row.

@HimanshuPanwar

Thanks for using Aspose APIs.

We tested this issue with the following code and it seems like error. We will look into this issue further and update you asap.

C#

Workbook wb = new Workbook("sample.xlsx");

Worksheet ws = wb.Worksheets[0];

ExportTableOptions opts = new ExportTableOptions();
opts.ExportColumnName = true;
opts.Indexes = new int[] {0, 2, 3};

DataTable dt = ws.Cells.ExportDataTable(0, 0, 15, 6, opts);

@HimanshuPanwar

The property ExportTableOptions.Indexes works OK . It is just used to change the position of the columns. I have explained how to use it in the following code and its screenshots. Please also check the sample Excel file used in this code for a reference.

Download Link:
Sample Excel File.zip (6.6 KB)

C#

//Load sample workbook
Workbook wb = new Workbook("sample.xlsx");

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Specify export table options - explains the usage of Indexes property
ExportTableOptions opts = new ExportTableOptions();
opts.ExportColumnName = true;
opts.Indexes = new int[] { 5, 4, 1, 3, 2, 0 };

//Export Data Table with Export Table Options
DataTable dt = ws.Cells.ExportDataTable(0, 0, 15, 6, opts);

Screenshots

Okay. I might had not explained a better way but i do not want just to change the column ordering in exported data table, i want to limit the columns exported like in your example if i want to skip column 2 and 5 what values do i need to provide as int[]? does this functions support this functionality? i will get an error if i miss any column index from the array i.e. options.Indexes = new int[] { 5, 3,2, 0 }; this will throw an error.

pls let me know if more info needed.

@HimanshuPanwar

Thanks for your feedback and using Aspose APIs.

We have logged your issue as follow

  • CELLSNET-45751 - ExportTableOptions.Indexes property used in ExportDataTable() method causes- Index was outside the bounds of the array exception

@HimanshuPanwar

Thanks for using Aspose APIs.

This is to inform you that we have fixed your issue CELLSNET-45751 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

hey, thank you for the information. When can we expect a fix to be released for GA?

@HimanshuPanwar

The issue has already been marked as fixed. However, fix is not available yet. At most, you will have to wait till 25th of this month. Because we will publish the official release 17.11 somewhere between 20-25th and it will contain the fix of your issue.

The issues you have found earlier (filed as CELLSNET-45751) have been fixed in this Aspose.Cells for .NET 17.11 update.

Please also check the following article: