Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to use ClosedXml and Save excel file to local pc

i use closedxml in asp.net project to generate file excel, and now i want to save my excel file to my local pc but it now work. [i already tried from my local browser and it saved to my server folder]. i really need your guide. thanks.

and here is my code :

        Dim wb As XLWorkbook = New XLWorkbook
        wb.Worksheets.Add(datatable01, "sheetdata")
        wb.SaveAs("d:\myfolder\filereport.xlsx")

it's saved in "d:\myfolder\filereport.xlsx" in server side. i need it to my local pc, and if it possible i can choose file folder to save my file in my local pc folder (as file save dialog).

like image 388
Deddy H Avatar asked Dec 16 '25 15:12

Deddy H


1 Answers

i already changed my code and it work, strPath using Server.MapPath also

            ' save ke server
            Dim wb As XLWorkbook = New XLWorkbook
            wb.Worksheets.Add(datatable01, "sheetdata")
            wb.SaveAs(strPath)

            ' save ke local folder
            Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
            response.ClearContent()
            response.Clear()
            response.ContentType = "text/plain"
            response.AddHeader("Content-Disposition", "attachment; filename=" & rptName & ".xlsx" + ";")
            response.TransmitFile(strPath)
            response.Flush()
            response.End()
like image 179
Deddy H Avatar answered Dec 19 '25 04:12

Deddy H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!