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

    public static void main(String[] args) throws Exception {
        //输入流。a.xls为要读取的excel文件名,不可为xlsx后缀
        Workbook book = Workbook.getWorkbook(new File("E:\\a.xls"));
        //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
        Sheet sheet = book.getSheet(0);
        //输出流
        WritableWorkbook wwb = Workbook.createWorkbook(new FileOutputStream("E:\\b.xls"));
        //创建第一个工作表对象,名为("Sheet 1)
        WritableSheet ws = wwb.createSheet("Sheet 1", 0);
        //单元格对象
        Label label;

        //label里面的样式
        WritableFont wfc = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
        WritableCellFormat wcfFC = new WritableCellFormat(wfc);
        //前三行数据,列不用加条件
        for (int i = 0; i < 13; i++) {
            label = new Label(i, 0, sheet.getCell(i, 0).getContents(), wcfFC);
            ws.addCell(label);
            label = new Label(i, 1, sheet.getCell(

你可能感兴趣的:(java)