c# excel将A工作表复制到B工作表

Excel跨表复制

Excel.Application excelApplication = null;
Excel.Workbooks excelWorkBooks = null;
Excel.Workbook excelWorkbook = null;
Excel.Workbook excelWorkbook1 = null;
Excel.Worksheet excelWorkSheet = null;
Excel.Worksheet excelWorkSheet1 = null;
Excel.Range range = null;
Excel.Range range1 = null;


public void print(string lujin1,string,lujin2){

excelApplication  = new Excel.ApplicationClass();

excelWorkBooks = excelApplication.Workbooks;

excelWorkbook =((Excel.Workbook)excelWorkBooks.open(lujin1,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,));

ExcelWorkBook.Worksheets.Add();//添加空表

excelWorkSheet = excelWorkBook.Worksheet[1];//获取空表

range = excelWorkSheet.get_Range("A1:F40");//需要粘贴到的对应位置

excelWorkbook1 =((Excel.Workbook)excelWorkBooks.open(lujin2,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,));//打开需复制的文档

excelWorkSheet1 = excelWorkBook.Worksheet[1];//得到工作表

range1 = excelWorkSheet1.get_Range("A1:F40");//获取需要复制的值

range.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteAll,Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.XlPasteSpecialOperationNone,Missing.Value,Missing.Value);//带格式的粘贴

}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值