不同Excel文件中工作表的移动和复制:
建立3个Excel文件,分别命名为“Source01.xlsx”,“Source02.xlsx”,“destn.xlsx”。将前两个文件中的第一个工作表,分别命名“工作表1”“工作表2”,并移动到“destn.xlsx”文件中去。
//添加引用,在com类型库里 添加Office和Excel引用
using Excel = Microsoft.Office.Interop.Excel;
private void button2_Click(object sender, EventArgs e)
{
//数据源表格
string filename01 = @"D:\Source01.xlsx";
string filename02 = @"D:\Source02.xlsx";
Excel.Application app = new Excel.Application();
app.Visible = false;//app.Visible = true; //选择导出是表格是否打开可见
Excel.Workbook wbSource01 = app.Workbooks.Open(Filename: filename01, ReadOnly: true);
Excel.Worksheet shtSource01 = wbSource01.Worksheets[1];
Excel.Workbook wbSource02 = app.Workbooks.Open(Filename: filename02, ReadOnly: true);
Excel.Worksheet shtSource02 =