如何使用vb.net以PDF格式以编程方式保存RDLC报告 [英] how to programatically save RDLC report in PDF format using vb.net

查看:120
本文介绍了如何使用vb.net以PDF格式以编程方式保存RDLC报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

i在vb.net中创建报表开发,我想以pdf格式自动保存rdlc报告。发送你的代码..

解决方案

我可以帮助导出,不知道如何打印 - 我只有一个C#示例:



出口到EXCEL或PDF



报告上有一个按钮,允许用户导出为ex​​cel或pdf。但是,如果您想使用代码强制导出,只需添加以下代码:



  private   void  exportToExcel( string  DestWhereExcelFileWillBe)

{

System.IO.FileInfo fi = new System.IO.FileInfo(DestWhereExcelFileWillBe);

if (fi.Exists)fi.Delete();

警告[]警告;

string [] streamids;

string mimeType,encoding,filenameExtension;

byte [] bytes = reportViewer1.LocalReport.Render( Excel null out mimeType, out 编码, out filenameExtension,

out streamids, out 警告);

System.IO.FileStream fs = System.IO.File.Create(DestWhereExcelFileWillBe);

fs.Write(bytes, 0 ,bytes.Length);

fs.Close();

}







或VB.Net代码示例此处



我用来生成PDF格式的单个报告的代码是:



  Dim 警告作为 Microsoft.Reporting.WebForms.Warning()=  Nothing  

Dim streamids As 字符串()= 没什么

Dim mimeType 作为 字符串 = 没什么

Dim 编码 As String = 没什么

Dim extension 字符串 = 没什么

Dim deviceInfo As String

Dim bytes As Byte ()

Dim lr As Microsoft.Reporting .WebForms.LocalReport

deviceInfo = < deviceinfo>< simplepageheaders> True< / simplepageheaders>< / deviceinfo>

bytes = ReportViewer1.LocalReport.Render( PDF,deviceInfo,mimeType,encoding,extension,streamids,warnings)

Response.ClearContent()

Response.ClearHeaders()

Response.Conten tType = application / pdf

Response.BinaryWrite(bytes)

Response.Flush()

Response.Close()





[由MK编辑] 解决方案来源


此问题已解决,请参阅解决方案,请转到



如何在vb.net中以Pdf格式保存RDLC报告Windows应用程序 [ ^ ]


我在这里做同样的代码我的代码:

  Imports  Microsoft.Reporting.WinForms 
公开 Form1
公共 属性 strReport 作为 字符串
私有 Sub Form1_Load(发件人作为 对象,e As EventArgs)句柄 MyBase .Load
Me .companyTableAdapter.Fill( Me .invoicedbDataSet.company )
Dim rptDataSource As ReportDataSource
尝试
使用 .ReportViewer1.LocalReport
.DataSources.Clear()
结束 使用

Dim ds 作为 报告。 invoicedbDataSet
Dim da As report.invoicedbDataSetTableAdapters.companyTableAdapter
da.Fill(ds.company)
rptDataSource = ReportDataSource( DataSet1,ds.Tables( company))
Me .ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
.ReportViewer1.RefreshReport()

Catch ex As Exception
MessageBox.Show(ex.Message,My.Application.Info.Title, MessageBoxButtons.OK,MessageBoxIcon。错误
结束 尝试
.ReportViewer1.RefreshReport()
结束 Sub
结束


hi...
i creating report development in vb.net,i want to save the rdlc report automatically in pdf format.pls send your code..

解决方案

I can help with the export, not sure how to print - and I only have a C# example:

EXPORT TO EXCEL OR PDF

There is a button on the report allowing the user to export to excel or pdf. However, if you want to force an export using code, just add this code:

private void exportToExcel(string DestWhereExcelFileWillBe)

{

System.IO.FileInfo fi = new System.IO.FileInfo(DestWhereExcelFileWillBe);

if (fi.Exists) fi.Delete();

Warning[] warnings;

string[] streamids;

string mimeType, encoding, filenameExtension;

byte[] bytes = reportViewer1.LocalReport.Render( "Excel", null, out mimeType, out encoding, out filenameExtension,

out streamids, out warnings);

System.IO.FileStream fs = System.IO.File.Create(DestWhereExcelFileWillBe);

fs.Write(bytes, 0, bytes.Length);

fs.Close();

}




or VB.Net Code Example Here

The code I use to Generate a single report as a PDF is:

Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing

Dim streamids As String() = Nothing

Dim mimeType As String = Nothing

Dim encoding As String = Nothing

Dim extension As String = Nothing

Dim deviceInfo As String

Dim bytes As Byte()

Dim lr As New Microsoft.Reporting.WebForms.LocalReport

deviceInfo = "<deviceinfo><simplepageheaders>True</simplepageheaders></deviceinfo>"

bytes = ReportViewer1.LocalReport.Render("PDF", deviceInfo, mimeType, encoding, extension, streamids, warnings)

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType = "application/pdf"

Response.BinaryWrite(bytes)

Response.Flush()

Response.Close()



[Edit by MK] Solution Source


This problem is solved see the solution means go to

How to save RDLC report in Pdf format in vb.net windows application[^]


i doing same code for here My code:

Imports Microsoft.Reporting.WinForms
Public Class Form1
    Public Property strReport As String
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.companyTableAdapter.Fill(Me.invoicedbDataSet.company)
        Dim rptDataSource As ReportDataSource
        Try
            With Me.ReportViewer1.LocalReport
                .DataSources.Clear()
            End With

            Dim ds As New report.invoicedbDataSet
            Dim da As New report.invoicedbDataSetTableAdapters.companyTableAdapter
            da.Fill(ds.company)
            rptDataSource = New ReportDataSource("DataSet1", ds.Tables("company"))
            Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
            Me.ReportViewer1.RefreshReport()

        Catch ex As Exception
            MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        Me.ReportViewer1.RefreshReport()
    End Sub
End Class


这篇关于如何使用vb.net以PDF格式以编程方式保存RDLC报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆