本文概述
- Apache POI绘图边框示例
让我们看一个示例,其中我们在单元格周围绘制边框。
Apache POI绘图边框示例
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderExtent;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.PropertyTemplate;
public class DrawingBorderExample {
public static void main(String[] args) {
try (OutputStream os = new FileOutputStream("srcmini.xls")) {
PropertyTemplate pt = new PropertyTemplate();
pt.drawBorders(new CellRangeAddress(1, 2, 1, 2), BorderStyle.MEDIUM, BorderExtent.ALL);
pt.drawBorders(new CellRangeAddress(5, 6, 1, 2), BorderStyle.MEDIUM, BorderExtent.OUTSIDE);
pt.drawBorders(new CellRangeAddress(5, 6, 1, 2), BorderStyle.THIN, BorderExtent.INSIDE);
pt.drawBorders(new CellRangeAddress(9, 10, 1, 3), BorderStyle.MEDIUM, IndexedColors.GREEN.getIndex(), BorderExtent.OUTSIDE);
pt.drawBorders(new CellRangeAddress(9, 10, 1, 3), BorderStyle.MEDIUM, IndexedColors.BLUE.getIndex(), BorderExtent.INSIDE_VERTICAL);
pt.drawBorders(new CellRangeAddress(9, 10, 1, 3), BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), BorderExtent.INSIDE_HORIZONTAL);
pt.drawBorders(new CellRangeAddress(10, 10, 2, 2), BorderStyle.NONE, BorderExtent.ALL);
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet");
pt.applyBorders(sheet);
wb.write(os);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
【apache poi绘制边界】输出:
文章图片
推荐阅读
- apache poi单元多种风格
- apache poi excel单元格属性
- apache poi隐藏行
- apache poi excel文档标题
- apache poi excel字体
- apache poi合并单元
- apache poi excel单元格颜色
- apache poi excel单元格边界
- apache poi excel单元格