[英]How to programmatically select multiple sheets and copy to the same workbook at the same time in C#
I'm looking for some advices.我正在寻找一些建议。
I'm sorry, I don't know how to make it clarify in text, so, I will show you what I need to achieve via Excel instead.对不起,我不知道如何在文本中澄清,所以,我将向您展示我需要通过 Excel 实现的目标。
I would like to know 2 things我想知道两件事
The reason why I want to copy both in 1 shot because I put formula in Sheet1 in cell A1 which is "=Sheet2!A1".我想一次复制两者的原因是因为我将公式放在单元格 A1 中的 Sheet1 中,即“=Sheet2!A1”。 If I copy it one by one the formula won't change but If I select both sheets and copy at the same time, the formula will change to "=Sheet2(2)!A1" automatically << This is what I intend to do.如果我一一复制,公式不会改变,但如果我同时选择两个工作表并复制,则公式将自动更改为“=Sheet2(2)!A1”<<这就是我打算做的.
Which excel interop command should I use to achieve this result ?我应该使用哪个 excel interop 命令来实现这个结果?
I think this is what you need:我认为这就是你需要的:
var MyApp = new Excel.Application();
MyApp.Visible = false;
var MyBook = MyApp.Workbooks.Open(path);
Excel.Worksheet sheet = (Excel.Worksheet)MyBook.Sheets[1];
sheet.Copy(MyBook.Sheets[MyBook.Sheets.Count]);
sheet = (Excel.Worksheet)MyBook.Sheets[2];
sheet.Copy(MyBook.Sheets[MyBook.Sheets.Count]);
MyBook.Save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.