Apache POIを使用してExcelファイルを読み込んでいます。複数の値を含むExcelファイルを単一の列に読み込みます。-Java
List<Class> list = new ArrayList<Class>();
File file = new File(file_path);
FileInputStream fis = new FileInputStream(file);
//Create an instance of workbook which refers to an excel file
XSSFWorkbook wb = new XSSFWorkbook(fis);
//This selects the 1st sheet
XSSFSheet sheet = wb.getSheetAt(0);
//Iterate through each row one by one
Iterator<Row> itr = sheet.iterator();
String newName = null;
String oldName = null;
while(itr.hasNext()){
Row nextRow = itr.next();
// For each row, iterate through all the columns
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
newName = nextRow.getCell(0).toString();
if(nextRow.getCell(1).toString().contains(",")){
StringTokenizer st = new StringTokenizer(nextRow.getCell(1).toString(),",");
while(st.hasMoreTokens()){
oldName = st.nextToken();
}
}
else{
oldName = nextRow.getCell(1).toString();
}
}
System.out.println();
}
: 私のExcelのテーブル構造は、右側のデータのために、私は今、私はこの方法を実装しましたティル2000年代
に割り当てることが必要ですので、この
|2000s| 2001, 2003, 2008, 2009|
のようなものですコンパイルすると、ヌルポインタの例外がnextRow.getCell(1)
行にスローされます。
どのようにすべてのカンマ値を2000年にマップするのか分かりません。
これは、通常のデータ(コンマなし)では問題なく動作しています。