使用VB.net基于预定义模板将数据导出到Excel
我在下面粘贴了一段代码片段,它是几年前有人写的。这是关于基于模板将一些数据导出到excel文件中。有人能帮我们了解一下下面的代码是什么意思吗?因为我无法理解?提前谢谢 _xlTmp=新的Excel.Application _xlTmp.Workbooks.Open_文件名,True,,,,True Dim xlNewSheet=CType_xlTmp.Worksheets.ItemSHEET1,Excel。工作表xlNewSheet.CopyCType_xlTmp.worksheetsheets2,Excel。工作表 xlNewSheet=CType_xlTmp.Worksheets.ItemSHEET1 2,Excel.Worksheet使用VB.net基于预定义模板将数据导出到Excel,.net,vb.net,excel,vba,.net,Vb.net,Excel,Vba,我在下面粘贴了一段代码片段,它是几年前有人写的。这是关于基于模板将一些数据导出到excel文件中。有人能帮我们了解一下下面的代码是什么意思吗?因为我无法理解?提前谢谢 _xlTmp=新的Excel.Application _xlTmp.Workbooks.Open_文件名,True,,,,True Dim xlNewSheet=CType_xlTmp.Worksheets.ItemSHEET1,Excel。工作表xlNewSheet.CopyCType_xlTmp.worksheetsheets
但是,如果使用Excel COM,则应以不同的方式编写代码,以便可以处理引用Excel中某些内容的所有对象。如果找不到文件名或具有给定名称的工作表,您也会遇到例外情况。非常感谢您的回复。这很有帮助。
'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)