Free Support Forum -

cells.ImportFromDataReader() method does not poppulate cells in v4.8.0


I updated the component to the latest release( v4.8) and ran the existing code to verify some fixes.

But it seems that excel cells are not being populated and excel sheet is empty.

I am not sure if I am missing anything here.

There is no change in code. To verify the issue, I reverted back to older version and it started working fine.

Any comments?


Hi Jignesh,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Please provide us further details regarding your issue. Which version of Aspose.Cells for .NET you were using before. Also, please share your sample code to reproduce the issue and we will check it soon.

Thank You & Best Regards,


Thanks for your quick response.

We are currently using v4.7.1. And here is the sample code:



Aspose.Cells.Workbook asposeWS = new Aspose.Cells.Workbook();

Aspose.Cells.Cells cells = asposeWS.Worksheets[0].Cells

using (IDataReader reader = db.ExecuteReader(command))


IRange range = cells.CreateRange(0, 0, 1, columnHeadings.Count);

range.ApplyStyle(this.headerStyle, this.headerStyleToken);

// Write column headings into Excel.


// Bulk import database values (into Excel) from the data reader.

cells.ImportFromDataReader((SqlDataReader)reader, FirstDataRow, FirstDataColumn);



catch (Exception e)


throw new Exception(

string.Format("{0} : {1} - {2} ",



"Failure bulk-importing data into Excel cells from an IDataReader."),



After this, cells collection is empty and saved excel document contains header information only.

Hope this helps,


Hi Jignesh,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I think your code is a mixture of Aspose.Cells APIs & Office Automation. You may simply use Aspose.Cells APIs to get your desired results. Please see the following code for your reference:

Aspose.Cells.Workbook asposeWS = new Aspose.Cells.Workbook();

Aspose.Cells.Cells cells = asposeWS.Worksheets[0].Cells;

//Create command object and Fill Reader

OleDbCommand oleDbSelectCommand1 = new OleDbCommand();

string path = "C:\\Program Files\\Microsoft Office\\OFFICE11\\SAMPLES\\Northwind.mdb";

string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;

OleDbConnection oleDbConnection1 = new OleDbConnection(ConnectionString);

oleDbSelectCommand1.CommandText = "SELECT CategoryID, CategoryName, Description FROM Categories";

oleDbSelectCommand1.Connection = oleDbConnection1;


OleDbDataReader reader = oleDbSelectCommand1.ExecuteReader();

//Import data with header using Aspose.Cells

cells.ImportFromDataReader(reader, true,0, 0, true);



//Create <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Aspose.Cells Range and Apply Header Style

Range range = cells.CreateRange(0, 0, 1, cells.MaxDataColumn+1);

Style headerStyle = asposeWS.Styles[asposeWS.Styles.Add()];

headerStyle.ForegroundColor = Color.Black;

headerStyle.Pattern = BackgroundType.Solid;

headerStyle.Font.Color = Color.White;

StyleFlag headerStyleToken = new StyleFlag();

headerStyleToken.CellShading = true;

headerStyleToken.FontColor = true;

range.ApplyStyle(headerStyle, headerStyleToken);



The Resultant File is attached.

Also, you may check the following documentation link for details regarding importing data to worksheet and see our online demos for your reference.

If you still face any problem after updating your code, please create a simple console application to reproduce the issue and post it here and we will check it soon.

Thank You & Best Regards,


Well, we don't use any VSTO APIs at all. Some interfaces that you saw in my sample code are our internal ones. And they don't have anything to do with VSTO APIs.

Besides, I have another question:

I get unreadable contents error when I export the data in Excel 2007 format. But this happens only in some cases. So code is same but depending on resultset from database, I get this error. So I was wondering if you can provide any data related constraints/restrictions which might cause this issue.

I noticed that there are couple of fixes for this issue in latest release.

But I encountered original issue and could not use latest version. Original issue still happens at my end.

How can I assist in providing more info? Any comments?


Hi Jignesh,

Thank you for considering Aspose.

We will appreciate it if you can create a sample application and post it here to reproduce the issue. We will check it soon.

Thank You & Best Regards,