-7

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

4

2 回答 2

2

您应该尝试阅读 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
      }
   }
}

这部分文档介绍了如何获取单元格的值

于 2013-03-20T09:52:19.273 回答
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() );
  }
}
于 2013-03-20T09:56:27.113 回答