さらにいい方法を見つけた

先日の記事でExcelに出力するのを書いたけど、もっといい方法を見つけました。

はてなブログ
はてなブログは、無料でしっかり書けるブログサービスです。日々の生活から感じたこと、考えたことを書き残しましょう。

ExcelのワークシートにVelocityのような感じでコマンドを埋め込む方法。Velocity好きとしては、これに書き直します。

import org.seasar.fisshplate.template.*
import org.apache.poi.hssf.usermodel.*
     :
     :
    /** excel形式でダウンロード */
    def downloadXLS = {
        if (servletContext.customerPoint) {
            InputStream is = new FileInputStream(
                servletContext.getRealPath("/WEB-INF/customer_point_template.xls"))
	    def template = new FPTemplate()
	    HSSFWorkbook wb = template.process(is,[list:servletContext.customerPoint])
            response.setHeader("Content-disposition",
            "attachment; customer_point.xls")
	     response.contentType = "application/vnd.ms-excel"
	     wb.write(response.outputStream)
        }
    }

超短くなりましたね。行を作ったりしなくていいので、あきらかにこの方がシンプルですね。

コメント

  1. […] Fisshplateは、Excelをテンプレート化してデータを埋め込んだExcelファイルを作るライブラリ。 プロジェクトのサイトはこちら さらにいい方法を見つけた […]

タイトルとURLをコピーしました