Aspose.Cells如何处理大数据量的Excel文件合并

作者:控件中国网   出处:控件中国网   2015-07-22 10:00:20   阅读:40

在很多时候客户需要把存在的Excel文件进行合并处理,Aspose.Cells为开发人员提供了几种Excel文件合并的方法,对于简单且不大的文件的合并可采用 Workbooks.Combine()方法,Worksheet.Copy()方法可以实现把一个工作表复制到另外一个Excel文件里,但是如果需要对数据量大的Excel文件进行合并时,这两种方法就不是很效率了。控件针对大的Excel文件合并,则提供了CellsHelper.MergeFiles方法,注意该方法只支持合并数据、样式、格式化以及公式,对于图表、图片以及评论等不能合并。具体请参考下面的代码:

//Create an Array (length=2)
string[] files = new string[2];
//Specify files with their paths to be merged
files[0] = @"e:\test2\MyBook1.xls";
files[1] = @"e:\test2\MyBook2.xls";

//Create a cachedFile for the process
string cacheFile = @"e:\test2\temporaystoragefile.txt";
//Output File to be created
string dest = @"e:\test2\OutputGrandBook.xls";

//Merge the files in the output file
CellsHelper.MergeFiles(files, cacheFile, dest);


//Now if you need to rename your sheets, you may load the output file
Workbook workbook = new Workbook("e:\\test2\\OutputGrandBook.xls");

int i = 1;

//Browse all the sheets to rename them accordingly
foreach (Worksheet sheet in workbook.Worksheets)
{
        sheet.Name = "My_Custom_Sheet_" + i.ToString();
        i++;

}

//Re-save the file
workbook.Save("e:\\test2\\OutputGrandBook1.xls");

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat