Windows 控件 Microsoft.Office.Interop.Excel 复制sheet

        Dim app As New Microsoft.Office.Interop.Excel.Application()
        app.Visible = False
        app.DisplayAlerts = False
        Dim wbks As Microsoft.Office.Interop.Excel.Workbooks = app.Workbooks
        Dim workbook As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks._Open("文件目录", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)

        '获取sheet
        Dim sheet As Microsoft.Office.Interop.Excel.Worksheet = CType(workbook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)

        '添加sheet
        'workbook.Worksheets.Add()

        '复制sheet
        sheet.Copy(Type.Missing, sheet)

        '保存Excel
        workbook.Save()
        'workbook.SaveAs(filepath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)

        '关闭Excel
        workbook.Close(False, DBNull.Value, DBNull.Value)
        app.Workbooks.Close()
        app.Quit()

        '回收内存
        GC.WaitForPendingFinalizers()
        GC.Collect()

 

你可能感兴趣的:(.net)