Infoga intervall
Contents
[
Hide
]
Introduktion
I Excel kan du välja ett intervall, sedan infoga ett intervall och skifta andra data höger eller ned.
Infoga Intervall med Aspose.Cells
Aspose.Cells tillhandahåller metoden Cells.InsertRange för att infoga ett intervall.
Infoga Intervall och skifta celler höger
Infoga ett intervall och skifta celler höger med följande koder med Aspose.Cells:
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
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get all the worksheets in the book. | |
WorksheetCollection worksheets = workbook.Worksheets; | |
// Get the first worksheet in the worksheets collection. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create a range of cells. | |
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2"); | |
// Input some data with some formattings into | |
// A few cells in the range. | |
sourceRange[0, 0].PutValue("Test"); | |
sourceRange[1, 0].PutValue("123"); | |
CellArea ca = CellArea.CreateCellArea("A1", "A2"); | |
worksheet.Cells.InsertRange(ca, ShiftType.Right); | |
Console.WriteLine(worksheet.Cells["B1"].StringValue == "Test"); | |
Infoga Intervall och skifta celler ned
Infoga ett intervall och skifta celler ned med följande koder med Aspose.Cells:
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
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get all the worksheets in the book. | |
WorksheetCollection worksheets = workbook.Worksheets; | |
// Get the first worksheet in the worksheets collection. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create a range of cells. | |
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2"); | |
// Input some data with some formattings into | |
// A few cells in the range. | |
sourceRange[0, 0].PutValue("Test"); | |
sourceRange[1, 0].PutValue("123"); | |
CellArea ca = CellArea.CreateCellArea("A1", "A2"); | |
worksheet.Cells.InsertRange(ca, ShiftType.Down); | |
Console.WriteLine(worksheet.Cells["A3"].StringValue == "Test"); | |