彩票走势图

使用Aspose.Cells轻松实现工作表合并

原创|其它|编辑:郝浩|2012-09-05 15:22:10.000|阅读 690 次

概述:有时候,我们需要将几个工作表合并为一个,用Aspose.Cells可轻松实现这点:

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

有时候,我们需要将几个工作表合并为一个,用Aspose.Cells可轻松实现这点:

首先,我们来看一下合并前的工作表:

用Aspose.Cells合并工作表

用Aspose.Cells合并工作表

用Aspose.Cells合并工作表

然后,我们输入相应代码:

[C#]

string filePath = @"c:\source.xlsx";

Workbook workbook = new Workbook(filePath);

Workbook destWorkbook = new Workbook();

Worksheet destSheet = destWorkbook.Worksheets[0];

int TotalRowCount = 0;

for (int i = 0; i < workbook.Worksheets.Count; i++)
{
      Worksheet sourceSheet = workbook.Worksheets[i];

      Range sourceRange =

sourceSheet.Cells.MaxDisplayRange;

&nbsp;     Range destRange = destSheet.Cells.CreateRange

(sourceRange.FirstRow + TotalRowCount,

sourceRange.FirstColumn,
            sourceRange.RowCount, sourceRange.ColumnCount);

 &nbsp; &nbsp;  destRange.Copy(sourceRange);

      TotalRowCount = sourceRange.RowCount + TotalRowCount;
}

destWorkbook.Save("output.xlsx");

 

[VB]

 Dim filePath As String = &quot;C:\source.xlsx"

Dim workbook As Workbook = New Workbook(filePath)

Dim destWorkbook As Workbook = New Workbook()

Dim destSheet As Worksheet = destWorkbook.Worksheets(0)

Dim TotalRowCount As Integer = 0

For i = 0 To workbook.Worksheets.Count - 1
     Dim sourceSheet As Worksheet = workbook.Worksheets(i)

    Dim sourceRange As Range =

sourceSheet.Cells.MaxDisplayRange

&nbsp;   Dim destRange As Range = destSheet.Cells.CreateRange

(sourceRange.FirstRow + TotalRowCount,

sourceRange.FirstColumn, _
  sourceRange.RowCount, sourceRange.ColumnCount)

    destRange.Copy(sourceRange)

  &nbsp; TotalRowCount = sourceRange.RowCount + TotalRowCount

Next

destWorkbook.Save("output.xlsx")

最后,让我们一起来看合并后的工作表:

用Aspose.Cells合并工作表


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP