vb.net 需要使用 ClosedXml 并将 excel 文件保存到本地电脑

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23361311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:28:50  来源:igfitidea点击:

Need to use ClosedXml and Save excel file to local pc

c#asp.netvb.netopenxmlclosedxml

提问by Deddy H

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.

我在 asp.net 项目中使用 closedxml 生成文件 excel,现在我想将我的 excel 文件保存到我的本地电脑,但它现在可以工作了。[我已经在我的本地浏览器中尝试过并将它保存到我的服务器文件夹中]。我真的需要你的指导。谢谢。

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

它保存在服务器端的“d:\myfolder\filereport.xlsx”中。我需要它到我的本地 pc,如果可能,我可以选择文件夹将我的文件保存在我的本地 pc 文件夹中(作为文件保存对话框)。

回答by Deddy H

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

我已经更改了我的代码并且它可以工作,strPath 也使用 Server.MapPath

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