Kombinera flera arkmallar till ett enda ark
Contents
[
Hide
]
Ibland behöver du kombinera flera kalkylblad till ett enda kalkylblad. Detta kan enkelt uppnås med Aspose.Cells API. Den här artikeln visar ett kodexempel som läser in en källbok och kombinerar datan från alla källkalkylblad till ett enda kalkylblad i en målbok.
Följande kodsnutt visar hur du kombinerar flera arkmallar till ett enda ark.
This file contains 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); |