Free Support Forum - aspose.com

Not getting all columns of Excel sheet

I am using AsposeCells to read excel file and after that export the data into datatable.

While reading one of excel file Its returning only 4 columns of the excel sheet, but there were actually 19 columns in that. None of column is hidden.
When I tried to read same excel file through OLEDB, it returns all 19 columns.

Kindly help me in this matter.

Attaching excel file which I tried to attach.

Hi,


Thanks for the template file and some details.

How do you export data from worksheet to fill the DataTable, which sheet your are talking about? I think it might be an issue with your code that you are using (via Aspose.Cells APIs), so kindly evaluate your own code and correct it accordingly. We also recommend you to kindly see the document on data exporting options which you can use to directly save worksheet data into data table here:
http://www.aspose.com/docs/display/cellsnet/Exporting+Data+from+Worksheets

If you still find any issue, kindly create a sample console application (runnable), zip it and post us here to reproduce the issue on our end, we will check it soon.

Thank you.

Hello,



As you suggested I made sample code and attaching with the sample excel file, which I am trying to import. In a code on line no 28, excel file path has hard coded as –

string fileName = @“c:\Ashish_Share\SPAInput_ee8a5581-368a-422f-991a-6f700553e7c4.xls”;



That You need to change according file location at your end.

I am targeting worksheet having name -“COMPLEX” in the attached excel file.

Kindly help me in this matter.

Hi,


Thanks for the sample project and template file.

I have evaluated your scenario/ case using your sample project with the template file. Well, there is an issue with your code segment that you using.

Please change your code segment:
i.e.,
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[sheetName];
int i = worksheet.Cells.Rows.Count;
int j = worksheet.Cells.Columns.Count;

//Exporting the contents of rows and columns starting from 1st cell to DataTable
DataTable stringdataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.Columns.Count, true);

DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.Columns.Count, true);

to:
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[sheetName];
int tRows = worksheet.Cells.MaxDataRow +1;
int tCols = worksheet.Cells.MaxDataColumn +1;

//Exporting the contents of rows and columns starting from 1st cell to DataTable
DataTable stringdataTable = worksheet.Cells.ExportDataTableAsString(0, 0, tRows, tCols, true);

DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, tRows, tCols, true);

it would work fine. Please use Cells.MaxDataRow and Cells.MaxDataColumn attributes instead which give the farthest row and column indexes accordingly.

Let us know if you still have any issue.

PS. I noticed you also included your license file in the project archive. For security concerns, please first remove the project attachment from your post (in the thread) while edit, remove the license file from the project archive and re-archive it and then re-add/ attach the project to your post again. We appreciate your cooperation in this regard.

Thank you.

Thanks Amjad.

Its working. :slight_smile:

Hi,


Good to know that your issue is sorted out now. Feel free to contact us any time if you need further help or have some other queries or issue, we will happy to assist you soon.

Thank you.