我想在单击按钮后将报表查看器导出到Excel文件,并隐藏可用于报表查看器的现有导出工具条按钮。
以下是我的ExportFile函数代码:
private void ExportFile()
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "*PDF files (*.pdf)|*.pdf|Excel files (*.xls)|*.xls|Doc files (*.doc)|*.doc";
// Variables
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string path = " ";
DialogResult dr = saveFileDialog1.ShowDialog();
path = saveFileDialog1.FileName;
byte[] bytes = reportViewerForm.reportViewer1.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(path + ".xls", FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();}
button_click事件的代码:
private void btnExport_Click(object sender, EventArgs e)
{
this.GetData();
this.ExportFile();
}
但是,尝试导出时出现异常错误。 这是我的内在例外:
InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException
Message=One or more parameters required to run the report have not been specified.
Source=Microsoft.ReportViewer.Common
ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsParametersNotSpecified&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=1.0
SkipTopLevelMessage=false
StackTrace:
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory cacheDataChunkFactory, IChunkFactory yukonCompiledDefinition, Boolean& dataCached)
at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(CatalogItemContextBase itemContext, ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials)
at Microsoft.Reporting.LocalService.Render(CatalogItemContextBase itemContext, Boolean allowInternalRenderers, ParameterInfoCollection reportParameters, IEnumerable dataSources, DatasourceCredentialsCollection credentials, CreateAndRegisterStream createStreamCallback, ReportRuntimeSetup runtimeSetup)
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
InnerException:
我错过了什么参数?任何帮助将不胜感激。谢谢。
答案 0 :(得分:1)
您尝试导出的报告是否需要报告参数? (参数快速信息:how to add parameters in report viewer?)
我问,因为这通常是我忘记传递报告参数时得到的例外情况。