複数のワークシートを 1 つのワークシートに結合する
Contents
[
Hide
]
場合によっては、複数のワークシートを 1 つのワークシートに結合する必要があります。これは、Aspose.Cells API を使用して簡単に実現できます。この記事では、ソース ワークブックを読み取り、すべてのソース ワークシートのデータを結合して、宛先ワークブック内の 1 つのワークシートにするコード例を示します。
次のコード スニペットは、複数のワークシートを 1 つのワークシートに結合する方法を示しています。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "SampleInput.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; | |
Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn, | |
sourceRange.RowCount, sourceRange.ColumnCount); | |
destRange.Copy(sourceRange); | |
TotalRowCount = sourceRange.RowCount + TotalRowCount; | |
} | |
dataDir = dataDir + "Output.out.xlsx"; | |
destWorkbook.Save(dataDir); |