首页 > 编程语言 >用C#生成多个Telerik Report PDF

用C#生成多个Telerik Report PDF

时间:2023-04-03 11:14:27浏览次数:32  
标签:Telerik 报表 C# 生成 PDF Report new string

1.创建一个新的WinForms或WPF应用程序,具体取决于您的需要。

2.将Telerik Reporting组件添加到您的应用程序中。您可以通过NuGet包管理器来完成此操作。

3.在您的应用程序中添加多个报表文件。您可以使用Telerik Report Designer创建报表并将其添加到您的应用程序项目中。确保为每个报表定义一个唯一的名称。

4.创建一个C#方法来生成PDF。该方法应该类似于以下示例代码:

public static void GenerateReport(string reportName)
{
    Telerik.Reporting.Report report = ReportResolver.Resolve(reportName);
    Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    
    Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", report, null);
    
    string fileName = "output_" + reportName + ".pdf";
    string filePath = AppDomain.CurrentDomain.BaseDirectory + fileName;
    
    using (FileStream fs = new FileStream(filePath, FileMode.Create))
    {
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
    }
}

此方法将根据报表名称生成PDF文件,并将其保存到应用程序的基本目录中。

5.使用该方法生成所有报表的PDF。以下是一个示例方法来遍历所有报表并生成它们的PDF:

public static void GenerateAllReports()
{
    string[] reportNames = new string[] { "report1", "report2", "report3" };
    
    for (int i = 0; i < reportNames.Length; i++)
    {
        GenerateReport(reportNames[i]);
    }
}

此方法将遍历所有报表名称,并对每个报表调用GenerateReport方法来生成相应的PDF。

6.最后,您可以在应用程序的UI中提供适当的UI元素或逻辑来触发报表生成过程。

希望这些步骤对您有所帮助,让您成功地使用C#生成多个Telerik Report PDF。

 

二.Telerik Reporting ReportBook是另一种生成多个PDF文件的方法。

ReportBook是一个特殊的Telerik报表,它由多个子报表组成,可将它们合并成单个PDF输出。

下面是一个使用ReportBook生成多个PDF文件的简单示例:

using System;
using System.IO;
using Telerik.Reporting;
using Telerik.Reporting.Processing;

namespace PDFGenerator
{
    class Program
    {
        static void Main(string[] args)
        {
            // 创建包含多个报表的ReportBook
            ReportBook reportBook = new ReportBook();

            // 添加要生成的所有子报表
            reportBook.ReportSources.Add(new UriReportSource() { Uri = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "report1.trdp") });
            reportBook.ReportSources.Add(new UriReportSource() { Uri = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "report2.trdp") });
            reportBook.ReportSources.Add(new UriReportSource() { Uri = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "report3.trdp") });

            // 遍历所有子报表,生成一个包含每个子报表的PDF文件
            for (int i = 0; i < reportBook.ReportSources.Count; i++)
            {
                // 获取子报表的报表实例
                Report report = (new InstanceReportSource() { ReportDocument = reportBook.Reports[i] }).ReportDocument;

                // 生成子报表的PDF文件
                ReportProcessor reportProcessor = new ReportProcessor();
                RenderingResult result = reportProcessor.RenderReport("PDF", report, null);
                byte[] pdfBytes = result.DocumentBytes;

                // 将生成的PDF保存到文件
                string fileName = $"report_{i + 1}.pdf";
                string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
                File.WriteAllBytes(filePath, pdfBytes);
            }
        }
    }
}

 

标签:Telerik,报表,C#,生成,PDF,Report,new,string
From: https://www.cnblogs.com/tx1185498724/p/17282477.html

相关文章

  • [USACO08FEB]Hotel G
    [USACO08FEB]HotelG线段树二分,最大字段和对于操作二,是很简单的区间赋值对于操作一,长度为\(len\)的,我们要找到最小的的\(x\)满足\([x,x+len-1]\)的房间为空在最大字段和的基础上,我们可以求出最长连续空房间的长度,对于要求长度为\(len\)的房间,可以按顺序判断:若左区......
  • ORACLE之PACKAGE-包、存储过程、函数
    原文地址:https://www.cnblogs.com/hoaprox/p/5316444.html1,简单的包。创建包规范:createorreplacepackagepack_test1is--定义过程1procedurep_test1(p_1invarchar2);--定义函数1functionf_test1(p_1invarchar2)returnvarchar2;endpack_test1;......
  • Graph database concepts
    Graphdatabaseconcepts图数据结构由nodes(离散对象)组成,这些nodes可以通过relationships(关系)连接起来。Example1.图结构的概念.xxxxxxxxxx ​pycharm图数据库模型由一下属性组成:Nodes描述域的实体(离散对象).Nodes可以有零个或多个labels来定义(分类)它们是什么......
  • C语言,str系列函数
     1、strcat()此函数原型为char*strcat(char*dest,constchar*src).功能为连接两个字符串,把src连接到dest后面;返回dest地址//函数实现char*strcat(char*dest,constchar*src){char*addr=dest;while(*dest)//找到'\0'{dest++;};......
  • [leetcode每日一题]4.3
    1053. 交换一次的先前排列提示中等80相关企业给你一个正整数数组 arr(可能存在重复的元素),请你返回可在 一次交换(交换两数字 arr[i] 和 arr[j] 的位置)后得到的、按字典序排列小于 arr 的最大排列。如果无法这么操作,就请返回原数组。 示例1:输入:arr=[3,2,1]输出:[3,1,2]......
  • 不支持关键字: “connection timeout”
    “/”应用程序中的服务器错误。--------------------------------------------------------------------------------不支持关键字:“connectiontimeout”。说明:执行当前Web请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的......
  • C# 常用加密方式二种
    一、MD5加密算法MD5的全称是Message-DigestAlgorithm5(信息-摘要算法),在90年代初由MITLaboratoryforComputerScience和RSADataSecurityInc的RonaldL.Rivest开发出来,经MD2、MD3和MD4发展而来。1991年,Rivest开发出技术上更为趋近成熟的MD5算法。它在MD4的基础上增加了"安......
  • VS2017 未能正确加载“ReferenceManagerPackage”包
    MicrosoftVisualStudio未能正确加载“ReferenceManagerPackage”包。1.以管理员身份打开DeveloperCommandPromptforVS20172.定位到你的vs2017的安装目录我安装的是企业版就是E:\ProgramFiles(x86)\MicrosoftVisualStudio\2017\Enterprise\Common7\IDE\PublicAssemblies......
  • CA登录问题汇总
    情景:“/”应用程序中的服务器错误。检索COM类工厂中CLSID为{68210AC9-5DD1-45E1-AAC8-631FCB554570}的组件失败,原因是出现以下错误:80040154没有注册类(异常来自HRESULT:0x80040154(REGDB_E_CLASSNOTREG))。说明:执行当前Web请求期间,出现未经处理的异常。请检......
  • 面向chatgpt翻译:与google,baidu做对比
    先说结论:chatgpt完胜You翻译一下:ThechatbothassomeamazingcapabilitiesthatareveryclosetotheoriginalchatgptbutitdidinheritopenaiwoknesstoointhesensethatanycontroversialtopicisheavilyleaningtoaleftlibtardmindsetHopetofixthat......