zoukankan      html  css  js  c++  java
  • Java使用poi对Execl简单_写_操作

     1 public class WriteExecl {
     2     
     3     @Test
     4     public void writeExeclTest() throws Exception{
     5         OutputStream os = new FileOutputStream("F:/execl/writeTest2.xlsx");
     6 //        Workbook wb = new HSSFWorkbook(); // 创建一个 2003 版本的Execl
     7         Workbook wb = new XSSFWorkbook(); // 创建一个 2007 以上版本的Execl
     8         
     9         CellStyle cellStyle = wb.createCellStyle(); // 创建一个样式
    10         cellStyle.setBorderLeft(CellStyle.BORDER_THIN); // 单元格边框粗细
    11         cellStyle.setBorderRight(CellStyle.BORDER_THIN);// 单元格边框粗细
    12         cellStyle.setBorderTop(CellStyle.BORDER_THIN);// 单元格边框假粗细
    13         cellStyle.setBorderBottom(CellStyle.BORDER_THIN);// 单元格边框粗细
    14         cellStyle.setAlignment(CellStyle.ALIGN_CENTER); // 水平居中  
    15         cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // 垂直居中 
    16         cellStyle.setBottomBorderColor(IndexedColors.RED.getIndex()); // 设置底边框为红色
    17         cellStyle.setFillForegroundColor(IndexedColors.DARK_YELLOW.getIndex()); // 设置前景色
    18         cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 设置单元格填充颜色
    19         
    20         Sheet sheet = wb.createSheet("第一个sheet"); // 创建一个名字的sheet
    21         sheet.setDefaultColumnWidth(1000); // 设置sheet中的默认宽度
    22         sheet.setDefaultRowHeight((short) 800); // 设置sheet中的默认高度
    23         
    24         Row row = sheet.createRow(0); // 创建一行
    25         row.createCell(0, Cell.CELL_TYPE_BLANK); // 创建一个blank的单元格
    26         row.createCell(1, Cell.CELL_TYPE_BOOLEAN).setCellValue(true); // 创建一个boolean的单元格
    27         row.createCell(2, Cell.CELL_TYPE_FORMULA).setCellValue(3.141592653); // 创建一个formula的单元格
    28         row.createCell(3, Cell.CELL_TYPE_NUMERIC).setCellValue(0); // 创建一个numeric的单元格
    29         row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue("String..."); // 创建一个string的单元格
    30         row.setRowStyle(cellStyle); // 设置行的样式
    31         wb.write(os); // 向内存中的Execl写出orkbook工作簿
    32         os.close(); // 记得关闭流,释放资源
    33     }
    34 }
    没有最好,也没有最坏,一切习惯就好~_^! JAVA交流群^_^:487566461 Activiti5交流群~_^:470165731 JBPM6交流群^_^:470118196 你的加入是我的荣耀,来吧,朋友:让我们一起交流和探讨!
  • 相关阅读:
    MySQL查询缓存
    MySQL复制相关参数详解
    MySQL复制机制
    MySQL数据库的多表查询操作
    MySQL数据库单表查询基本操作及DML语句
    Hadoop大数据系列汇总
    MySQL数据库之日志功能详解
    MySQL数据库扫盲
    MySQL数据库之数据类型及基本使用详解
    MySQL数据库之日志管理
  • 原文地址:https://www.cnblogs.com/fengmenghuo/p/4774397.html
Copyright © 2011-2022 走看看