下载Excel文件ASP VB.Net

时间:2013-05-10 03:49:41

标签: asp.net vb.net excel

我的目标是下载我创建的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中,我怎样才能保存在桌面路径中并自动下载文件,谢谢

1 个答案:

答案 0 :(得分:1)

试试这个..

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

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

关于自动下载,您可以阅读here

相关问题