c#2005 中水晶表報問題.(分不夠在加)

一事無成 2009-01-15 12:29:22
那位能提供一個c#2005自帶水晶報表的用法的例子.
我是一個c#2005的初學者,最好能說具體點,有源代碼的例子最好.
...全文
193 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ken_sniper 2009-01-16
  • 打赏
  • 举报
回复
demo有点大,不好贴,就贴了这个水晶报表操作的核心部分。如果要看看的话:http://download.csdn.net/source/678709
ken_sniper 2009-01-16
  • 打赏
  • 举报
回复
很久没有弄过水晶报表了,以前弄的。

using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Windows.Forms;
using System.IO;

namespace test_dx
{
/// <summary>
/// report 的摘要说明。
/// </summary>
public class report
{
private ReportDocument rdc;
private DiskFileDestinationOptions disk;
private ExportOptions ex;
public report()
{
disk = new DiskFileDestinationOptions();
ex = new ExportOptions();
//
// TODO: 在此处添加构造函数逻辑
//
}

#region//得到各种格式水晶报表,参数:数据集、导出文件格式、保存导出文件的完整路径。
public void getCrystal(DataSet ds,string type,string path) //参数:数据集、导出文件格式、导出文件的完整路径。
{
try
{
//set ReportDocument;
rdc = new ReportDocument();
rdc.Load(Application.StartupPath + @"\Report1.rpt" );
rdc.SetDataSource(ds);

//set path;
disk.DiskFileName = @path;
ex = rdc.ExportOptions;
ex.DestinationOptions = disk;
ex.ExportDestinationType = ExportDestinationType.DiskFile;

//Export the report
switch (type)
{
case "pdf":
ex.ExportFormatType = ExportFormatType.PortableDocFormat;
break;
case "doc":
ex.ExportFormatType = ExportFormatType.WordForWindows;
break;
case "xls":
ex.ExportFormatType = ExportFormatType.Excel;
break;
case "txt":
ex.ExportFormatType = ExportFormatType.Text;
break;
default:
this.writeLog("Export type error!");
break;
}


rdc.Export();
}
catch(Exception ex)
{
this.writeLog(ex.ToString());
}

}
#endregion

#region//得到报表ReportDocument,参数:数据集、水晶报表框架路径。
public ReportDocument getPDF(DataSet ds,string reportPath)
{
try
{
rdc = new ReportDocument();
rdc.Load(reportPath);
rdc.SetDataSource(ds);
}
catch(Exception ex)
{
this.writeLog(ex.ToString());
}
return rdc;
}
#endregion

#region//写日志
private void writeLog(string ex) //报表日志
{
try
{
string path = Application.StartupPath + @"\log\pdflog.txt";
string time = DateTime.Now.ToString();
StreamWriter sw = new StreamWriter(path,true,System.Text.Encoding.UTF8);
sw.WriteLine(time);
sw.WriteLine(ex);
sw.WriteLine(" ");
sw.Flush();
sw.Close();
}
catch(Exception ss)
{
this.writeLog(ss.ToString());
}
finally
{
MessageBox.Show("Report log test ok!","TEST");
}

}
#endregion
}
}
阿泰 2009-01-16
  • 打赏
  • 举报
回复
【原创+分享】VS2005水晶报表PUSH模式(DataSet)视频教程+源代码工程示例 [推荐]
http://topic.csdn.net/u/20081118/10/49a1751d-1d86-44e4-969f-a847c2316dd3.html

0基础,看完就会了。
cs78799662 2009-01-16
  • 打赏
  • 举报
回复
学习,关注中。。。。
kldx5092 2009-01-15
  • 打赏
  • 举报
回复
在安装目录下有demo的
SAP辉哥 2009-01-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 devilli 的回复:]
首先 ReportDocument report = new ReportDocument(); // 定义报表文档对象
再 report.Load(Application.StartupPath + "\\Report\\" + _reportName + ".rpt"); //load报表文件
report.SetDataSource(yourDataSet);
report.SetParameterValue("parameterName", "parameterValue");//设置报表变量
再用CrystalReportViewer这个控件
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.Zoom(1);
cry…
[/Quote]
7L 正解
devilli 2009-01-15
  • 打赏
  • 举报
回复
首先 ReportDocument report = new ReportDocument(); // 定义报表文档对象
再 report.Load(Application.StartupPath + "\\Report\\" + _reportName + ".rpt"); //load报表文件
report.SetDataSource(yourDataSet);
report.SetParameterValue("parameterName", "parameterValue");//设置报表变量
再用CrystalReportViewer这个控件
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.Zoom(1);
crystalReportViewer1.Show();
大头_衍 2009-01-15
  • 打赏
  • 举报
回复
初学的话,建议你使用.net自带的.rdlc报表
功能和水晶报表类似。
水晶报表要注册。
给你一个我写的代码:

//报表
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetReport_数据集", DataTable));
ReportViewer1.LocalReport.ReportPath = "Report/报表(带路径).rdlc";
ReportViewer1.LocalReport.ReportEmbeddedResource = "报表.rdlc";
//参数
ReportParameter rpStartDate = new ReportParameter("StartDate", StartDate.ToShortDateString());
ReportParameter rpEndDate = new ReportParameter("EndDate", EndDate.ToShortDateString());
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpStartDate, rpEndDate });
ReportViewer1.DataBind();
ReportViewer1.LocalReport.Refresh();
一事無成 2009-01-15
  • 打赏
  • 举报
回复
請問,我在c#2005(winform)中加了一個 Crystal Reports ,
payReport pay_Report = new payReport()
實例化後怎麼顯示這個實例呢? pay_Report好像沒有.show ?
zxkid 2009-01-15
  • 打赏
  • 举报
回复
C:\Program Files\Microsoft Visual Studio 8\Crystal Reports\Samples
zxkid 2009-01-15
  • 打赏
  • 举报
回复
https://www.sdn.sap.com/irj/boc/businessobjects-samples?rid=/webcontent/uuid/80774579-b086-2b10-db91-ed58c4dda375
一事無成 2009-01-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kldx5092 的回复:]
在安装目录下有demo的
[/Quote]
沒找到啊. 具體path 是什麼?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧