Poi 操作excel样式

Poi 操作excel样式



package com.cloud.poi.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
 * Poi 操作excel样式
 * @author Henry
 */
public class PoiExcelStyleAlter {
	public static void main(String[] args) throws IOException {
		String filePath = "d:/";
		String fileName = "test";
		String fileType = "xlsx";
		Workbook workbook = new XSSFWorkbook();//创建工作簿
		Sheet sheet = workbook.createSheet("test");//创建sheet
		sheet.setColumnHidden(2, true);//隐藏第1列--excel就不显示C纵列了
		Row row = sheet.createRow(1);
		Cell cell = row.createCell(1);
		CellStyle style = workbook.createCellStyle();//新建样式对象
		style.setWrapText(true);//设置自动换行
		XSSFFont font = (XSSFFont) workbook.createFont();//创建字体对象
		font.setFontName("微软雅黑");
		style.setFont(font);
		cell.setCellStyle(style);
		style.setLocked(true);//设置cell所引用的样式是否锁住
		cell.setCellType(XSSFCell.CELL_TYPE_STRING);//设置单元格 格式为 字符串
		cell.setCellValue("test我现在很累,你知道吗,我真的很累。我现在很累很累很累很累!~I 老虎 YOU!");
		File file = new File(filePath + fileName + "." + fileType);
		OutputStream stream = new FileOutputStream(file);
		workbook.write(stream);
		stream.close();
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值