Java 生成一个excel表 9*9
2015-06-23 21:12
615 查看
工具
Apache 提供的POI,可以对Microsoft Excel, Word, PPT, Visio进行文件创建、读取等功能实验目的
创建一个excel文件,内容是9*9表格代码
java public static void main(String[] args) throws IOException { FileOutputStream fos = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\workbook.xlsx"); String letter = "ABCDEFGHIJK"; String joint; Workbook wb = new XSSFWorkbook(); Sheet sheet1 = wb.createSheet("Sheet1"); CellStyle style = wb.createCellStyle(); //单元格样式 style.setAlignment(CellStyle.ALIGN_CENTER); //水平居中 style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //垂直居中 for(int r = 0; r < 9; r++){ Row row = sheet1.createRow(r); for(int c = 0; c < r + 1; c ++){ joint = letter.charAt(r) + "" + (c + 1); Cell cell = row.createCell(c); cell.setCellStyle(style); //往cell写入公式 cell.setCellFormula("ROW(" + joint + ")&\"*\"&COLUMN(" + joint + ")&\"=\"&ROW(" + joint + ")*COLUMN(" + joint + ")"); } } //设置列宽 for(int i = 0; i < 9; i++) sheet1.setColumnWidth(i, 10 * 256); wb.write(fos); fos.close(); }
相关文章推荐
- 22Spring基于配置文件的方式配置AOP
- Java多线程 多个生产者和多个消费者实现同步 jdk1.5
- Java之fianl修饰符
- JAVA List<> 合并去重
- JAVA基础第四天
- struts1的原理
- 线程总结(适合初学者)
- 浅析JavaBean
- Java多线程 多个生产者和多个消费者实现同步 jdk1.4
- 浅析JavaBean
- Ubuntu下配置Java环境JDK并配置
- 对Spring MVC初学的认识 编辑
- Java Socket编程(转)
- SVM实现垃圾邮件分类(java调用libsvm.jar)
- Java知多少(101)图像缓冲技术
- java和ajax实现带文件的form提交
- Java Web开发模式一(JSP+JavaBean)
- 初学JAVA之基本语句的使用
- eclipse 各种奇葩错误(不定期更新)
- 堆排序 Java