Essential XlsIO如何从Excel文件中复制单元格内容到另外一个Excel

作者:控件中国网   出处:控件中国网   2016-09-28 09:47:24   阅读:4

Essential XlsIO是一款类似Excel的电子数据表格控件,可以对Excel文件进行各种操作,对单元格进行各种格式化,设置单元格类型、插入公式等,这篇文章主要介绍如何使用Essential XlsIO提供的API来从一个Excel文件中的单元格复制内容到另外一个Excel中,具体如下:
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook sourceWorkbook = application.Workbooks.Open("SourceWorkbook.xlsx", ExcelOpenType.Automatic);
IWorkbook destinationWorkbook = application.Workbooks.Open("DestinationWorkbook.xlsx", ExcelOpenType.Automatic);
IWorksheet SourceWorksheet = SourceWorkbook.Worksheets[0];
//The first worksheet object in the worksheets collection in the Destination Workbook is accessed.
IWorksheet DestinationWorksheet = DestinationWorkbook.Worksheets[0];
//Assigning an object to the range of cells (90 rows) both for source and destination.
IRange sourceRange = SourceWorksheet.Range[1, 1, 90, 100];
IRange destinationRange = DestinationWorksheet.Range[1, 1, 90, 100];
//Copying (90 rows) from Source to Destination worksheet.
sourceRange.CopyTo(destinationRange);
destinationWorkbook.SaveAs("CopyingRange.xlsx");
destinationWorkbook.Close();
excelEngine.Dispose();
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat