0

データベースの値をA4ページ(JPGテンプレートがあります)に配置し、ページごとに挿入されたPDFブック/レポートを作成したいだけです。私は、 iReportエディターを使用してNetBeans JavaJasperReportsで簡単にそれを実行しました。

Visual Studio C#CrystalReportsでは非常に難しいようです。私はCrystalReportsのチュートリアルを実際に検索しましたが、A4画像をテンプレートとして使用しているチュートリアルはありません。そのようなチュートリアルを知っているなら、私を助けてください。

ウィザードではなく、プログラムで機能するソリューションが好きです。私はすでに自分のプログラムでデータベースを管理しています。レポートと、レポートに入力値を与える方法のドキュメントが必要です。レポートがデータベースにアクセスする必要すらありません。プログラム内のすべての値を取得できます。私にとって最良の解決策は、JPGファイルを背景として使用するテンプレートと、関数のパラメーターを介してプログラムからテキストを提供するボックス(テキストボックスなど)です。Jasper Reports/iReportのように。

4

2 に答える 2

1

OK、私は簡単な解決策を見つけるために少し時間を費やしました、そして私は以下を得ました:

まず、Crystal Reportsではなく、Windowsレポート(rdlcファイル)を使用しました。Windowsレポートはよりシンプルで簡単で、背景として画像を追加し、この画像の上に文字列パラメーター(まさに私が必要としていたもの)を参照するいくつかのTextBoxを追加することができます。これらは既定でVisualStudioにあり、Visual Studioでレポートをデザインします(ソリューションエクスプローラーで右クリック->レポートの追加)

次に、レポートをPDFファイルに変換するコードサンプルを見つけ、それを使用して次のクラスを記述しました。

public class XReport
{
    private ReportViewer reportViewer = new ReportViewer();

    public XReport()
    {
    }
    public XReport(String reportFilePath)
    {
        setReportFile(reportFilePath);
    }
    // set rdlc file
    public void setReportFile(String reportFilePath)
    {
        reportViewer.Reset();
        reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
        reportViewer.LocalReport.ReportPath = reportFilePath;
    }
    public void setParameters(List<ReportParameter> parameters)
    {
        reportViewer.LocalReport.SetParameters(parameters.ToArray());
        reportViewer.LocalReport.Refresh();
    }
    public void setParameters(Dictionary<String, String> parameters)
    {
        XList<ReportParameter> parameterList = new List<ReportParameter>();
        XList<String> parameterKeys = parameters.getKeys();
        foreach (String parameterKey in parameterKeys) {
            parameterList.Add(new ReportParameter(parameterKey, parameters.get(parameterKey))); }
        setParameters(parameterList);
    }
    public void exportToPDF(String pdfFilePath)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType = string.Empty;
        string encoding = string.Empty;
        string extension = string.Empty;
        byte[] bytes = null;
        // render PDF file
        try { bytes = reportViewer.LocalReport.Render( "PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings); }
        catch (Exception ex) { System.Console.Write(ex.Message); }
        // write PDF file
        using (FileStream fs = new FileStream(pdfFilePath, FileMode.Create)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); }
        // release reportViewer resources to avoid errors
        reportViewer.LocalReport.ReleaseSandboxAppDomain();
    }
}

できます。それを試してみてください。2つのことに注意してください:

  • reportFilePathとpdfFilePathには正しいパスを使用してください。(pdfFilePathは、私にとっては非相対パスでのみ機能しました)

  • rdlcレポートにすべてのパラメーターを正しい名前で追加したことを確認してください。これらは、[表示]->[レポートデータ]->[新しいパラメーターの追加]([パラメーター]を右クリック)で追加できます。こちらもご覧ください:rdlcレポートにパラメータを作成する

私が助けてくれたことを願っています。それは私にとって素晴らしい働きをしました。

于 2012-08-28T13:22:48.390 に答える
0

下記のCrystal自体のオプションを使用して、レポートの用紙サイズを設定できます。最初にレポートを開き、[ファイル]->[ページ設定]に移動しますここに画像の説明を入力してください

于 2012-07-22T09:09:55.807 に答える