LoginSignup
0
0

More than 1 year has passed since last update.

【帳票】Stimulsoft Report.jsでのファイル保存(PDF Excel Wordなど)

Last updated at Posted at 2022-03-28

はじめに

Stimulsoft report.jsを使い、帳票をプレビューなしでPDF、Excel、Wordなどのファイルで保存する方法について整理します。
特に拡張モジュールは不要で、JavaScriptのコードを記述するだけで、実現できます。

前提

stimulsoft report.js

PDFで保存する場合

最初に結論を書きます。PDF形式で保存するケースになります。
必要な処理は、
①レポート(帳票)を指定したファイル形式でエキスポート
②エキスポートしたデータをダウンロード保存
となります。

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>レポートをPDFにエクスポート</title>
    <script src="../scripts/stimulsoft.reports.js" type="text/javascript"></script>
</head>
<body>
    レポートをPDFにエクスポート<br><br>
    <script type="text/javascript">
        // 新しいレポートインスタンスを作成
        var report = new Stimulsoft.Report.StiReport();
        // URLからレポートを読み込む
        report.loadFile("../reports/SimpleList.mrt");
        // レポートレンダリング後にボタンを活性化
        report.renderAsync(function () {
            document.getElementById("savePdf").disabled = false;
        });
        // レポートをPDF形式にエクスポートし、ファイルに保存
        function saveReportPdf() {
            // PDFにエクスポート
            report.exportDocumentAsync(function (pdfData) {
                // レポートファイル名を取得する
                var fileName = report.reportAlias;
                // データをファイルに保存
                Stimulsoft.System.StiObject.saveAs(pdfData, fileName + ".pdf", "application/pdf");
            }, Stimulsoft.Report.StiExportFormat.Pdf);
        }
    </script>
    <button id="savePdf" onclick="saveReportPdf()" disabled>PDFファイル保存</button><br>
    <br><br>
    <div id="htmlContainer"></div>
</body>
</html>

その他のファイル出力

ファイルデータのエキスポート

以下のコードで、StiExportFormatで指定したファイル形式(PDF/Word/Excel/PowerPoint/Html/PNG/GIF/CSVなど多数)のデータをコールバック関数に渡すことができます。

report.exportDocumentAsync(callback(data), Stimulsoft.Report.StiExportFormat.Excel2007)

StiExportFormat列挙型

定数 列挙名
0 None
1 Pdf
2 Xps
3 HtmlTable
4 HtmlSpan
5 HtmlDiv
6 Rtf
7 RtfTable
8 RtfFrame
9 RtfWinWord
10 RtfTabbedText
11 Text
12 Excel
13 ExcelXml
14 Excel2007
15 Word2007
16 Xml
17 Csv
18 Dif
19 Sylk
20 Image
21 ImageGif
22 ImageBmp
23 ImagePng
24 ImageTiff
25 ImageJpeg
26 ImagePcx
27 ImageEmf
28 ImageSvg
29 ImageSvgz
30 Mht
31 Dbf
32 Html
33 Ods
34 Odt
35 Ppt2007
36 Html5
37 Data
38 Json
1000 Document

ファイルデータの保存

Stimulsoft.System.StiObject.saveAs({ファイルデータ}, "ファイル名", "MIMEタイプ");

まとめ

いかがだったでしょうか。Stimulsoft製品は、ファイルに出力に関して多くのファイルタイプをサポートしています。これにより様々な要件に対応することが可能です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0