当前位置:   article > 正文

java使用Workbook进行excel读取和创建_workbook create

workbook create
  1. public static void main(String[] args) throws Exception {
  2. //输入流。a.xls为要读取的excel文件名,不可为xlsx后缀
  3. Workbook book = Workbook.getWorkbook(new File("E:\\a.xls"));
  4. //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
  5. Sheet sheet = book.getSheet(0);
  6. //输出流
  7. WritableWorkbook wwb = Workbook.createWorkbook(new FileOutputStream("E:\\b.xls"));
  8. //创建第一个工作表对象,名为("Sheet 1)
  9. WritableSheet ws = wwb.createSheet("Sheet 1", 0);
  10. //单元格对象
  11. Label label;
  12. //label里面的样式
  13. WritableFont wfc = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
  14. WritableCellFormat wcfFC = new WritableCellFormat(wfc);
  15. //前三行数据,列不用加条件
  16. for (int i = 0; i < 13; i++) {
  17. label = new Label(i, 0, sheet.getCell(i, 0).getContents(), wcfFC);
  18. ws
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号