Porting a sql server report directly to pdf or excel
2010-11-04 11:15
281 查看
PORTINGASQLSERVERREPORTINGSERVICES2005REPORTDIRECTLYTOPDFOREXCEL
ExportingaSQLServerReportingServices2005(SSRS)ReportDirectlytoPDF/ExcelisahandywayofgeneratinghighqualityreportswithoutbeingstucktousingtheReportViewerinterface.SometimestheReportViewerinterfaceisanunnecessarystep,butothertimestheReportViewerwon'trendercorrectlyeventhoughtheunderlyingreportiscorrect.ThisisespeciallytruewhenyouraudiencemightuseFirefoxorSafari(oranythingotherthanIE),sincetheReportViewercontrolalmostneveroutputsareadablereport.OfcourseitwouldbenicetojusthaveabuttononyourpagethatgeneratesaPDForExcelfileinanybrowser,andusesaSSRSback-endtodoallofthereportcreatingandheavylifting.Thefollowingcodewillshowhowtoexportsuchareport,includingthepassingofanarbitrarynumberofcustomparameters.Notethattheidentityoftheapplicationpoolthatyourwebsiterunsunderwillneedtohaveatleast"browser"accesstothefoldercontainingthereportyouwanttodisplay.ThisisusuallyprettysimpleifboththeIISandSSRSserverarewithinthesamedomain,butitmightbetrickyifthisisnotthecase.
Microsoft.Reporting.WebForms.ReportViewerrview=newMicrosoft.Reporting.WebForms.ReportViewer();
//WebAddressofyourreportserver(ex: 'target='_blank'>http://rserver/reportserver)rview.ServerReport.ReportServerUrl=newUri(WebConfigurationManager.AppSettings[”ReportServer”]);System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter>paramList=newSystem.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter>();paramList.Add(newMicrosoft.Reporting.WebForms.ReportParameter(”Param1″,“Value1″));paramList.Add(newMicrosoft.Reporting.WebForms.ReportParameter(”Param2″,“Value2″));rview.ServerReport.ReportPath=“/ReportFolder/ReportName”;rview.ServerReport.SetParameters(paramList);stringmimeType,encoding,extension,deviceInfo;string[]streamids;Microsoft.Reporting.WebForms.Warning[]warnings;stringformat=“PDF”;//Desiredformatgoeshere(PDF,Excel,orImage)deviceInfo=“<DeviceInfo>”+“<SimplePageHeaders>True</SimplePageHeaders>”+“</DeviceInfo>”;byte[]bytes=rview.ServerReport.Render(format,deviceInfo,outmimeType,outencoding,outextension,outstreamids,outwarnings);Response.Clear();if(format==“PDF”){Response.ContentType=“application/pdf”;Response.AddHeader(”Content-disposition”,“filename=output.pdf”);}elseif(format==“Excel”){Response.ContentType=“application/excel”;Response.AddHeader(”Content-disposition”,“filename=output.xls”);}Response.OutputStream.Write(bytes,0,bytes.Length);Response.OutputStream.Flush();Response.OutputStream.Close();Response.Flush();Response.Close();OnepotentialissuethatyoumightrunintoupondeployingyourprojectisthatyourapplicationservermaynothavetheReportViewerDLLsthatareneeded.Youhavetwooptionsinthiscase.ThefirstistocopythethreeMicrosoft.ReportViewer.*.dll's(ReportViewer.Common.dll,ReportViewer.ProcessingObjectModel.dll,andReportViewer.WebForms.dll)fromyourdevelopmentcomputerintotheBINfolderofyourapplicationserver(orintotheGAC).Thesecondoption(thoughIhavenotverifiedit),istoinstalltheSSRSredistributableontheapplicationserver(http://www.microsoft.com/downloads/details.aspx?familyid=8a166cac-758d-45c8-b637-dd7726e61367&displaylang=en).
Checkouthttp://www.microsoft.com/sql/technologies/reporting/default.mspxforgoodSSRSresources,includingsomenicelearningtoolsandreportpacks.
相关文章推荐
- The report server cannot decrypt the symmetric key that is used to access sensitive or encrypted data in a report server databas
- [转载]:How to pass a list of values or array to SQL Server stored procedure?
- Validation failed for one or more entities while saving changes to SQL Server Database
- SQLServerException: 数据类型 time 和 datetime 在 less than or equal to 运算符中不兼容。
- To SP or not to SP in SQL Server: an argument for stored procedures
- convert return char from sql server 2008 r2 or below version to c#
- csharp: word or excel Convert to PDF
- Delphi Excel to Sql Server
- Import Data from Excel to SQL Server
- A network-related or instance-specific error occurred while establishing a connection to SQL Server
- How to troubleshoot slow-running queries on SQL Server 7.0 or on later versions [ZT-from MS]
- Import/Export Excel (.Xlsx) or (.Xls) File into SQL Server
- C# word or excel Convert to PDF
- A network-related or instance-specific error occurred while establishing a connection to SQL Server
- How to find user who ran DROP or DELETE statements on your SQL Server Objects
- a network-related or instance-specific error occurred while establishing a connection to sql server
- A network-related or instance-specific error occurred while establishing a connection to SQL Server
- Cannot connect to WMI provider.You do not have permission or the server is unreachable.Note that you can only manager SQL Server 2005 and later version with SQL Server Configuration Manager.Invalid namespace [0x8004100e]
- SQL Server has encountered 1 occurrence(s) of cachestore flush for the 'Object Plans' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.
- Inport Excel File To Sql Server Table