サーブレットとApachePOIについて質問です。
下記のソースで書き込んだセルをすべて黄色で塗りつぶしをしたいのですが、
ソースの書き方を教えてください。
以上、お願いします。
「ソース」
// 業務名前
String[] name4 = request.getParameterValues("gyoumuname");
for (int i = 0; i < name4.length; i++) {
System.out.println(i + " " + name4[i]);
name4[i] = new String(name4[i].getBytes("8859_1"), "UTF-8");
List outList=new ArrayList();
for (int i = 0; i < name4.length; i++) {
outList.add(name4[i]);
}
for (int i = 0; i < outList.size(); i++) {
Row row5 = sheet.getRow(8 + i);
row5.getCell(3).setCellValue(new HSSFRichTextString(outList.get(i).toString()));
}
// 値を書き込んだエクセルを出力する
FileOutputStream out = null;
try {
out = new FileOutputStream(
"C:\\Users\\satou\\Desktop\\weekreport.xls");
workbook.write(out);
} catch (IOException e) {
System.out.println(e.toString());
} finally {
try {
out.close();
} catch (IOException e) {
System.out.println(e.toString());
}
}
以下省略。
No.2ベストアンサー
- 回答日時:
> //HSSFCellStyle style = workbook.createCellStyle();
> //style.setFillForegroundColor(HSSFColor.YELLOW.index); //黄色
> //style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //塗り潰し
これはスタイルを定義しただけであって、org.apache.poi.ss.usermodel.Cell::setCellStyle(CellStyle)を呼び出さないと
対象セルにスタイル反映しませんよ。
https://poi.apache.org/apidocs/org/apache/poi/ss …
値を設定している場面は
> row5.getCell(3).setCellValue(new HSSFRichTextString(outList.get(i).toString()));
なのですから、
Cell cell = row5.getCell(3);
cell.setCellValue(new HSSFRichTextString(outList.get(i).toString()));
CellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); //黄色
style.setFillPattern(CellStyle.SOLID_FOREGROUND); //塗り潰し
cell.setCellStyle(style);
などとなりませんか?
No.1
- 回答日時:
この回答への補足
このように書いたのですが、だめでした。
for (int i = 0; i < name4.length; i++) {
//HSSFCellStyle style = workbook.createCellStyle();
//style.setFillForegroundColor(HSSFColor.YELLOW.index); //黄色
//style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //塗り潰し
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
[JAVA]try 内の変数を外で!?
-
プログラムの組み合わせ方
-
JSPやサーブレットでSystem.out...
-
文字列の引き算
-
java シンボルが見つかりません...
-
C言語のポインターに関する警告
-
JAVA 文字色変更
-
バイナリ文字列の比較について
-
java キーボード入力された値の...
-
1~100までの数字を表示し、か...
-
BOOL値を逆にしたい
-
エクセルVBAで「〜」が表現でき...
-
Java配列でNullPointerExceptio...
-
パソコンキーボードで時分秒を...
-
IF関数でEmpty値を設定する方法。
-
コマンドライン引数の例外処理...
-
C++、クラスメンバの構造体配列...
-
共有メモリについて
-
Arduino(C言語) String "1101" ...
-
Java配列の問題を教えてくださ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
JSPやサーブレットでSystem.out...
-
[JAVA]try 内の変数を外で!?
-
C言語のポインターに関する警告
-
EclipseでJava
-
LC発振回路-ループ利得
-
改行の判定方法
-
JAVAのDouble型の小数点以下の...
-
文字列の引き算
-
java シンボルが見つかりません...
-
エクセルマクロ文で、赤文字セ...
-
vb6 オブジェクトライブラリは...
-
構文解析中にファイルの終わり...
-
「続行するには何かキーを押し...
-
java int integer
-
Javaのプログラムがどうしても...
-
JAVAでの占い
-
nullcline
-
Javaのコマンドライン引数を使...
-
JAVA 文字色変更
-
Javaでカレントディレクトリを...
おすすめ情報