删除范围

介绍

在 Excel 中,您可以选择一个范围,然后将其删除并将其他数据向左或向上移动。

Shift 选项

使用 Aspose.Cells 删除范围

Aspose.Cells提供[Cells.DeleteRange](https://reference.aspose.com/cells/java/com.aspose.cells/cells#deleteRange(int,%20int,%20int,%20int,%20int)方法删除范围。

删除范围并向左移动 Cells

删除一个 range 和 shift 单元格,如下代码为 Aspose.Cells:

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.getWorksheets();
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get cells.
Cells cells = worksheet.getCells();
// Set a few cells in the range.
cells.get("C2").putValue("C2");
cells.get("C3").putValue("C3");
CellArea ca = CellArea.createCellArea("B2", "B3");
cells.deleteRange(1,1,2,2, ShiftType.LEFT);
String b2 = worksheet.getCells().get("B2").getStringValue();

删除范围并向上移动 Cells

使用 Aspose.Cells 删除一个范围并将单元格向上移动为以下代码:

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.getWorksheets();
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.getWorksheets().get(0);
// Gets cells.
Cells cells = worksheet.getCells();
// Get cells.
Cells cells = worksheet.getCells();
// Set a few cells in the range.
cells.get("B4").putValue("B4");
cells.get("B5").putValue("B5");
cells.deleteRange(1,1,2,1, ShiftType.UP);