我正在从c#代码生成水晶报告。我的数据集有10列。数据是动态的。报告在运行时生成数据正常。但格式是没有表格格式的默认水晶格式。我想以表格格式显示数据,如excel中的表格。我该怎么做呢?
以下是我用来生成水晶报告的代码块。
using (ReportDocument rd = new ReportDocument())
{
CrystalReportFilePath = ConfigurationManager.AppSettings["crystal_report_file_path"];
crystalReportFileName = "client_Details.rpt";
pdfFileName = clientName + " - " + reportMonth + ".pdf";
string rptFilePath = string.Format(@"{0}\{1}", CrystalReportFilePath, crystalReportFileName);
rd.Load(rptFilePath);
rd.SetDataSource(tempds);
rd.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
rd.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crDiskFileDestinationOptions.DiskFileName = string.Format(@"{0}\{1}", CrystalReportFilePath, pdfFileName);
rd.ExportOptions.ExportDestinationOptions = crDiskFileDestinationOptions;
rd.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
rd.VerifyDatabase();
rd.Export();
}
答案 0 :(得分:0)
Public Shared Sub ExportDataSetToExcel(ByVal ds As DataTable, ByVal filename As String)
Dim response As HttpResponse = HttpContext.Current.Response
response.Clear()
response.Buffer = True
response.Charset = ""
'response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
response.ContentType = "application/vnd.ms-excel"
'response.AddHeader("Content-Disposition", "attachment;filename=""" & filename & ".xls")
Using sw As New StringWriter()
Using htw As New HtmlTextWriter(sw)
Dim dg As New DataGrid()
dg.DataSource = ds
dg.DataBind()
dg.RenderControl(htw)
response.Charset = "UTF-8"
response.ContentEncoding = System.Text.Encoding.UTF8
response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble())
response.Output.Write(sw.ToString())
response.[End]()
End Using
End Using
End Sub
答案 1 :(得分:0)
我们正在使用2008年的水晶报告。在这个版本中,我们没有表格格式。相反,我们必须选择字段,为每个字段指定边框并以表格格式排列。这是一种痛苦,但事情就是这样。
对于Excel中的替换行的不同颜色,我们必须在section expert中编写一个公式 - >详情 - >颜色标签
if RecordNumber mod 2 = 0 then Color (234, 234, 234) else crNoColor