POI微软雅黑等样式操作
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(); } }
相关推荐
chenjia00 2020-07-04
zhangxiaocc 2020-06-10
香帅 2020-06-07
chenjia00 2020-06-03
chenjia00 2020-05-29
大白配小猪 2020-05-27
duckes 2020-05-17
ErixHao 2020-05-04
登峰小蚁 2020-04-17
chenjia00 2020-04-17
stoneechogx 2020-03-04
URML 2020-01-11
dxmkkk 2019-12-09
小西0 2019-12-06
itmale 2019-12-04
在旅途 2019-11-09
newfarhui 2019-11-04