VB-Report 10.0 for .NET - ASP.NET MVC デモ

売上明細書

売上明細書の作成例です。シンプルな可変帳票の作成に向いている Section.Start 機能を使用して実装しています。


サンプルコード

  • VB.NET
  • C#
  • Public Function CreateSalesStatement() As ReportData
        ' 帳票作成処理(デザインファイル使用)
        CellReport1.FileName = Path.Combine(basePath, "SectionSample.xlsx")
        CellReport1.Report.Start(ReportMode.Speed)
        CellReport1.Report.File()
        ' Section 機能を開始
        CellReport1.Section.Start("売上明細書", False)
        ' 帳票ページのヘッダ部を指定
        CellReport1.Section.Header("1:13")
        ' 帳票ページのフッタ部を指定
        CellReport1.Section.Footer("15:16")
        CellReport1.Section.ReportToFill = False
        CellReport1.Section.MaxDetailCount = 0
        ' 明細行数の範囲を指定
        Dim detail As SectionDetail = CellReport1.Section.Detail("A14:I14")
        ' 明細のデータ件数分、明細行の追加
        For Each row As Sales In sales
            detail.Start()
            detail.Cell("**Shouhin").Value = row.Item
            detail.Cell("E14").Value = row.Price
            detail.Cell("**Suuryou").Value = row.Count
            Dim kingaku As Integer = Convert.ToInt32(row.Price) * Convert.ToInt32(row.Count)
            detail.Cell("**Kingaku").Value = kingaku
            detail.Cell("**Biko").Value = row.Memo
            detail.Next()
        Next
        ' Section 機能を終了
        CellReport1.Section.End()
        ' 帳票終了処理
        CellReport1.Report.End()
        ' 作成した帳票を SVG 形式で取得
        Dim document As String = CellReport1.Report.GetSvgReport(SvgSaveType.IncludeExcelPdf)

        Dim reportData As ReportData = New ReportData()
        reportData.Document = document
        Return reportData
    End Function

    ' SectionNewPage イベント
    Private Sub CellReport1_SectionNewPage(sender As Object, e As SectionNewPageEventArgs) Handles CellReport1.SectionNewPage
        e.Header.Cell("**DateNow").Value = DateTime.Now.ToString("yyyy/M/d")
        e.Header.Cell("**Date").Value = DateTime.Now.AddDays(-1).ToString("yyyy/M/d")
        e.Header.Cell("**Tenpo").Value = "フレッシュマート"
        e.Header.Cell("**Kubun").Value = "ホットメニュー"
    End Sub

    ' SectionEndPage イベント
    Private Sub CellReport1_SectionEndPage(sender As Object, e As SectionEndPageEventArgs) Handles CellReport1.SectionEndPage
        e.Footer.Cell("**Ninzu").Value = "500"
    End Sub
  • public ReportData CreateSalesStatement()
    {
        // 帳票作成処理(デザインファイル使用)
        cellReport1.FileName = Path.Combine(basePath, "SectionSample.xlsx");
        cellReport1.Report.Start(ReportMode.Speed);
        cellReport1.Report.File();
        // Section 機能を開始
        cellReport1.Section.Start("売上明細書", false);
        // 帳票ページのヘッダ部を指定
        cellReport1.Section.Header("1:13");
        // 帳票ページのフッタ部を指定
        cellReport1.Section.Footer("15:16");
        cellReport1.Section.ReportToFill = false;
        cellReport1.Section.MaxDetailCount = 0;
        // 明細行数の範囲を指定
        SectionDetail detail = cellReport1.Section.Detail("A14:I14");
        // 明細のデータ件数分、明細行の追加
        foreach (Sales row in sales)
        {
            detail.Start();
            detail.Cell("**Shouhin").Value = row.Item;
            detail.Cell("E14").Value = row.Price;
            detail.Cell("**Suuryou").Value = row.Count;
            int kingaku = Convert.ToInt32(row.Price) * Convert.ToInt32(row.Count);
            detail.Cell("**Kingaku").Value = kingaku;
            detail.Cell("**Biko").Value = row.Memo;
            detail.Next();
        }
        // Section 機能を終了
        cellReport1.Section.End();
        // 帳票終了処理
        cellReport1.Report.End();
        // 作成した帳票を SVG 形式で取得
        string document = cellReport1.Report.GetSvgReport(SvgSaveType.IncludeExcelPdf);

        ReportData reportData = new ReportData();
        reportData.Document = document;
        return reportData;
    }
    // SectionNewPage イベント
    private void CellReport1_SectionNewPage(object sender, SectionNewPageEventArgs e)
    {
        e.Header.Cell("**DateNow").Value = DateTime.Now.ToString("yyyy/M/d");
        e.Header.Cell("**Date").Value = DateTime.Now.AddDays(-1).ToString("yyyy/M/d");
        e.Header.Cell("**Tenpo").Value = "フレッシュマート";
        e.Header.Cell("**Kubun").Value = "ホットメニュー";
    }
    // SectionEndPage イベント
    private void CellReport1_SectionEndPage(object sender, SectionEndPageEventArgs e)
    {
        e.Footer.Cell("**Ninzu").Value = "500";
    }