poi3.17excel加边框

本文将详细讲解如何利用Java的Apache POI库,在版本3.17下为Excel单元格添加不同类型的边框,包括粗细、颜色和样式,以增强表格的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
	 * 给合并单元格加边框
	 * @throws IOException
	 */
	public static void border() throws IOException {
		CellRangeAddress CellRangeAddress1 = new CellRangeAddress(5,6,3,4);
		InputStream input = new FileInputStream(new File("d:/q1.et"));
		HSSFWorkbook workbook = new HSSFWorkbook(input);
		HSSFSheet sheet = workbook.getSheet("qqq");  
		sheet.addMergedRegion(CellRangeAddress1);//合并单元格
		  RegionUtil.setBorderLeft(1, CellRangeAddress1, sheet);
		  RegionUtil.setBorderBottom(1, CellRangeAddress1, sheet);
		  RegionUtil.setBorderRight(1, CellRangeAddress1, sheet);
		  RegionUtil.setBorderTop(1, CellRangeAddress1, sheet);
		  //给合并的单元格加边框	 
		FileOutputStream	output = new FileOutputStream(new File("d:/q1.et"));
		workbook.write(output);
		if (output != null) {
			try {
				output.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}

	/**
	 * 给指定单元格加边框
	 * @throws IOException
	 */
	public static void  cellBorder() throws IOException {
		HSSFWorkbook workbook=new HSSFWorkbook(); // 定义一个新的工作簿
				Sheet sheet=workbook.createSheet("第一个Sheet页");  // 创建第一个Sheet页
				Row row=sheet.createRow(0); // 创建一个行    
				Cell cell=row.createCell(6); // 创建一个单元格
				cell.setCellValue(4);
				HSSFCellStyle cellStyle = workbook.createCellStyle();       
				// 设置单元格边框
				cellStyle.setBorderBottom(BorderStyle.DOTTED); //下边框    
				cellStyle.setBorderLeft(BorderStyle.THIN);//左边框    
				cellStyle.setBorderTop(BorderStyle.DOTTED);//上边框    
				cellStyle.setBorderRight(BorderStyle.THIN);//右边框    
				cell.setCellStyle(cellStyle);
				FileOutputStream	output = new FileOutputStream(new File("d:/1111.et"));
				workbook.write(output);
				if (output != null) {
					try {
						output.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值