Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VB.net基于预定义模板将数据导出到Excel_.net_Vb.net_Excel_Vba - Fatal编程技术网

使用VB.net基于预定义模板将数据导出到Excel

使用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文件中。有人能帮我们了解一下下面的代码是什么意思吗?因为我无法理解?提前谢谢

_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


但是,如果使用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)