jxl对excel的操作实例

来源:互联网 发布:java商店管理系统 编辑:程序博客网 时间:2024/05/27 00:45

jxl操作excel简单,容易上手。

public class ReadExcel {    public static void main(String[] args) {        readExcel("d:\\文本病例.xls");    }    public static void readExcel(String fileName) {        Workbook wb = null;        try {            wb = Workbook.getWorkbook(new File(fileName));            Sheet sheet = wb.getSheet(0);            WritableWorkbook wwb = Workbook.createWorkbook(new File("d:\\data.xls"));            WritableSheet ws = wwb.createSheet("data",0);            //10908            for(int i=0; i<1853; i++){                for(int j=0;j<7;j++){                    String content = sheet.getCell(j, i).getContents();                    content = content.replaceAll("\n", "####"); //.replaceAll(",", " ");                    System.out.println(content);                    Label label = new Label(j, i, content);                    ws.addCell(label);                }            }            wwb.write();            wwb.close();        } catch (Exception e) {            System.out.println("出现异常" + e);            e.printStackTrace();        } finally {            wb.close();        }    }}
0 0
原创粉丝点击