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. Image for the cookie policy date

Export datatable to Excel

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()

4 Replies

MM Manikandan M Syncfusion Team December 13, 2012 01:20 PM UTC

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



MM Manikandan M Syncfusion Team December 14, 2012 12:03 PM UTC

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


DC David Cleland December 14, 2012 09:48 PM UTC

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


MR Mahajothi R Syncfusion Team December 18, 2012 12:52 PM UTC

Hi David,

 

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

 

Regards,

Mahajothi.


Loader.
Live Chat Icon For mobile
Up arrow icon