0

誰でも助けてもらえますか?そのコードを使用することで、Excel フィールドからも値を取得できました。特定の列 = 5 の値があります。

public Integer  Check4(int b) throws IOException  {
    InputStream myxls = new FileInputStream("book.xls");
    HSSFWorkbook wb     = new HSSFWorkbook(myxls);
    HSSFSheet sheet = wb.getSheetAt(0);       // first sheet
    HSSFRow row     = sheet.getRow(0);        // first row
    //HSSFCell cell0   = row.getCell((short)a);  // first arg
    HSSFCell cell1   = row.getCell((short)b);  // second arg
    cell1.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
    System.out.println("smth "+  cell1);
    return ;

}

ただし、そのようなコードの出力は次のとおりです。

"smth + 5.0"

var cell1 5.0 を 5 に変換する方法はわかりますか?Math.round、Integer.parseInt() は実際には役に立たない

4

2 に答える 2

1

HSSFCellを使用する前に、 から文字列値を取得する必要がありますInteger.parseInt()。を使用しInteger.parseInt(cell1.getStringCellValue())ます。おそらく使用できますgetNumericCellValue()が、それはdouble.

于 2014-05-12T13:47:13.000 に答える
0

最後に、 (int) Math.round(cell1.getNumericCellValue())) で解きます

    public Integer  Check4(int b) throws IOException  {
    InputStream myxls = new FileInputStream("book.xls");
    HSSFWorkbook wb     = new HSSFWorkbook(myxls);
    HSSFSheet sheet = wb.getSheetAt(0);       // first sheet
    HSSFRow row     = sheet.getRow(1);        // first row
    //HSSFCell cell0   = row.getCell((short)a);  // first arg
    HSSFCell cell1   = row.getCell((short)b);  // second arg
    String sell = cell1.toString();
    cell1.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
    System.out.println("smth "+ (int) Math.round(cell1.getNumericCellValue()));
    return  (int) Math.round(cell1.getNumericCellValue());

}
于 2014-05-12T14:33:03.830 に答える