簡體   English   中英

使用VB.net根據預定義的模板將數據導出到Excel

[英]Exporting data into Excel based on a predefined template using VB.net

我在下面粘貼了一個代碼片段,該片段是某人幾年前編寫的。 這是關於基於模板將一些數據導出到excel文件中。 有人能幫我解決以下代碼的問題,因為我無法弄清楚嗎? 提前致謝。

_xlTmp = New Excel.Application _xlTmp.Workbooks.Open(_fileName, , True, , , , , , , True) Dim xlNewSheet = CType(_xlTmp.Worksheets.Item("SHEET1"), Excel.Worksheet) xlNewSheet.Copy(CType(_xlTmp.Worksheets("SHEET2"), Excel.Worksheet)) xlNewSheet = CType(_xlTmp.Worksheets.Item("SHEET1 (2)"), Excel.Worksheet)

'Opens Excel and stores a reference to Excel process
xlTmp = New Excel.Application 

'Opens the excel file with path '_fileName'
_xlTmp.Workbooks.Open(_fileName, , True, , , , , , , True)

'Stores a reference to Sheet named "SHEET1"
Dim xlNewSheet = CType(_xlTmp.Worksheets.Item("SHEET1"), Excel.Worksheet)

'Copies the refered sheet to sheet named "SHEET2" - replacing it                                                                      
xlNewSheet.Copy(CType(_xlTmp.Worksheets("SHEET2"), Excel.Worksheet))

'Reference to the copied sheet
xlNewSheet = CType(_xlTmp.Worksheets.Item("SHEET1 (2)"), Excel.Worksheet)

但是,如果使用Excel COM,則應以不同的方式進行編碼,以便可以在Excel中處置所有“引用某些對象”的對象。 如果找不到文件名或具有給定名稱的工作表,您還將獲得例外。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM