We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Export excel to XML

I am using an evaluation version, before buying. I want to know if there is any way to specify the column header while exporting the data from excel to a dataset. I want the data in dataset along with column name.



This message was posted using Aspose.Live 2 Forum


Well, you may simply use Cells.ExportDataTable() method to export the data to fill a data table, one version of ExportDataTable method can take the following parameters to export worksheet data as DataTable object:

* Row Number, represents the row number of the first cell from where the data will be exported
* Column Number, represents the column number of the first cell from where the data will be exported
* Number of Rows, represents the number of rows to export
* Number of Columns, represents the number of columns to export
* Export Column Names, a Boolean property that indicates whether the data in the first row of the worksheet should be exported as column names of the DataTable or not

You need to set true for the last Boolean parameter to export the column names in the first row of the set (you specify) in the worksheet. See the document for reference:

You can also create your own data table and specify your desired columns, then export data in your desired range to fill into that data table, see the sample code below:

Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;

DataTable dt = new DataTable();
dt.Columns.Add(“column1”, typeof(string));
dt.Columns.Add(“column2”, typeof(string));
dt.Columns.Add(“column3”, typeof(string));
dt.Columns.Add(“column4”, typeof(double));
dt.Columns.Add(“column5”, typeof(double));
dt.Columns.Add(“column6”, typeof(double));
dt.Columns.Add(“column7”, typeof(double));
cells.ExportDataTable(dt, 0, 0, 1000, true);

Hope, it helps.

Thank you.