2016-03-06 26 views

回答

0

您可以使用java的「jxl」庫。

試試這個:

package com.quicklyjava; 

進口JXL *; import jxl.read.biff.BiffException;

import java.io.File; import java.io.IOException;

公共類JavaExcelRead {

public static void main(String[] args) { 

    try { 

     //Create a workbook object from the file at specified location. 
     //Change the path of the file as per the location on your computer. 
     Workbook wrk1 = Workbook.getWorkbook(new File("C:/test.xls")); 

     //Obtain the reference to the first sheet in the workbook 
     Sheet sheet1 = wrk1.getSheet(0); 

     //Obtain reference to the Cell using getCell(int col, int row) method of sheet 
     Cell colArow1 = sheet1.getCell(0, 0); 
     Cell colBrow1 = sheet1.getCell(1, 0); 
     Cell colArow2 = sheet1.getCell(0, 1); 

     //Read the contents of the Cell using getContents() method, which will return 
     //it as a String 
     String str_colArow1 = colArow1.getContents(); 
     String str_colBrow1 = colBrow1.getContents(); 
     String str_colArow2 = colArow2.getContents(); 

     //Display the cell contents 
     System.out.println("Contents of cell Col A Row 1: \""+str_colArow1 + "\""); 
     System.out.println("Contents of cell Col B Row 1: \""+str_colBrow1 + "\""); 
     System.out.println("Contents of cell Col A <span class="IL_AD" id="IL_AD12">Row 2</span>: \""+str_colArow2 + "\""); 


    } catch (BiffException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 


} 

}

+0

羅希特感謝您的幫助,但我想從該列獲取特定值時,我從同一行中的另一列值傳遞相關的值... 就像我從主方法傳遞「Rahul」那麼它應該給我「test123 $」作爲輸出 – Unmesh

+1

爲此,您從第0行開始到第一行,if(sheet1.getCell(i,j).getContents( )==「Rahul」)。如果條件爲真,然後遞增j的值和那些單元格的getContents。 –

+0

可以請你分享我的代碼 – Unmesh