zoukankan      html  css  js  c++  java
  • JXL API总结

    API参考:

    http://www.andykhan.com/jexcelapi/index.html

    官网:

    http://jexcelapi.sourceforge.net/

    1. 创建可写的工作簿workbook

    WritableWorkbook workbook = Workbook.createWorkbook(new File("c:	est.xls"));

    2. 读取现有的工作簿workbook(不可写)

    Workbook workbook = Workbook.getWorkbook(new File("c:	emplate.xls"));

    3. 创建可写的Sheet

    workbook.createSheet("name", 0);

    4. 读取现有的Sheet

    workbook.getSheet(0);

    5. 创建Label

    Label label = new Label(0,0,"content");

    6. 将Label 添加到Sheet

    sheet.addCell(label);

    7. 根据模板创建workbook

    Workbook template = Workbook.getWorkbook(new File("c:	emplate.xls"));
    WritableWorkbook workbook = Workbook.createWorkbook(new File("c:	est.xls"),template);

    8. 创建Excel的例子

    WritableWorkbook workbook = Workbook.createWorkbook(new File("c:	est.xls"));
    WritableSheet sheet = workbook.getSheet(0);
    Label label1 = new Label(0,0,"content");
    Label label2 = new Label(0,1,"content");
    sheet.addCell(label1);
    sheet.addCell(label2);
    workbook.write();
    workbook.close();

    9. 根据模板创建Excel的例子

    Workbook template = Workbook.getWorkbook(new File("c:	emplate.xls"));
    WritableWorkbook workbook = Workbook.createWorkbook(new File("c:	est.xls"),template);
    WritableSheet sheet = workbook.getSheet(0);
    Label label1 = new Label(0,0,"content");
    Label label2 = new Label(0,1,"content");
    sheet.addCell(label1);
    sheet.addCell(label2);
    workbook.write();
    workbook.close();

    10. 使用模板单元格的格式

    Workbook template = Workbook.getWorkbook(new File("c:	emplate.xls"));
    WritableWorkbook workbook = Workbook.createWorkbook(new File("c:	est.xls"),template);
    WritableSheet sheet = workbook.getSheet(0);    
    //获取模板单元格的格式(字体,颜色等)    
    CellFormat cellFormat = sheet.getWritableCell(0, 0).getCellFormat();
    Label label = new Label(0,0,"content",cellFormat);
    sheet.addCell(label);
    workbook.write();
    workbook.close();

    11. 处理换行

    WritableCellFormat wcf = new WritableCellFormat();
    wcf.setWrap(true);
    wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
    Label label= new Label(0, 0,wcf);

    12. struts2 下载excel

    public InputStream getInputStream(){
            try {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                            Workbook template = Workbook.getWorkbook(new File("c:	emplate.xls"));
                WritableWorkbook workbook = Workbook.createWorkbook(os,template);
                    WritableSheet sheet = workbook.getSheet(0);        
                    CellFormat cellFormat = sheet.getWritableCell(0, 0).getCellFormat();
                    Label label = new Label(0,0,"content",cellFormat);
                    sheet.addCell(label);
                    workbook.write();
                    workbook.close();
                    return new ByteArrayInputStream(os.toByteArray());
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                return null;
            }
        }
  • 相关阅读:
    好久没有写博客了
    老师网站 回顾及复习 https://www.linuxprobe.com/ (linux就该这么学 电子版)
    这周要考试了,还没有时间干其它的了,
    linux学习第十九天 (Linux就该这么学) 结课了
    linux学习第十八天 (Linux就该这么学)
    linux学习第十七天 (Linux就该这么学)
    Spanner's Correctness Constraints on Transactions
    Linearizability
    HDFS vs GFS
    Raft
  • 原文地址:https://www.cnblogs.com/tangyanbo/p/4283799.html
Copyright © 2011-2022 走看看