StackOverflowでグーグルして検索した後、この質問に関連する場所が見つかりませんでした。現在、空白のセルをnullとして読み取ることができますが、一度に1つのセルしか読み取ることができません。だから私はこのようなものを書かなければなりません:
data.setAddress(row.getCell(10, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(10).getStringCellValue());
data.setClientType(row.getCell(11, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(11).getNumericCellValue());
data.setClientType0Charge(row.getCell(12, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(12).getNumericCellValue());
data.setClientType1Charge(row.getCell(13, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(13).getNumericCellValue());
data.setCooYears(row.getCell(14, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(14).getNumericCellValue());
data.setConYears(row.getCell(15, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(15).getNumericCellValue());
data.setProjectType(row.getCell(16, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(16).getNumericCellValue());
data.setProjectTypeNotes(row.getCell(17, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(17).getStringCellValue());
data.setChargeMethod(row.getCell(18, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(18).getNumericCellValue());
data.setFixedPrice(row.getCell(19, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(19).getNumericCellValue());
data.setHighTime(row.getCell(20, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(20).getStringCellValue());
data.setHighPrice(row.getCell(21, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(21).getNumericCellValue());
data.setPeakTime(row.getCell(22, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(22).getStringCellValue());
data.setPeakPrice(row.getCell(23, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(23).getNumericCellValue());
data.setPlainTime(row.getCell(24, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(24).getStringCellValue());
data.setPlainPrice(row.getCell(25, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(25).getNumericCellValue());
data.setValleyTime(row.getCell(26, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(26).getStringCellValue());
data.setValleyPrice(row.getCell(27, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(27).getNumericCellValue());
data.setServFee(row.getCell(28, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(28).getNumericCellValue());
data.setServFeePercent(row.getCell(29, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(29).getNumericCellValue());
data.setServFeeFixed(row.getCell(30, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(30).getNumericCellValue());
data.setPropertyType(row.getCell(31, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(31).getNumericCellValue());
data.setPropertyOwner(row.getCell(32, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(32).getStringCellValue());
data.setPropertyManager(row.getCell(33, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(33).getStringCellValue());
data.setAcquireMethod(row.getCell(34, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(34).getNumericCellValue());
data.setAcquireMethodNotes(row.getCell(35, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(35).getStringCellValue());
data.setSiteAddress(row.getCell(36, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(36).getStringCellValue());
data.setSiteType(row.getCell(37, Row.RETURN_BLANK_AS_NULL) == null ? null : (int) row.getCell(37).getNumericCellValue());
data.setSiteTypeNotes(row.getCell(38, Row.RETURN_BLANK_AS_NULL) == null ? null : row.getCell(38).getStringCellValue());
繰り返しに対する恨みの感覚があるので、これは私にはあまり良く見えません。Row.RETURN_BLANK_AS_NULL
シート全体またはブック全体のセルのどこかに普遍的に設定できますか?
これは、ワークブックレベルの欠落セルポリシーで設定できます。
XSSFWorkbook book = new XSSFWorkbook("h:\\excel.xlsx");
XSSFSheet sheet = book.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
book.setMissingCellPolicy(Row.RETURN_BLANK_AS_NULL);
これが機能するのは、セル番号のみのgetcellの定義が次のようになっているためです(POIソースコードから)。
@Override
public XSSFCell getCell(int cellnum) {
return getCell(cellnum, _sheet.getWorkbook().getMissingCellPolicy());
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加