vb-report5.0msdn for vb.net.net

VB.net CrystalReport报表 - 推酷
VB.net CrystalReport报表
CrystalReport的创建过程
1、选中一个项目—右击—添加—新建项
2、左击Reporting—左击CrystalReports
如果之前没有安装Crystal Reports,会出现如下的界面
此时要做的是,下载相应的组件。
。下载安装后,重复上述操作,第2步后的操作界面为
3、点击确定,之后的界面就是为报表指定数据库,表的操作。创建新连接
4、连接创建好后,确定报表显示的表
5、显示那些字段
6、出现如下界面,接下了就是设计报表格式了
CrystalReportViwer控件的创建
&如果你没有在工具箱里发现这个控件可以尝试一下操作
1、工具箱中想工具集上右击—选择项
2、添加相应的控件
按照上面的操作后,如果仍然没有显示相应的控件,可以再按下面的操作做
现在就可以看到相应的控件了
程序中显示报表
1、主要代码
'相对路径 CrystallReports1.rpt默认保存在该项目的文件夹中,但下面代码中的CrystallReport1.rpt是在该项目的bin/debug文件夹中 &
Dim path As String = Application.StartupPath & &\CrystalReport1.rpt&
'表示一个报表,并且包含定义、格式化、加载、导出和打印该报表的属性和方法。
Dim Report As New ReportDocument
'加载你事先做好的Crystal Report报表文件
Report.Load(Path)
‘报表依据的显示的表 设定显示的table,dt为DataTable,也可以为ds.Tables(0)
Report.SetDataSource(dt)
’控件加载报表,并显示
CrystalReportViewer1.ReportSource = Report
2、运行的时候如果出现如下错误
需要向向配置文件app.config中添加如下代码
&!--新添加--&
&startup useLegacyV2RuntimeActivationPolicy=&true&&
&supportedRuntime version=&v4.0& sku=&.NETFramework,Version=v4.0&/&
&/startup&
具体如下图
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致如何使用ReportParameter,并在RDLC文本框如何编辑公式?
---------------------------
&&&&Private&Sub&FormPrinter_Load(ByVal&sender&As&System.Object,&ByVal&e&As&System.EventArgs)&Handles&MyBase.Load
&&&&&&&&Dim&aBindingSource&As&New&System.Windows.Forms.BindingSource
&&&&&&&&aBindingSource.DataSource&=&Form1.DS
&&&&&&&&aBindingSource.DataMember&=&Form1.DS.Tables(0).ToString
&&&&&&&&Dim&rds&As&New&Microsoft.Reporting.WinForms.ReportDataSource
&&&&&&&&rds.Name&=&Form1.DS.Tables(0).ToString
&&&&&&&&rds.Value&=&aBindingSource
&&&&&&&&Me.ReportViewer1.LocalReport.DataSources.Clear()
&&&&&&&&Me.ReportViewer1.LocalReport.DataSources.Add(rds)
&&&&&&&&Me.ReportViewer1.LocalReport.Refresh()
&&&&End&Sub
回复讨论(解决方案)
关注一下,我也正遇上
没人对rdlc感兴趣吗?急呀,那位兄弟能帮帮忙?
RDLC用表可以实现分页显示,但是自定义纸张碰到一些问题,网上的例子大多是C#搞不大懂
楼主,你的报表的数据源是不是动态的临时生成的?&
如果是的,&你是如何调用报表的?&报表rdlc文件中的字段栏位是如何写的?I am new in programming crystal Report, so please help me. i have main report with sub-report on it. i know already how to set data source of main report, the problem is in my sub-report. here's how i did for my main report:
open_con()
Dim a As String
a = "SELECT * FROM students where year_id=1"
Dim reader As SqlDataReader
cmd = New SqlCommand(a, dbcon)
reader = cmd.ExecuteReader
'tblstud is a datagridview
While reader.Read
tblstud.Rows.Add(reader("name"), reader("address"),reader("grade_level"),reader("id_number"))
reader.Close()
cmd.Dispose()
close_con()
Catch ex As Exception
MsgBox(ex.Message)
Dim dtable As New DataTable
With dtable
.Columns.Add("name")
.Columns.Add("address")
.Columns.Add("g_lvl")
.Columns.Add("id_num")
For Each tblrow As DataGridViewRow In Me.tblstud.Rows
dtable.Rows.Add(tblrow.Cells("names").Value, tblrow.Cells("addrs").Value, tblrow.Cells("lvl").Value, tblrow.Cells("ids").Value)
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = New stud_rep
rptDoc.SetDataSource(dtable)
CrystalReportViewer1.ReportSource = rptDoc
Catch ex As Exception
MsgBox(ex.Message)
that's how i generated data and set it to the Crystal report, now the problem is in sub-report i don't know how to set data source, i tried to repeat that and set it to the next table (datagridview) and create another datatable but it shows empty.. i tried rptDoc.OpenSubreport(0).SetDataSource(dtable2)
hope anybody understand my problem.. thanks in advance
解决方案 it might be little bit simple if you try like this
RptDocument.Subreports[0].SetDataSource(YourDataSource);
本文地址: &
我是新编程水晶报告,所以请帮助我。我有主报告及其分报告。我知道已经如何设置主报表的数据源,问题是在我的子报表。这里是我为我的主要报告:
尝试 open_con() Dim a As String a =“SELECT * FROM students where year_id = 1” Dim reader As SqlDataReader
cmd = New SqlCommand(a,dbcon) reader = cmd.ExecuteReader
'tblstud是一个datagridview
虽然reader.Read
tblstud.Rows.Add(reader(“name”),reader(“address”),reader(“grade_level” reader(“id_number”)) End While
reader.Close() cmd.Dispose() close_con() Catch ex As Exception
MsgBox(ex.Message) End Try
Dim dtable As New DataTable
With dtable
.Columns.Add(“name”) .Columns .Add(“address”) .Columns.Add(“g_lvl”) .Columns.Add(“id_num”)以结尾对于每个tblrow As DataGridViewRow In Me .tblstud.Rows
dtable.Rows.Add(tblrow.Cells(“names”)。Value,tblrow.Cells(“addrs”)。Value,tblrow.Cells(“lvl”)。Value,tblrow.Cells (“ids”)。Value) Next
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = new stud_rep
rptDoc。 SetDataSource(dtable) CrystalReportViewer1.ReportSource = rptDoc
Catch ex As Exception
MsgBox(ex.Message)结束尝试
这是我如何生成数据并将其设置为Crystal报表,现在的问题是在子报表中我不知道如何设置数据源,我试过重复并设置它到下一个表(datagridview)和创建另一个数据表,但它显示空..我尝试 rptDoc.OpenSubreport(0).SetDataSource(dtable2)
希望任何人了解我的问题。
解决方案 可能会有点简单,如果你尝试这样
RptDocument.Subreports [0] .SetDataSource(YourDataSource);
本文地址: &
扫一扫关注官方微信VB-Report7 使用后,做些记录以便日后再用。
博客分类:
前几天写了个打印相关的程序,调用vb-report打印。说一下vb-report是个什么东西。你可给以给一个模板EXCEL,分当然只是指VB-REPORT7里。然后用这个工具往里面填数据,你把模板样式改了。数据还是照样填到相应的位置,他可以保存成EXCEL,和PDF,还有打印预览。 我编这东西老费劲了。资料又少,官网文档只是简单的东西。晕了。还好总算完成任务了。用的是VS2008,他的几个示例程序有的,我就用2008编的。他的示例有,winform,都是有界面的。我想我照着做就是。后面要求不要界面,运行程序直接打印。我就想啊用consoleAppliction,于是建了个这个程序。。。跑发现不行。于是换成winform,我用的c#,vb很多年没整了。把包引进来,工具栏把这个vbreport加进来,结果就是没有xlsReport这个控件,晕了,我只好从示例程序里复制,然后在这个工程里粘过来。显出来了,为了看到效果没办法,没有打印预览怎么行。这个控件就是一个打印预览工具。
viewerControl为预览工具。xlsReport为xls处理类 如果需要调用excel里面的统计函数,则要用xlsReport1.ExcelMode = 每次生成新的视图时viewerControl1.Clear(); 处理完后将document给视图控件。viewerControl1.Document=xlsReport1.D 保存成PDFErrorNo eno=viewerControl1.SavePDF(pdffilename);保存成EXCELeno = viewerControl1.SaveAs(Environment.CurrentDirectory + excelname, xlsVersion.ver2003); 本来不用生成PDF,EXCEL的,直接打印就可以了,但时需要双面打印,发现打印的时候他是一页一页发过去的。设置了打印机也没什么效果。viewerControl1.Printer.Duplex = Duplex.H 这一句完全没效果。 不知道什么意思,明明就一个文档,43页打出来的时候就发了43个打印过去。所以设置双面打印也不行,我想应该是这个原因。保存成PDF43页,保存成EXCEL31个SHEET。有些SHEET有两三页。
下面的代码是填充excel的C#代码
//设置excel路径
xlsReport1.FileName = designFileP
xlsReport1.Report.Start();
xlsReport1.Report.File();
//sheetNameList是一个list,模板excel的sheet名
for (int i = 0; i < sheetNameList.C i++)
//dataList.Count是该sheet有几页
xlsReport1.Page.Start(sheetNameList[i], "1-" + dataList.Count);
for (int j = 0; j < dataList.C j++)
//xlsReport1.Page.Start(sheetNameList[i], (j + 1).ToString());
xlsReport1.Cell("**reportdate").Value =
xlsReport1.Cell("**nowdate").Value =
xlsReport1.Cell("**pageno", 0, j * 41).Value = (j + 1).ToString();
//xlsReport1.Cell("**pageno").Value = (j + 1).ToString();
xlsReport1.Cell("**termno").Value = termNo;
xlsReport1.Cell("**termname").Value = termN
xlsReport1.Cell("**codlbase").Value = getRealData(baseValMap[termNo + "-" + Constants.itemNoMap["CODL"]].ToString(),Constants.itemNoMap["CODL"]);
xlsReport1.Cell("**nlbase").Value=getRealData(baseValMap[termNo+"-"+Constants.itemNoMap["NL"]].ToString(),Constants.itemNoMap["NL"]);
xlsReport1.Cell("**plbase").Value = getRealData(baseValMap[termNo + "-" + Constants.itemNoMap["PL"]].ToString(),Constants.itemNoMap["PL"]);
int tmprow = 0;
for (int k = 0; k < dataList[j].L k++, tmprow++)
if (k == 6+1 || k == 12+1 || k == 18+1) tmprow++;
for (int x = 0; x < dataList[j][k].Lx++ )
if (k == 0)
if (dataList[j][k][x] != null && dataList[j][k][x] != "")
xlsReport1.Cell("A", x * 2 + 1, j * 41 + tmprow + 4).Value = dataList[j][k][x];
if (isDoubleNumber(dataList[j][k][x]))
xlsReport1.Cell("A", x * 2 + 1, j * 41 + tmprow + 7).Value =
Convert.ToDouble(dataList[j][k][x]) ;
------分隔线----------------------------
------分隔线----------------------------
你可能对下面内容感兴趣:

我要回帖

更多关于 vb.net reportviewer 的文章

 

随机推荐