1。你首先必须把报表载入,也就是你说的加载,
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
try
{
lblMessage.Visible=false;
DataSet myDs=new DataSet();
myDs=(DataSet) this.Session["g_sbcx_jg"];
//string jdyqcx_reporttitle=(string) this.Session["g_jdyqcx_title"];
rDsbcxAll.Load(Server.MapPath("CrSbcx_jg.rpt"));
//((TextObject)rDjdyqcx.ReportDefinition.Sections["Section2"].ReportObjects["toTitle"]).Text=jdyqcx_reporttitle;
rDsbcxAll.SetDataSource(myDs.Tables[0]);
CRVsbcxAll.ReportSource=rDsbcxAll;
}
catch(Exception ExLoad)
{
lblMessage.Visible=true;
lblMessage.Text=ExLoad.Message.ToString(); } }
2。先保存到word文件里面,然后添加下面代码就可以实现你的要求
private void btnPrintWord_Click(object sender, System.EventArgs e)
{
try
{
CrystalDecisions.Shared.ExportOptions myExportsOptions;
CrystalDecisions.Shared.DiskFileDestinationOptions myDiskFileOptions;
string myExportFileName;
//Crsbcx_jg1 myReport=new Crsbcx_jg1();
//Read the temp directory from Web.Config,this temp Directory at the server
string strTempDirectory=System.Configuration.ConfigurationSettings.AppSettings["TempDirectory"];
//-----------------------------End--------------b0b0 2004-4.15
myExportFileName=strTempDirectory.Trim()+ this.Session.SessionID.ToString() +".doc" ;
myDiskFileOptions=new CrystalDecisions.Shared.DiskFileDestinationOptions();
myDiskFileOptions.DiskFileName=myExportFileName;
myExportsOptions=rDsbcxAll.ExportOptions; myExportsOptions.DestinationOptions=myDiskFileOptions;
myExportsOptions.ExportDestinationType=CrystalDecisions.Shared.ExportDestinationType.DiskFile;
myExportsOptions.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.WordForWindows;
rDsbcxAll.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType="application/msword";
Response.WriteFile(myExportFileName);
Response.Flush();
Response.Close();
System.IO.File.Delete(myExportFileName);
}
catch(Exception ExWord)
{
lblMessage.Visible=true;
lblMessage.Text=ExWord.Message.ToString();
}