将Excel工作表复制到C#中的另一个工作簿

时间:2016-10-24 08:25:53

标签: c# excel

我有一张包含签名行的Excel工作表。我试图将此工作表复制到另一个工作簿,但可以复制工作表的值,但签名行除外。我认为这种复制方法是基于细胞的。

如何将签名行发送到另一个工作簿。这是我的代码

        Excel._Application xlApp;
        Excel.Workbook xlTemplateWB;
        Excel.Workbook xlTempWB;
        object missing = System.Reflection.Missing.Value;

        xlApp = new Excel.Application();
        xlApp.Visible = true;

        //Open Bench Sheet Template
        xlTemplateWB = xlApp.Workbooks.Open(@"C:\TempProjects\test.xlsx", 0, true, 5, "", 
        "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

        //Save As a temporary workbook
        xlTemplateWB.SaveAs(@"C:\\TempProjects\mytmp.xlsx");

        //Open temporary workbook
        xlTempWB = xlApp.Workbooks.Open(@"C:\TempProjects\my.xlsx", 0, false, 5, true, "",
        true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

        xlTemplateWB.Worksheets.Copy(xlTempWB.Worksheets["Sheet1"]);
        xlTemplateWB.Close(true, missing, missing);
        releaseObject(xlTemplateWB);

        xlTempWB.Save();

        //Close Workbooks
        xlTempWB.Close(true, missing, missing);
        xlApp.Quit();

        //Release Objects
        releaseObject(xlTempWB);
        releaseObject(xlApp);

0 个答案:

没有答案