Using DataReader

Greetings,

Is there a way to use a datareader when populating a spreadsheet? I have been able to create a spreadsheet using a datatable but it would be so much easier to create one from a datareader. Is this supported? If so could someone give me an example of how to do it.

Thanks!

Zack

Hi Zack,

Currently importing data directly from a datareader is not supported. I will add it in Aspose.Excel. I think it will be available in next week.

Hi Zack,

Now it’s available. Please download the latest hotfix and have a try. You can use Cells.ImportFromDataReader 3 method to import data from a datareader.

Laurence,

Thank you so much for adding this capability! Unfortuantely I can’t seem to get it working right. Below is the code I’m using:

Dim drdMaster As SqlDataReader
drdMaster = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings(“connStr”), CommandType.StoredProcedure, “MasterCustomerList”)
Dim Excel As New Excel
Dim Path As String
Path = "C:\Inetpub\wwwroot\ASPTest\Templates\MasterCustomerList.xls"
Excel.Open(Path)
Dim Sheet As Worksheet = Excel.Worksheets(0)
Sheet.Cells.ImportFromDataReader(drdMaster, 4, 1, True)
Sheet.Name = "Master Customer List"
Excel.Save(“Master Customer List.xls”, FileFormatType.Default, SaveType.OpenInBrowser, Me.Response)

When I run the above code I see a couple of “Unable to Open file” warning dialog boxes and then I’m prompted to open or save the spreadsheet. When I try to open it I receive an error that the excel file was damaged and that excel tried to repair it, etc.

I’ve checked directory where I’m storing my template files and made sure the IIS account has read/write permissions as well as having read/write permissions on the xls file.

Any hints or tips would be appreciated. BTW, if you see me online (zackojones@hotmail.com) on MSN feel free to ask any questions you may have.

Thanks!

Zack


Dear Zack,

I think this problem may be caused by your template file. Please remove this line of code and see if your problem disappears.
Excel.Open(Path)

And please check if you use the latest hotfix. It’s v2.3.4.



If you find your template file does cause the problem, please send it to me at excel@aspose.com. Thanks.

Laurence,

Removing the Excel.Open(Path) line did fix the problem. I’m emailing the template file.

Zack

Please change

Excel.Save(“Master Customer List.xls”, FileFormatType.Default, SaveType.OpenInBrowser, Me.Response)

to Excel.Save(“Master Customer List.xls”,SaveType.OpenInBrowser, FileFormatType.Default, Me.Response)

VB cannot check this error at compile time.