1

パイプで区切られたオブジェクトがいくつかありListます。Stringこのようなもの:

String1|String2|String3
String4|String5|String6
...

Apache POIをExcelライブラリとして使用して、リスト全体を反復処理して、Excelファイルの各行として文字列オブジェクトを書き出すことは可能ですか?つまり、次のようなものです。

for (String inst : <List instance>)
       <sheetInstance>.write(inst)

つまり、各セルの値を文字列で設定するのではなく、文字列を行エントリとして直接Excelに出力します。

setting row 1, cell 1 = String1
setting row 1, cell 2 = String2
setting row 1, cell 3 = String3
setting row 2, cell 1 = String4 ...

現在、個々のセルを各値に設定する必要があるようです。

4

1 に答える 1

4

String次のように、セルを埋めるためにを配列に分割する必要があります。

for (short rowIndex = 0; rowIndex < stringList.length(); rowIndex++) {
    Row row = sheet.createRow(rowIndex);
    String[] cellValues = stringList.get(rowIndex).split("|");
    for (int colIndex = 0; colIndex < cellValues.length; colIndex++) {
        Cell cell = row.createCell(colIndex);
        cell.setCellValue(cellValues[colIndex]);
    }
}
于 2012-06-28T22:13:09.223 に答える