Удалить диапазоны
Contents
[
Hide
]
Введение
В Excel можно выбрать диапазон, затем удалить его и сдвинуть другие данные влево или вверх.
Удаление диапазонов с помощью Aspose.Cells
Aspose.Cells предоставляет метод Cells.DeleteRange, чтобы удалить диапазон.
Удалить диапазоны и сдвинуть ячейки влево
Удалить диапазон и сдвинуть ячейки влево с помощью следующих кодов с 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]; | |
// Gets cells. | |
Cells cells = worksheet.Cells; | |
// Input some data with some formattings into | |
// A few cells in the range. | |
cells["C2"].PutValue("C2"); | |
cells["C3"].PutValue("C3"); | |
CellArea ca = CellArea.CreateCellArea("B2", "B3"); | |
cells.DeleteRange(ca.StartRow, ca.StartColumn, ca.EndRow, ca.EndColumn, ShiftType.Left); | |
Console.WriteLine(worksheet.Cells["B2"].StringValue == "C2"); | |
Удалить диапазоны и сдвинуть ячейки вверх
Удалить диапазон и сдвинуть ячейки вверх с помощью следующих кодов с 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]; | |
// Gets cells. | |
Cells cells = worksheet.Cells; | |
// Input some data with some formattings into | |
// A few cells in the range. | |
cells["B4"].PutValue("B4"); | |
cells["B5"].PutValue("B5"); | |
CellArea ca = CellArea.CreateCellArea("B2", "B3"); | |
cells.DeleteRange(ca.StartRow, ca.StartColumn, ca.EndRow, ca.EndColumn, ShiftType.Up); | |
Console.WriteLine(worksheet.Cells["B2"].StringValue == "B4"); |