2013-03-20 85 views
-7

我想从第二行读取excel表到第13行,也想获得相应的列值。请向我提供代码。 在此先感谢。阅读excel的特定行

+0

让我们了解您已经尝试和询问你所面临的问题的价值。 – Kai 2013-03-20 09:51:50

+0

[你有什么试过](http://mattgemmell.com/2008/12/08/what-have-you-tried/)?这不是免费的编码服务。 – 2013-03-20 09:52:15

+0

我已经得到了行索引的行我想要什么,并迭代在for循环。但它不能正常工作 – user2118527 2013-03-20 10:25:03

回答

2

您应该试试reading the documentation that comes with Apache POI

从那里直接摘自:

// Decide which rows to process 
int rowStart = Math.min(1, sheet.getFirstRowNum()); // 0 based not 1 based rows 
int rowEnd = Math.max(12, sheet.getLastRowNum()); 

for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) { 
    Row r = sheet.getRow(rowNum); 

    int lastColumn = Math.max(r.getLastCellNum(), MY_MINIMUM_COLUMN_COUNT); 

    for (int cn = 0; cn < lastColumn; cn++) { 
     Cell c = r.getCell(cn, Row.RETURN_BLANK_AS_NULL); 
     if (c == null) { 
     // The spreadsheet is empty in this cell 
     } else { 
     // Do something useful with the cell's contents 
     } 
    } 
} 

This bit of the docs介绍了如何获得一个细胞

0
public class ApachePoiDoc 
{ 
    public static void main(String[] args) throws IOException, URISyntaxException 
    { 
    URL url = new URL("http://poi.apache.org/spreadsheet/quick-guide.html#ReadWriteWorkbook"); 
    Desktop.getDesktop().browse(url.toURI()); 
    } 
}