I have pasted a code snippet below which was written by someone some years ago. This is regarding exporting some data into an excel file based on a template. Can someone please help we with what the below code means as I am not able to figure it out? Thanks in advance.
_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)
However, if you use Excel COM you should code in a different way, so you can dispose all objects "referencing something" in Excel. You will also get exceptions if the filename or sheets with given names are not found.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.