VB-Report 10.0 for .NET - ASP.NET MVC デモ
テンプレートを使用しない
テンプレート(Excel で作成したデザインファイル)を使用せずにコード上から新規に帳票を作成することができます。
サンプルコード
- VB.NET
- C#
- Public Function TemplateCreate() As ReportData' 帳票出力時にセルの計算式を再計算CellReport1.ApplyFormula = TrueCellReport1.Report.Start(ReportMode.Speed)' 帳票作成処理(新規)CellReport1.Report.Create(ExcelVersion.ver2007)CellReport1.Page.Start("売上伝票", "1")' デザインの作成' 用紙サイズCellReport1.Page.Attr.Size(PageOrientation.Landscape, PaperKind.A5)' フォントCellReport1.Cell("A1:I18").Attr.FontName = "Meiryo"' タイトルCellReport1.Cell("1:2").RowHeight = 14.5FCellReport1.Cell("A1").Attr.FontStyle = VBReport.FontStyle.BoldCellReport1.Cell("A1").Attr.FontPoint = 11CellReport1.Cell("A1").Value = "売上伝票"' 日時CellReport1.Cell("C1:D1").Attr.MergeCells = TrueCellReport1.Cell("C1:D1").Attr.HorizontalAlignment = HorizontalAlignment.LeftCellReport1.Cell("C1").Attr.Format = "yyyy年m月d日"' IDCellReport1.Cell("H1:I1").Attr.MergeCells = TrueCellReport1.Cell("H1:I1").Attr.HorizontalAlignment = HorizontalAlignment.RightCellReport1.Cell("H1:I1").Attr.LineBottom(BorderStyle.Thin, Color.Black)' コメントCellReport1.Cell("A3").Value = "お買い上げ誠にありがとうございます。"' 名前入力欄CellReport1.Cell("A5").Attr.FontULine = FontULine.Normal' 納品先入力欄CellReport1.Cell("A7").Value = "納品先"CellReport1.Cell("A8:E10").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black)CellReport1.Cell("H8:H10").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black)CellReport1.Cell("I8:I10").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black)' 表(ヘッダー部)CellReport1.Cell("A12:I12").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black)CellReport1.Cell("A12:I17").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black)CellReport1.Cell("B12:B17").Attr.LineRight(BorderStyle.Hair, Color.Black)CellReport1.Cell("G12:G17").Attr.LineRight(BorderStyle.Hair, Color.Black)CellReport1.Cell("H12:H17").Attr.LineRight(BorderStyle.Hair, Color.Black)CellReport1.Cell("A12:B12").Attr.MergeCells = TrueCellReport1.Cell("A12:B12").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("A12:B12").Value = "商品コード"CellReport1.Cell("C12:G12").Attr.MergeCells = TrueCellReport1.Cell("C12:G12").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("C12:G12").Value = "商品名"CellReport1.Cell("H12").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("H12").Value = "数量"CellReport1.Cell("I12").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("I12").Value = "金額"CellReport1.Cell("A12:I12").Attr.BackColor = Color.FromArgb(91, 155, 213)CellReport1.Cell("A12:I12").Attr.FontColor = Color.WhiteCellReport1.Cell("A12:I12").Attr.FontStyle = VBReport.FontStyle.Bold' 表(データ入力部)CellReport1.Cell("A13:I17").Attr.FontPoint = 9CellReport1.Cell("I13:I17").Attr.Format = "#,##"CellReport1.Cell("A14:I14").Attr.BackColor = Color.FromArgb(221, 235, 247)CellReport1.Cell("A16:I16").Attr.BackColor = Color.FromArgb(221, 235, 247)CellReport1.Cell("A13:I13").Attr.LineBottom(BorderStyle.Hair, Color.Black)CellReport1.Cell("A14:I14").Attr.LineBottom(BorderStyle.Hair, Color.Black)CellReport1.Cell("A15:I15").Attr.LineBottom(BorderStyle.Hair, Color.Black)CellReport1.Cell("A16:I16").Attr.LineBottom(BorderStyle.Hair, Color.Black)' 表(合計入力部)CellReport1.Cell("A18").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("A18").Attr.BackColor = Color.FromArgb(91, 155, 213)CellReport1.Cell("A18").Attr.FontColor = Color.WhiteCellReport1.Cell("A18").Attr.FontStyle = VBReport.FontStyle.BoldCellReport1.Cell("A18").Value = "税抜き"CellReport1.Cell("B18:C18").Attr.MergeCells = TrueCellReport1.Cell("B18:C18").Attr.HorizontalAlignment = HorizontalAlignment.RightCellReport1.Cell("B18:C18").Attr.FontPoint = 9CellReport1.Cell("B18:C18").Attr.Format = "#,##"CellReport1.Cell("D18").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("D18").Attr.BackColor = Color.FromArgb(91, 155, 213)CellReport1.Cell("D18").Attr.FontColor = Color.WhiteCellReport1.Cell("D18").Attr.FontStyle = VBReport.FontStyle.BoldCellReport1.Cell("D18").Value = "消費税"CellReport1.Cell("E18:F18").Attr.MergeCells = TrueCellReport1.Cell("E18:F18").Attr.HorizontalAlignment = HorizontalAlignment.RightCellReport1.Cell("E18:F18").Attr.FontPoint = 9CellReport1.Cell("E18:F18").Attr.Format = "#,##"CellReport1.Cell("G18").Attr.HorizontalAlignment = HorizontalAlignment.CenterCellReport1.Cell("G18").Attr.BackColor = Color.FromArgb(91, 155, 213)CellReport1.Cell("G18").Attr.FontColor = Color.WhiteCellReport1.Cell("G18").Attr.FontStyle = VBReport.FontStyle.BoldCellReport1.Cell("G18").Value = "合計"CellReport1.Cell("H18:I18").Attr.MergeCells = TrueCellReport1.Cell("H18:I18").Attr.HorizontalAlignment = HorizontalAlignment.RightCellReport1.Cell("H18:I18").Attr.FontPoint = 9CellReport1.Cell("H18:I18").Attr.Format = "#,##"CellReport1.Cell("A18:I18").Attr.Box(BoxType.Ltc, BorderStyle.Thin, Color.Black)' データの挿入' 日付CellReport1.Cell("C1").Value = DateTime.Now' IDCellReport1.Cell("H1").Value = "10000001"' 会社名CellReport1.Cell("A5").Value = "株式会社レポート○○○○ 様"' 住所CellReport1.Cell("A8").Value = "福井県○○郡○○○町○○XX-XX"' 名前CellReport1.Cell("A9").Value = "○○ ○○ 様"' 商品一覧の設定Dim totalPrice As Integer = 0' 商品コードCellReport1.Cell("A13").Value = "ADV-00100"' 商品名CellReport1.Cell("C13").Value = "ExcelCretor 2016"' 数量Dim unitNumber As Integer = 2CellReport1.Cell("H13").Value = unitNumber' 単価Dim unitPrice As Integer = 64000CellReport1.Cell("I13").Value = unitPricetotalPrice += unitNumber * unitPrice' 税抜き合計CellReport1.Cell("B18").Value = totalPrice' 消費税CellReport1.Cell("E18").Value = totalPrice * 0.10' 合計金額CellReport1.Cell("H18").Value = totalPrice * 1.10' ページ終了処理CellReport1.Page.End()' 帳票終了処理CellReport1.Report.End()' 作成した帳票を SVG 形式で取得Dim document As String = CellReport1.Report.GetSvgReport(SvgSaveType.IncludeExcelPdf)Dim reportData As ReportData = New ReportData()reportData.Document = documentReturn reportDataEnd Function
- public ReportData TemplateCreate(){// 帳票出力時にセルの計算式を再計算cellReport1.ApplyFormula = true;cellReport1.Report.Start(ReportMode.Speed);// 帳票作成処理(新規)cellReport1.Report.Create(ExcelVersion.ver2007);cellReport1.Page.Start("売上伝票", "1");// デザインの作成// 用紙サイズcellReport1.Page.Attr.Size(PageOrientation.Landscape, PaperKind.A5);// フォントcellReport1.Cell("A1:I18").Attr.FontName = "Meiryo";// タイトルcellReport1.Cell("1:2").RowHeight = 14.5F;cellReport1.Cell("A1").Attr.FontStyle = VBReport.FontStyle.Bold;cellReport1.Cell("A1").Attr.FontPoint = 11;cellReport1.Cell("A1").Value = "売上伝票";// 日時cellReport1.Cell("C1:D1").Attr.MergeCells = true;cellReport1.Cell("C1:D1").Attr.HorizontalAlignment = HorizontalAlignment.Left;cellReport1.Cell("C1").Attr.Format = "yyyy年m月d日";// IDcellReport1.Cell("H1:I1").Attr.MergeCells = true;cellReport1.Cell("H1:I1").Attr.HorizontalAlignment = HorizontalAlignment.Right;cellReport1.Cell("H1:I1").Attr.LineBottom(BorderStyle.Thin, Color.Black);// コメントcellReport1.Cell("A3").Value = "お買い上げ誠にありがとうございます。";// 名前入力欄cellReport1.Cell("A5").Attr.FontULine = FontULine.Normal;// 納品先入力欄cellReport1.Cell("A7").Value = "納品先";cellReport1.Cell("A8:E10").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black);cellReport1.Cell("H8:H10").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black);cellReport1.Cell("I8:I10").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black);// 表(ヘッダー部)cellReport1.Cell("A12:I12").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black);cellReport1.Cell("A12:I17").Attr.Box(BoxType.Box, BorderStyle.Thin, Color.Black);cellReport1.Cell("B12:B17").Attr.LineRight(BorderStyle.Hair, Color.Black);cellReport1.Cell("G12:G17").Attr.LineRight(BorderStyle.Hair, Color.Black);cellReport1.Cell("H12:H17").Attr.LineRight(BorderStyle.Hair, Color.Black);cellReport1.Cell("A12:B12").Attr.MergeCells = true;cellReport1.Cell("A12:B12").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("A12:B12").Value = "商品コード";cellReport1.Cell("C12:G12").Attr.MergeCells = true;cellReport1.Cell("C12:G12").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("C12:G12").Value = "商品名";cellReport1.Cell("H12").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("H12").Value = "数量";cellReport1.Cell("I12").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("I12").Value = "金額";cellReport1.Cell("A12:I12").Attr.BackColor = Color.FromArgb(91, 155, 213);cellReport1.Cell("A12:I12").Attr.FontColor = Color.White;cellReport1.Cell("A12:I12").Attr.FontStyle = VBReport.FontStyle.Bold;// 表(データ入力部)cellReport1.Cell("A13:I17").Attr.FontPoint = 9;cellReport1.Cell("I13:I17").Attr.Format = "#,##";cellReport1.Cell("A14:I14").Attr.BackColor = Color.FromArgb(221, 235, 247);cellReport1.Cell("A16:I16").Attr.BackColor = Color.FromArgb(221, 235, 247);cellReport1.Cell("A13:I13").Attr.LineBottom(BorderStyle.Hair, Color.Black);cellReport1.Cell("A14:I14").Attr.LineBottom(BorderStyle.Hair, Color.Black);cellReport1.Cell("A15:I15").Attr.LineBottom(BorderStyle.Hair, Color.Black);cellReport1.Cell("A16:I16").Attr.LineBottom(BorderStyle.Hair, Color.Black);// 表(合計入力部)cellReport1.Cell("A18").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("A18").Attr.BackColor = Color.FromArgb(91, 155, 213);cellReport1.Cell("A18").Attr.FontColor = Color.White;cellReport1.Cell("A18").Attr.FontStyle = VBReport.FontStyle.Bold;cellReport1.Cell("A18").Value = "税抜き";cellReport1.Cell("B18:C18").Attr.MergeCells = true;cellReport1.Cell("B18:C18").Attr.HorizontalAlignment = HorizontalAlignment.Right;cellReport1.Cell("B18:C18").Attr.FontPoint = 9;cellReport1.Cell("B18:C18").Attr.Format = "#,##";cellReport1.Cell("D18").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("D18").Attr.BackColor = Color.FromArgb(91, 155, 213);cellReport1.Cell("D18").Attr.FontColor = Color.White;cellReport1.Cell("D18").Attr.FontStyle = VBReport.FontStyle.Bold;cellReport1.Cell("D18").Value = "消費税";cellReport1.Cell("E18:F18").Attr.MergeCells = true;cellReport1.Cell("E18:F18").Attr.HorizontalAlignment = HorizontalAlignment.Right;cellReport1.Cell("E18:F18").Attr.FontPoint = 9;cellReport1.Cell("E18:F18").Attr.Format = "#,##";cellReport1.Cell("G18").Attr.HorizontalAlignment = HorizontalAlignment.Center;cellReport1.Cell("G18").Attr.BackColor = Color.FromArgb(91, 155, 213);cellReport1.Cell("G18").Attr.FontColor = Color.White;cellReport1.Cell("G18").Attr.FontStyle = VBReport.FontStyle.Bold;cellReport1.Cell("G18").Value = "合計";cellReport1.Cell("H18:I18").Attr.MergeCells = true;cellReport1.Cell("H18:I18").Attr.HorizontalAlignment = HorizontalAlignment.Right;cellReport1.Cell("H18:I18").Attr.FontPoint = 9;cellReport1.Cell("H18:I18").Attr.Format = "#,##";cellReport1.Cell("A18:I18").Attr.Box(BoxType.Ltc, BorderStyle.Thin, Color.Black);// データの挿入// 日付cellReport1.Cell("C1").Value = DateTime.Now;// IDcellReport1.Cell("H1").Value = "10000001";// 会社名cellReport1.Cell("A5").Value = "株式会社レポート○○○○ 様";// 住所cellReport1.Cell("A8").Value = "福井県○○郡○○○町○○XX-XX";// 名前cellReport1.Cell("A9").Value = "○○ ○○ 様";// 商品一覧の設定int totalPrice = 0;// 商品コードcellReport1.Cell("A13").Value = "ADV-00100";// 商品名cellReport1.Cell("C13").Value = "ExcelCretor 2016";// 数量int unitNumber = 2;cellReport1.Cell("H13").Value = unitNumber;// 単価int unitPrice = 64000;cellReport1.Cell("I13").Value = unitPrice;totalPrice += unitNumber * unitPrice;// 税抜き合計cellReport1.Cell("B18").Value = totalPrice;// 消費税cellReport1.Cell("E18").Value = totalPrice * 0.10;// 合計金額cellReport1.Cell("H18").Value = totalPrice * 1.10;// ページ終了処理cellReport1.Page.End();// 帳票終了処理cellReport1.Report.End();// 作成した帳票を SVG 形式で取得string document = cellReport1.Report.GetSvgReport(SvgSaveType.IncludeExcelPdf);ReportData reportData = new ReportData();reportData.Document = document;return reportData;}