How to reset row index? or rename a column header?

Hello,


I have a worksheet which I deleted row 0-10 before I export it. This cause an issue with the worksheet column header not showing in the export even though I set the value to true for exporting first row as column header. At the moment I think I can resolve this with two solutions but not sure how to do it or it’s even possible:

1. Reset the row index before export so that row index 0 will get pickup by export feature

2. Rename the column header manually.

I’m using ExportDataTableAsString()

Thanks.

Hi,


Thanks for providing us some details.


I think you are using the following overloaded version of ExportDataTableAsString method, here is the complete description of the method:

public DataTable ExportDataTableAsString(
int firstRow,
int firstColumn,
int totalRows,
int totalColumns,
bool exportColumnName
);
Parameters
firstRow
The row number of the first cell to export out.
firstColumn
The column number of the first cell to export out.
totalRows
Number of rows to be imported.
totalColumns
Number of columns to be imported.
exportColumnName
Indicates whether the data in the first row are exported to the column name of the DataTable.

You may only export a contiguous dataset from a starting point/ position (cell - row/column index) in the worksheet, you cannot just skip certain rows or records for your custom needs. As the last Boolean parameter suggests, when you export data set with this parameter’s value as true, it will use first row’s cell values as Column names/headers for the DataTable. So, you should not remove the first row and should remove 1-9 rows rather than deleting only values in those cells in the rows and columns.

Another way is you can first export all the records to your DataTable and then remove your unwanted records/rows (DataRow objects) using .NET’s APIs e.g DataTable.Rows.Remove/RemoveAt() APIs for your needs.

Hope, this helps a bit.

Thank you.

Hello,


Thank you for your quick response. You are right, it is the exact issue I run into. I understand your suggestion, but the actual column header I want is in row 10. Leaving the first row won’t give me the correct column header.

So we don’t have a way to re-index the row index?

Thank you.

Hi,


Just wanted to give an update on this. I just resolved this issue with a workaround by copying row 10 to row 0 before the export. Then I deleted row 1-10 after the export.

I still would like to know if there is way to re-index the row or possible rename column header in aspose.

Thanks!
Hi,

paam:

Just wanted to give an update on this. I just resolved this issue with a workaround by copying row 10 to row 0 before the export. Then I deleted row 1-10 after the export.


You have done right, this would suit your needs.

And I am afraid as I said earlier by default Aspose.Cells would extract contiguous data, so you cannot reset the row index at custom position to evaluate to get Column headers, you cannot rename the column names via Aspose.Cells APIs.

Thank you.