Работа с границами в Apache POI и Aspose.Cells

Aspose.Cells - Работа с границами

Aspose.Cells предоставляет класс,Рабочая тетрадькоторый представляет собой файл Excel Microsoft. Класс Workbook содержит коллекцию WorksheetCollection, которая обеспечивает доступ к каждому рабочему листу в файле Excel. Рабочий лист представленРабочий листучебный класс. Класс Worksheet предоставляет коллекцию Cells. Каждый элемент коллекции Cells представляет собой объектCellучебный класс.

Aspose.Cells предоставляет метод setStyle вCellкласс, используемый для установки стиля форматирования ячейки. Кроме того, объект StyleСтильиспользуется класс и предоставляет свойства для настройки параметров шрифта.

Java

 // Style the cell with borders all around.

Style style = workbook.createStyle();

style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());

style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getGreen());

style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlue());

style.setBorder(BorderType.TOP_BORDER, CellBorderType.MEDIUM_DASH_DOT, Color.getBlack());

// Setting style to the cell

cell.setStyle(style);

Apache POI SS — HSSF XSSF — Работа с границами

Класс CellStyle предоставляет функции для установки параметров границ с использованием Apache POI SS — HSSF и XSSF.

Java

 //Setting the line of the top border

style.setBorder(BorderType.TOP_BORDER,CellBorderType.THICK,Color.getBlack());

//Setting the line of the bottom border

style.setBorder(BorderType.BOTTOM_BORDER,CellBorderType.THICK,Color.getBlack());

//Setting the line of the left border

style.setBorder(BorderType.LEFT_BORDER,CellBorderType.THICK,Color.getBlack());

//Setting the line of the right border

style.setBorder(BorderType.RIGHT_BORDER,CellBorderType.THICK,Color.getBlack());

//Saving the modified style to the "A1" cell.

cell.setStyle(style);

Скачать рабочий код

Скачать пример кода