POI Excel - 绘图边框

POI Excel - 绘图边框 首页 / POI入门教程 / POI Excel - 绘图边框

Apache POI允许无涯教程在工作簿工作表中应用一组边界。 PropertyTemplate 对象使用定义为允许绘制单元格的顶部(top),底部(bottom),左侧(left),右侧(right),水平(horizontal),垂直(vertical),内部(inside),外部(outside)边界的方法和常量对此进行模拟。

看一个示例,其中在单元格周围绘制边框。

链接:https://www.learnfk.comhttps://www.learnfk.com/apache-poi-word/apache-poi-drawing-border.html

来源:LearnFk无涯教程网

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("Learnfk.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 Drawing Border

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

快速上手Kotlin开发 -〔张涛〕

罗剑锋的C++实战笔记 -〔罗剑锋〕

分布式数据库30讲 -〔王磊〕

Redis源码剖析与实战 -〔蒋德钧〕

陈天 · Rust 编程第一课 -〔陈天〕

攻克视频技术 -〔李江〕

现代React Web开发实战 -〔宋一玮〕

超级访谈:对话毕玄 -〔毕玄〕

手把手带你写一个 MiniTomcat -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)