Skip to content

Instantly share code, notes, and snippets.

@kiyokura
Created March 21, 2012 02:51
Show Gist options
  • Save kiyokura/2143910 to your computer and use it in GitHub Desktop.
Save kiyokura/2143910 to your computer and use it in GitHub Desktop.
VB-Report7.0のXlsx.Web.XlsxWebReportのミニマムコードメモ
'----------------------------
' .Net 4版。
' 以下の参照設定が必要
' VBReport7.Document.4
' VBReport7.Xlsx.IO.4
' VBReport7.Xlsx.Web.Report.4
'----------------------------
Imports AdvanceSoftware.VBReport7
Class ExcelWebDonwloadSample
Private Sub DownloadExcel()
Dim templateFileName As String = ""
Dim templateSheetName As String = ""
Dim outputFileName As String = ""
Using report As New Xlsx.Web.XlsxWebReport
' 開始処理
report.FileName = templateFileName
report.Report.Start()
report.Report.File()
report.Page.Start(templateSheetName, "1")
' データ積み込み処理
report.Pos(1, 1).Value = "データ1"
report.Pos(1, 2).Value = "データ2"
report.Pos(1, 3).Value = "データ3"
' 終了処理
report.Page.End()
report.Report.End()
' エラーチェック
If report.ErrorNo <> ErrorNo.NoError Then
Throw New Exception("レポート出力に失敗")
End If
' ダウンロード
Using ms As New System.IO.MemoryStream
report.Report.SaveAs(ms)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & HttpUtility.UrlEncode(outputFileName))
HttpContext.Current.Response.BinaryWrite(ms.ToArray())
End Using
' HttpResponse終了
HttpContext.Current.Response.End()
End Using
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment