Created
February 10, 2009 10:20
-
-
Save masanobuimai/61337 to your computer and use it in GitHub Desktop.
GrailsでExcelダウンロード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.xml.MarkupBuilder | |
class ExcelController { | |
def type1 = { | |
render(contentType: "application/vnd.ms-excel") { | |
html { | |
body { | |
h1 "Books" | |
table(border:1) { | |
tr { th "a"; th "b" } | |
// 日本語は, あああ のようにエスケープされる。 | |
tr { td "あああ"; td "aaa" } | |
// MarkupBuilderを使っているワケではないので,yieldUnescaped()は使えない。 | |
tr { td { yieldUnescaped "<b>いいい</b><br>ううう\nえええ" }; td "bbb" } | |
tr { td "おおお"; td "ccc" } | |
} | |
} | |
} | |
} | |
} | |
def type2 = { | |
def writer = new StringWriter() | |
def builder = new MarkupBuilder(writer) | |
builder.html { | |
body { | |
h1 "Books" | |
table(border:1) { | |
tr { th "a"; th "b" } | |
tr { td "あああ"; td "aaa" } | |
tr { td { yieldUnescaped "<b>いいい</b><br>ううう\nえええ" }; td "bbb" } | |
tr { td "おおお"; td "ccc" } | |
} | |
} | |
} | |
// render()で明示的にエンコードを Shift_JIS に指定する。 | |
render(contentType: "application/vnd.ms-excel", text:writer, encoding:'Shift_JIS') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment