Java操作excel檔案

來源:互聯網
上載者:User

標籤:get   int   arch   getc   div   nbsp   五行   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(); // 得到的是Null 字元串            System.out.println("第五行,第一列的值:"+contents);            String s44 = rs.getCell(3, 3).getContents();            System.out.println(s44);                                } catch (Exception e) {            e.printStackTrace();        }            }}

 

Java操作excel檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.