关闭

jxl对excel的操作实例

标签: exceljxl
86人阅读 评论(0) 收藏 举报
分类:

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:46841次
    • 积分:1387
    • 等级:
    • 排名:千里之外
    • 原创:89篇
    • 转载:56篇
    • 译文:0篇
    • 评论:0条