Dim strOpenFile,strSaveFile as String
Dim xlsApp As New Excel.Application
Dim xlsWorkBook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsRange As Excel.Range
Dim xlsSrcRange As Excel.Range
strOpenFile = Server.MapPath("..\ReportFormat\test.xls")
strSaveFile = Server.MapPath("..\filetemp\testtarget.xls")
xlsApp.Application.DisplayAlerts = False
xlsApp.Visible = False
'打开格式文件
xlsWorkBook = xlsApp.Workbooks.Open(strOpenFile)
xlsSheet = xlsWorkBook.Sheets(1)
'根据需要的sheet数拷贝格式
xlsSheet.Copy(, xlsWorkBook.Sheets(1))
'获取需要填入数据的sheet
xlsSheet = xlsWorkBook.Sheets(1)
'选择拷贝源的行的下一行
xlsRange = xlsSheet.Rows(3)
'插入一行
xlsRange.Insert()
xlsRange.Insert()
'选择拷贝源
xlsSrcRange = xlsSheet.Rows(2)
'把源拷贝到刚插入的行
xlsSrcRange.Copy(xlsSheet.Rows(3))
xlsSrcRange.Copy(xlsSheet.Rows(4))
'进行数据填充,实际代码根据记录数使用循环
xlsSheet.Cells(2, 1) = "A"
xlsSheet.Cells(2, 2) = 300
xlsSheet.Cells(3, 1) = "B"
xlsSheet.Cells(3, 2) = 400
xlsSheet.Cells(4, 1) = "C"
xlsSheet.Cells(4, 2) = 500
'sheet重命名
xlsSheet = xlsWorkBook.Sheets(1)
xlsSheet.Name = "200501"
xlsSheet = xlsWorkBook.Sheets(2)
xlsSheet.Name = "200502"
'另存为结果表
xlsWorkBook.SaveAs(strSaveFile)
'关闭
xlsWorkBook.Close()
xlsApp.Quit()
xlsApp = Nothing
xlsWorkBook = Nothing
xlsSheet = Nothing
xlsRange = Nothing
xlsSrcRange = Nothing
GC.Collect()