• Java操作excel文件


    http://www.cnblogs.com/wuxinrui/archive/2011/03/20/1989326.html

    import java.io.File;
    import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;
    
    public class ReadExcel {
        public static void main(String[] args) {
            try {
                //直接从本地文件(.xls)创建Workbook   
                String excelfile = "Book1.xls";
                Workbook workbook = Workbook.getWorkbook(new File(excelfile));   
                //获取第一张Sheet表   
                Sheet rs = workbook.getSheet(0);   
                //一旦得到了Sheet,就可以通过它来访问Excel Cell(术语:单元格)。   
                //第三步:访问单元格cell   
                //获取第一行,第一列的值   
                Cell c00 = rs.getCell(0, 0);   
                String strc00 = c00.getContents();   
                //获取第一行,第二列的值   
                Cell c10 = rs.getCell(1, 0);   
                String strc10 = c10.getContents();   
                //获取第二行,第二列的值   
                Cell c11 = rs.getCell(1, 1);   
                String strc11 = c11.getContents();   
                System.out.println("Cell(0, 0)" + " value : " + strc00 + "; type : " + c00.getType());   
                System.out.println("Cell(1, 0)" + " value : " + strc10 + "; type : " + c10.getType());   
                System.out.println("Cell(1, 1)" + " value : " + strc11 + "; type : " + c11.getType());   
                // 获取第四行,第一列的值
                Cell c03 = rs.getCell(0,3);
                System.out.println("第四行,第一列的值:"+c03.getContents());
                String contents = rs.getCell(0,4).getContents(); // 得到的是空字符串
                System.out.println("第五行,第一列的值:"+contents);
                String s44 = rs.getCell(3, 3).getContents();
                System.out.println(s44);
                
                
            } catch (Exception e) {
                e.printStackTrace();
            }
            
        }
    }
  • 相关阅读:
    【京东面试复盘】一面二面真题面经解析
    4个小技巧带你轻松入门kafka!
    python 函数
    python 文件修改
    python 文件基本操作
    python 集合的一些用法
    python 字典的应用_简单的三级列表
    python 字典的一些用法
    python 字符串的一些用法
    python 列表应用-简单的购物车
  • 原文地址:https://www.cnblogs.com/stono/p/6106843.html
Copyright © 2020-2023  润新知