1
我有這樣的代碼:ASP.NET到Excel導出 - 參考文件並打開另存爲對話框?
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Here we go. All the data in the form to an Excel sheet. Cross your fingers...
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Start a new workbook in Excel- this isn't really what I need though, I need it to open a template and populate it.
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("C:\Users\jagtars\Desktop\HI Resources\HI.xlsx")
'Add data to cells of the first worksheet in the new workbook
oSheet = oBook.Worksheets(1)
oSheet.Range("H5").Value = CustomerName.Text
oSheet.Range("K5").Value = dropdown_serverVirtualisation.Value
oSheet.Range("L5").Value = dropdown_desktopVirtualisation.Value
oSheet.Range("M5").Value = dropdown_oracle.Value
oSheet.Range("N5").Value = dropdown_sqlServer.Value
'etc....
'Save the Workbook and Quit Excel
oBook.SaveAs("C:\Users\jagtars\Desktop\HI.xlsx")
MessageBox.Text = "Exported!"
MessageBox.Focus()
oExcel.Quit()
End Sub
此代碼在我的桌面文件夾抓起一個文件,然後對其進行編輯,並將其保存在我的桌面一個新的文件「HI」。
相反,我想把這個文件放在我的項目文件夾中,然後引用它,之後用戶應該可以選擇他們想要保存新修改文件的位置。
我需要在我的代碼中修改以實現此目的?
謝謝大家。
您必須從客戶端瀏覽器(它將在其他位置)在思維上斷開您的ASP.NET代碼隱藏(在服務器上運行)。 – Alexander