// 1つのテンプレートのパスを取得します:
。文字列lujing =でrequest.getSession()のgetServletContext()getRealPath( "/")+ "輸出\\テンプレート\\ test.xlsx"。
// 2.データ(一覧<地図<文字列、オブジェクト>> Object)を準備します
一覧<地図<文字列、オブジェクト>> = jdbcTemplate.queryForList地図(SQL);
XSSFWorkbookで... 3 //読み取りと書き込みのInputStreamストリーム
InputStreamで、
試してみる{
=新しいFileInputStreamを新しい中(新しい新しいファイル(lujing1));
XSSFWorkbook仕事= NULL;
仕事=新新XSSFWorkbook(中);
//再書き込みExcelテンプレートの値は4のBaマップ
//最初のシートを得ます
XSSFSheet sheetAt = work.getSheetAt(0)。
//割り当ては、第三の行で始まる
XSSFRow行= sheetAt.createRow(I + 2 )。
row.createCell(0).setCellValue( "")。
サイクルで// ......割り当て
// 5.エクスポート設定の一部を前景
response.reset();
response.setCharacterEncoding( "UTF-8");
response.setContentType( "アプリケーション/ vnd.ms-エクセル")。//保证不乱码
日付日付=新しいDate();
SimpleDateFormatのフォーマット=新しいてSimpleDateFormat( "MMDDHHMMSS");
文字列の時間= "BB" + format.format(日付)+ "XLSX。 "; //导出的エクセル的名字
response.setHeader("コンテンツ・処分"、 "添付ファイル;" + "ファイル名=" +新しいString(時間.getBytes( "UTF-8")、 "ISO-8859-1"));
ByteArrayOutputStream OSS =新しいByteArrayOutputStream();
OutputStreamのOS = response.getOutputStream()。
work.write(OSS)。
バイトTEMP [] = oss.toByteArray()。
するByteArrayInputStream IN1 =新しいれるByteArrayInputStream(温度)。
INT、N = 0。
一方、((N = in1.read(TEMP))> 0){
os.write(温度、0、N)
}
os.flush()。
os.close();
}キャッチ(例外e){
e.printStackTrace();
}
導入のpom.xmlに依存するJARパッケージ://添付
<! -ポイスタート- >
<依存>
<groupIdを> org.apache.poi </ groupIdを>
<たartifactId> POI </たartifactId>
<バージョン> $ {poi.version} </バージョン>
</依存関係>
<依存>
<のgroupId> org.apache.poi </のgroupId>
<たartifactId> POI-OOXML </たartifactId>
<バージョン> $ {poi.version} </バージョン>
</依存>
<依存性>
<のgroupId> org.apache .poi </のgroupId>
<たartifactId> POI-OOXML-スキーマ</たartifactId>
<バージョン> $ {poi.version} </バージョン>
</依存>
<依存性>
<のgroupId> org.apache.poi </のgroupId>
<たartifactId>POI-スクラッチパッド</たartifactId>
<バージョン> $ {poi.version} </バージョン>
</依存>
<依存性>
<のgroupId> org.jeecgframework </のgroupId>
<たartifactId> jeasypoiベース</たartifactId>
<バージョン> $ {jeasypoi.version} </バージョン>
<除外>
<除外>
<のgroupId> org.jeecgframework </のgroupId>
<たartifactId> jeasypoi-注釈</たartifactId>
</除外>
</除外>
</依存関係>
<依存>
<groupIdを> org.jeecgframework </ groupIdを>
<たartifactId> jeasypoi-ウェブ</たartifactId>
<バージョン> $ {jeasypoi .version} </バージョン>
<除外>
<除外>
<のgroupId> org.jeecgframework </のgroupId>
<たartifactId> jeasypoiベース</たartifactId>
</除外>
</除外>
</依存>
<依存性>
<groupIdを> org.jeecgframework </ groupIdを>
<たartifactId> jeasypoi-注釈</たartifactId>
<バージョン> $ {jeasypoi.version} </バージョン>
</依存関係>
<! -ポイ終了- >