我已經將我的excel文件作爲資源添加到了我的vb項目中,並使用了「嵌入式資源」選項。文件「StoredInformation.xlsx」的名稱。 'Build Action'被設置爲'Embedded Resource'。在Resources中讀取和寫入Excel文件
編輯二 - 但我再次卡住了。看來,如果當我運行我的程序
Dim sPath As String
sPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
For i = 1 To 50
Threading.Thread.Sleep(100)
Application.DoEvents()
Next
If My.Computer.FileSystem.FileExists(sPath & "\Housing\Stored Information.xlsx") Then
Dim APP As New Excel.Application
workbook = APP.Workbooks.Open(sPath & "\Housing\Stored Information.xlsx")
worksheet = workbook.Worksheets("Sheet1")
APP.Visible = False
MessageBox.Show("File Opened!" & Environment.NewLine & "Path: " & sPath & "\Housing\Stored Information.xlsx")
Else
My.Computer.FileSystem.WriteAllBytes(sPath & "\Housing\Stored Information.xlsx", My.Resources.StoredInformation, True)
Dim APP As New Excel.Application
workbook = APP.Workbooks.Open(sPath & "\Housing\Stored Information.xlsx")
worksheet = workbook.Worksheets("Sheet1")
APP.Visible = False
MessageBox.Show("File Created!" & Environment.NewLine & "Path: " & sPath & "\Housing\Stored Information.xlsx")
End If
這不是我的創建文件夾「住有所居」或我的文件「存儲Information.xlsx」 可能有人請看看,並告訴我什麼IM我的代碼甚而不工作做錯了?
編輯 - 我發現它不能創建新的目錄,因爲保護級別,所以當我改變目的地到桌面時,它創建了Excel文件,但它需要修復。
有人能告訴我如何創建一個新的文件夾,並添加一個文件,而不會損壞Excel文件?
編輯 - 修改了代碼,它仍然沒有創造我的文檔的新文件夾,並添加「存儲Information.xlsx」文件
當時一個有益的參考,但答案都爲C#,即時尋找Vb.net碼 –
還沒什麼即時尋找 –