Use aspose. Cells to merge multiple worksheets

Source: Internet
Author: User
Tags rowcount

Source from: huide Control Network

Sometimes, you need to combine multiple worksheets into one. If the manual operation is simple, it is time-consuming and labor-consuming, and the effect is not good, but aspose. cells can be easily implemented. This article will show how to read a source workbook and combine the worksheets into oneCodeExample.

We will copy the content of multiple source worksheets in the workbook to one worksheet.

Source workbook

Here we first create a source workbook with three worksheets. See all three worksheets of the image.

Output Work thin

After running the following sample code, you will get a workbook with only one worksheet, which contains all the data in the preceding three worksheets ,:

Sample Code:

[C #]

String filepath = @ "C: \ source.xlsx"; 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; range destrange = destsheet. cells. createRange (sourcerange. firstrow + totalrowcount, sourcerange. firstcolumn, sourcerange. rowcount, sourcerange. columncount); destrange. copy (sourcerange); totalrowcount = sourcerange. rowcount + totalrowcount;} destworkbook. save ("output.xlsx ");


Dim filepath as string = "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 = 0for I = 0 to workbook. worksheets. count-1 dim sourcesheet as worksheet = workbook. worksheets (I) dim sourcerange as range = sourcesheet. cells. maxdisplayrange dim destrange as range = destsheet. cells. createRange (sourcerange. firstrow + totalrowcount, sourcerange. firstcolumn, _ sourcerange. rowcount, sourcerange. columncount) destrange. copy (sourcerange) totalrowcount = sourcerange. rowcount + totalrowcountnextdestworkbook. save ("output.xlsx ")


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.