Last datarow is missed in excel while importing

Hi Team,

I am importing a datatable to excel file without applying any styles. All the data from the datatable is coming but the last row is skipped. We removed all the styling from the sheet as well but still the last row is not coming.
Could you please help.


Thanks for your query.

Please share your sample files and code snippet with us for our testing. We will reproduce the problem and provide our feedback after analysis.

Hi attach is the excel. i am trying to load a datatable which has 70 rows in the sheet of the sample excel attached.
i am just using the below line if code for it.

workSheetCells.ImportDataTable(datatable, false, startrowindex, StartColumnIndex, false); (3.7 MB)


Thanks for sharing the sample file. You have shared the template file which will be used for saving the data from datatable. I am afraid that this file is not helpful to identify the issue. Please share a complete solution (runnable without any missing reference and without any external database connection) which can be used to reproduce this issue. It should have the hard-coded datatable which is to be imported in the Excel sheet.

I have tried to reproduce this issue using a sample datatable but no issue is observed in the output Excel file and all the rows in the datatable are imported.

Following sample code is used for testing:

// Instantiating a Workbook object            
Workbook workbook = new Workbook();

// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];

// Instantiating a "Products" DataTable object
DataTable dataTable = new DataTable("Products");

// Adding columns to the DataTable object
dataTable.Columns.Add("Product ID", typeof(Int32));
dataTable.Columns.Add("Product Name", typeof(string));
dataTable.Columns.Add("Units In Stock", typeof(Int32));

// Creating an empty row in the DataTable object
DataRow dr = dataTable.NewRow();

// Adding data to the row
dr[0] = 1;
dr[1] = "Aniseed Syrup";
dr[2] = 15;

// Adding filled row to the DataTable object

// Creating another empty row in the DataTable object
dr = dataTable.NewRow();

// Adding data to the row
dr[0] = 2;
dr[1] = "Boston Crab Meat";
dr[2] = 123;

// Adding filled row to the DataTable object

// Importing the contents of DataTable to the worksheet starting from "A1" cell,
// Where true specifies that the column names of the DataTable would be added to
// The worksheet as a header row
worksheet.Cells.ImportData(dataTable, 0,0,new ImportTableOptions() {  });

// Saving the Excel file
workbook.Save(dataDir + "DataImport.out.xls");

Note: It seems that you are using some older version as you are using some deprecated calls in the sample code. Please try the scenario with the latest version Aspose.Cells for .NET 19.1.x and provide the feedback.

i have already tried the code above. But when i generate the report it gets saved and when i open the saved report it says some records removed from sheet2 … excel need to repair the file.

I am afraid that without a runnable solution it is not possible to reproduce this scenario here and provide our assistance. We have tried but could not observe it here with the available code and now you are requested to provide us a sample application for this purpose.