【问题标题】:Download Excel File ASP VB.Net下载 Excel 文件 ASP VB.Net
【发布时间】:2013-05-10 03:49:40
【问题描述】:

我的目标是下载我创建的 excel

到目前为止的代码可以正常工作:

Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)
        xlWorkSheet.Cells(1, 1) = "RECORD_STATUS"
        xlWorkSheet.Cells(1, 2) = "VENDOR_NO"
        xlWorkSheet.Cells(1, 3) = "PARTS_NO"
        xlWorkSheet.Cells(1, 4) = "EFECTIVE_DATE"
        xlWorkSheet.Cells(1, 5) = "CURRENCY_CODE"
        xlWorkSheet.Cells(1, 6) = "PRICE"


        xlWorkSheet.Cells(2, 1) = "A"
        xlWorkSheet.Cells(2, 2) = "NSEA"
        xlWorkSheet.Cells(2, 3) = "13231JX02A"
        xlWorkSheet.Cells(2, 4) = "2013/03/03"
        xlWorkSheet.Cells(2, 5) = "IDR"
        xlWorkSheet.Cells(2, 6) = "10"

        xlWorkSheet.SaveAs("D:\TemplateVendor.xlsx")

        xlWorkBook.Close()
        xlApp.Quit()
        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

这个保存在D盘,如何保存在桌面路径自动下载文件,谢谢

【问题讨论】:

  • 我一定有点困惑,你的最终目标是什么?您创建一个 excel 文件,然后将其保存到驱动器: D. 但是您想将其保存到桌面并自动下载文件?在我看来,只要在你的服务器上为任何人提供文件,让他们从你那里下载,然后他们会选择去哪里......?

标签: asp.net vb.net excel


【解决方案1】:

试试这个..

path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)

xlWorkSheet.SaveAs(path & "TemplateVendor.xlsx")

关于自动下载你可以阅读here

【讨论】:

  • 能否提供excel的样本以便弹出?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多