读取excel的特定行

时间:2013-03-20 09:42:25

标签: java apache-poi

我想从第2行到第13行读取excel表,并且还想获得相应的列值。请为我提供代码。 提前谢谢。

2 个答案:

答案 0 :(得分: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介绍了如何获取单元格的值

答案 1 :(得分: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() );
  }
}