【poi第七节】poi设置excel 设置字体格式,java设置excel设置字体格式

x33g5p2x  于2021-12-28 转载在 其他  
字(1.1k)|赞(0)|评价(0)|浏览(792)

poi设置excel 设置字体格式,java设置excel设置字体格式

  1. import org.apache.poi.hssf.usermodel.HSSFRichTextString;
  2. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  3. import org.apache.poi.ss.usermodel.Cell;
  4. import org.apache.poi.ss.usermodel.CellStyle;
  5. import org.apache.poi.ss.usermodel.Font;
  6. import org.apache.poi.ss.usermodel.Row;
  7. import org.apache.poi.ss.usermodel.Sheet;
  8. import org.apache.poi.ss.usermodel.Workbook;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileOutputStream;
  11. /**
  12. * @ClassName 类名:ExcelDemo7
  13. * @Author作者: hzh
  14. * @Date时间:2018/12/4 15:13
  15. * 设置字体格式
  16. **/
  17. public class ExcelDemo7 {
  18. public static void main(String[] args) throws Exception {
  19. Workbook wb = new HSSFWorkbook();
  20. Sheet sheet = wb.createSheet("hi sheet");
  21. Row row = sheet.createRow(1);
  22. Font font = wb.createFont();
  23. font.setBold(true);
  24. font.setColor((short) 13);
  25. font.setFontHeightInPoints((short) 24);
  26. font.setFontName("宋体");
  27. CellStyle cellStyle = wb.createCellStyle();
  28. cellStyle.setFont(font);
  29. Cell cell = row.createCell(1);
  30. cell.setCellValue("这是测试字体格式的");
  31. cell.setCellStyle(cellStyle);
  32. FileOutputStream fileOutputStream = new FileOutputStream("D://file//font.xls");
  33. wb.write(fileOutputStream);
  34. wb.close();
  35. }
  36. }

相关文章