ExportDataTableAsString - System.Data.DuplicateNameException

I have a 60x90 worksheet from importing a tab delimited file. Saving the worksheet and viewing in Excel it appears normal with first row as column labels which is desired. Trying to put this worksheet into a DataTable produces the following stack trace:

Unhandled Exception: System.Data.DuplicateNameException: A column named ' ' already belongs to this DataTable.
at System.Data.DataColumnCollection.RegisterColumnName(String name, DataColumn column, DataTable table)
at System.Data.DataColumn.set_ColumnName(String value)
at Aspose.Cells.Cells.ExportDataTableAsString(Int32 firstRow, Byte firstColumn, Int32 rowNumber, Int32 columnNumber, Boolean exportColumnName)

This occurs for any column count greater than 1 and for any row count. The code for this action follows. This is being done in VS 2005 J#.

// Prepare the DataTable of mail merge fields
Workbook workbook = new Workbook();
workbook.Open("samples/CPNTexas3.TXT", FileFormatType.TabDelimited);

// Test the format of the inported file.
//workbook.Save("Texas3.xls", FileFormatType.Excel97);

Worksheets wkshts = workbook.get_Worksheets();
Worksheet wksht = wkshts.get_Item(0);
Aspose.Cells.Cells cells = wksht.get_Cells();
// Create a DataTable from the worksheet
DataTable dataTable = cells.ExportDataTableAsString(1, (ubyte)1, 1, 2, true);

The first three column labels in row 1 are: batch_no, barcode_data, barcode_human.

The .NET reference says Cells version 4.0.2.0 and Runtime v1.0.3705.

Can you tell me what is wrong ?

***

I am not familar with J#, however, I think you should change your code to:

DataTable dataTable = cells.ExportDataTableAsString(0, (ubyte)0, cells.MaxDataRow, cell.MaxDataColumn, true);

Thank you Laurence. That code did not work because of the compile error: "Cannot find field 'MaxDataRow' in type Aspose.Cells.Cells." However, it did reveal the problem which was starting at row 1 instead of row 0 - a venerable and time honored error.

I ended up using "cells.get_MaxRow()" which has no compile error. It would be nice to know why not all the public properties are not visible in VS J#; but, that is a problem we don't need to solve now.

My only excuse is that the API doc says, "The row number of the first cell to export out" which would be taken in spreadsheet terms as 1, rather than zero. :-) But, if I had read the examples it would have been obvious that 0 was the first row. :-)

Thanks again.

Java doesn't support property so all public properties are converted to get/set methods.

We develop Aspose.Cells for .NET with C#. So all indexes are zero based.