其他分享
首页 > 其他分享> > FastReport入门

FastReport入门

作者:互联网

FastReport是一个报表组件,可以可视化定制报表,支持导出PDF、HTML等内容,同时支持字符串、XML、JSON、各类数据库作为数据源。
首先需要通过Nuget引入相关DLL

<packages>
  <package id="FastReport.Compat" version="2021.3.1" targetFramework="net40" />
  <package id="FastReport.Data.Json" version="2022.2.0" targetFramework="net40" />
  <package id="FastReport.OpenSource" version="2022.2.11" targetFramework="net40" />
  <package id="FastReport.OpenSource.Export.PdfSimple" version="2022.2.11" targetFramework="net40" />
</packages>

 

导出PDF

static void ExportPDF()
{
    Report report = new Report();
    report.Load("d:\\请假申请单.frx");
    report.SetParameterValue("userName", "周杰伦");
    report.SetParameterValue("remark", "今天想休息一天");

    PDFSimpleExport export = new PDFSimpleExport();
    try
    {
        report.Prepare();
        report.Export(export, "d:\\请假申请单.pdf");
        Console.WriteLine("导出成功");
    }
    finally
    {
        export.Dispose();
    }
}

 

导出HTML

static void ExportHTML()
{
    Report report = new Report();
    // 根据不同的数据源增加连接方式,比如:JSON、Oracle、Mysql等
    RegisteredObjects.AddConnection(typeof(JsonDataConnection));
    report.Load("d:\\请假申请单.frx");
    report.SetParameterValue("userName", "周杰伦");
    report.SetParameterValue("remark", "今天想休息一天");
                
    HTMLExport export = new HTMLExport();
    export.SinglePage = true;
    try
    {
        report.Prepare();
        using (MemoryStream ms = new MemoryStream())
        {
            report.Export(export, ms);

            string content = Encoding.UTF8.GetString(ms.ToArray());
            File.WriteAllText("d:\\请假申请单.html", content);
        }
        Console.WriteLine("导出成功");
    }
    finally
    {
        export.Dispose();
    }
}

 

标签:入门,SetParameterValue,FastReport,Report,export,report,new,申请单
来源: https://www.cnblogs.com/duanjt/p/16373963.html