We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Export datatable to Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

106021 Dec 4,2012 04:12 PM Dec 18,2012 07:52 AM ASP.NET Web Forms (Classic) 4
loading
Tags: XlsIO
David Cleland
Asked On December 4, 2012 04:12 PM

I am using XLsIO v9.4.0.62 and cannot update due to legacy issues.  I have a remote hosted server to which I am publishing a compiled dll which includes an excel document with several macros as a resource.  I need to figure out how to A) Open this excel document and write to it and then  B) export it to the client.  Currently I am opening the resource and trying to save it to the server C:\ drive but I do not think I have write permissions to it and for security reasons won't be given that access. Can I open an existing excel document straight from the dll without first saving it to the server?  I have included my code below.

' get the data
                da.Fill(ds)
                Dim dt As DataTable = ds.Tables(0)
                Dim gamaRpt As Array
                gamaRpt = Global.My.Resources.ResourceManager.GetObject("BetaGamaRptver6_1")
                Global.My.Computer.FileSystem.WriteAllBytes _
                ("C:\GamaRpt", gamaRpt, False)
                wkb = _excelEngine.Excel.Workbooks.Open("C:\GamaRpt")
                'wkb = _excelEngine.Excel.Workbooks.Create(1)
                wkb.StandardFont = "Times New Roman"
                Dim xtab As DataTable
                wks = wkb.Worksheets.Item("Report")
                xtab = GenerateTable(dt)
                'wks.ImportDataTable(xtab, True, 1, 1)
                GenerateSheet(wks, xtab, dt)


                ' save the workbook to a stream
                Dim memStream As New System.IO.MemoryStream
                wkb.SaveAs(memStream)
                wkb.Close()


                'Allow enterprise reports to be downloaded to client machine
                Response.ContentType = "application/vnd.ms-excel"
                Response.AddHeader("Content-Disposition", "attachment; filename=" & "Report.xlsx")
                wkb.SaveXlsx(memStream)
                memStream.WriteTo(Response.OutputStream)
                wkb.Close()

Manikandan M [Syncfusion]
Replied On December 13, 2012 08:20 AM

Hi David,

 

Thank you for using Syncfusion products.

 

We are working on sample creation for directly accessing the file instead of storing it to drive and open it in XlsIO. We will get back to you with sample in one business day.

 

Thank you very much for your patience.

 

Thanks,

Manikandan.M


Manikandan M [Syncfusion]
Replied On December 14, 2012 07:03 AM

Hi David,

Thanks for your patience.

We have created the simplified the sample to directly accessing the workbook instead of the loading it to drive and have attached the same in the below link. please make use of this and let us know if this helps you.

Sample link:LoadWorkbook.zip

Sample scenario:

1. Changed the array bytes of resource to Memory stream.
2. Opened the workbook using memory stream.

Code snippet:
        Dim gamaRpt As Array
        gamaRpt = GetLocalResourceObject("Incident")


        Dim workbookStream As MemoryStream
        workbookStream = New MemoryStream(gamaRpt)

        Dim excelEngine As New ExcelEngine()
        Dim application As IApplication = excelEngine.Excel


        Dim workbook As IWorkbook = application.Workbooks.Open(workbookStream)

Please let us know if you need any clarifications.

Thanks,
Manikandan.M

David Cleland
Replied On December 14, 2012 04:48 PM

Thank you for the response.  I am testing now and will let you know what happens.

Mahajothi R [Syncfusion]
Replied On December 18, 2012 07:52 AM

Hi David,

 

Thank you for the update. Please let us know if you require any further clarifications.

 

Regards,

Mahajothi.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;