Rename duplicate columns automatically while exporting worksheet data

Possible Usage Scenarios

Sometimes a user faces a problem of duplicate columns while exporting data from a worksheet into a DataTable. A DataTable cannot have duplicate columns, so duplicate columns must be renamed before you can export worksheet data to the DataTable. Aspose.Cells can rename the duplicate columns automatically according to the strategy specified by you with ExportTableOptions.RenameStrategy property. If you specify RenameStrategy.Digit, columns will be renamed like column1, column2, column3, etc., and if you specify RenameStrategy.Letter, then columns will be renamed like columnA, columnB, columnC, etc.

Rename duplicate columns automatically while exporting worksheet data

The following sample code adds some data in the first three columns of the worksheet, but all columns have the same name, i.e., People. Then it exports the data from the worksheet into a DataTable by specifying the RenameStrategy.Letter strategy. It then prints the column names of the DataTable generated by Aspose.Cells. The following screenshot shows the DataTable with exported data in the visualizer. As you can see, duplicate columns have been renamed to PeopleA, PeopleB, etc.

todo:image_alt_text

Sample Code

Console Output

Here is the console output of the above sample code for reference.

People
PeopleA
PeopleB