2

コンソール アプリケーションを使用して .rdlc を .pdf 出力にレンダリングするために、この Web サイトのいくつかの記事を参照しました。 string[] args = {string[0]}) 28 行目 私のクラスは以下のとおりです。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Reporting.WinForms;


namespace Rdclrender
{
    class Program
    {
        static void Main(string[] args)
        {
            // Variables
            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;


            // Setup the report viewer object and get the array of bytes
            ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportPath = "Report.rdlc";


            byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

            using (System.IO.FileStream fs = new System.IO.FileStream("output.pdf", System.IO.FileMode.Create))
            {
                fs.Write(bytes, 0, bytes.Length);
            }
            // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
            /*  Response.Buffer = true;
              Response.Clear();
              Response.ContentType = mimeType;
              Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
              Response.BinaryWrite(bytes); // create the file
              Response.Flush(); // send it to the client to download*/
        }
    }
}

これは .rdl から pdf を作成する方法ですか? .rdl の名前を手動で .rdlc に変更し、.rdlc アイテムをプロジェクトに追加しました。

4

1 に答える 1

3

最も簡単な解決策は次のとおりです。

DataTable にレポートのデータを入力し、Datatable に「Sales」という名前を付けます (レポートの DataSource 名のように)。

これは動作しない疑似コードですが、アイデアを提供する必要があることに注意してください。

var myDataSet = new DataSet(); 
var da = new SqlDataAdapter("Select * from Sales", "yourConnectionstring");

da.Fill(myDataSet);
DataTable table = myDataSet.Tables[0];
table.TableName = "Sales";

DataTable をデータソースとしてレポートに追加します。

viewer.LocalReport.DataSources.Add(table);
于 2013-10-15T11:40:06.830 に答える