C # generate report documents on the server: generate Word and Pdf reports using a soft report,

Source: Internet
Author: User

C # generate report documents on the server: generate Word and Pdf reports using a soft report,
I. Introduction to finereport

Among the Report tools, the final Report is better than the Report tools such as Crystal Report and SQL Server Report Service (SSRS, in addition, the soft report is also well applied in statistical charts and data reporting. Here we only talk about the application of the basic report function of the soft report.

Http://www.fanruan.com/

2. server integration

The final soft report is implemented in Java and can be deployed on Tomcat. The report can be directly displayed in the browser when the client views the report.

For the generation of report documents in enterprise applications, you can obtain the Word and Pdf output documents of reports/reports by simulating Web requests. If you need to perform secondary processing on the generated documents, for example, merging with other documents, you can use Word to operate components, services (such as DocX, MS Word DCOM, etc.), or PDF operation components (such as iTextSharp) to operate documents, A complete report is generated.

For example, the finereport service path is http: // localhost: 8075/WebReport/ReportServer. You can specify the report path to be accessed by passing the reportlets parameter, parameters passed to the report can be appended to the url in the format of paramname = paramvalue. If you use HTTP Get to request the URL, you can access the report.

The format parameter specifies the output file format, which can be specified as pdf, doc, and xls to output PDF, Word, and Excel files. Note that the output Word file is essentially an RTF file, to use DocX and other Office Open XML operations, you must first convert the format. The best way is to use Microsoft Word DCOM. Similarly, Excel is also in the 97-2003 format. For report output, the Soft Sail is not good enough.

Request Report:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);request.Method = "GET";HttpWebResponse response;try{     response = (HttpWebResponse)request.GetResponse(); }catch (Exception ex){    } if (response.ContentType != "application/pdf" && response.ContentType != "application/msword" && response.ContentType != "application/x-excel"){    response.Close(); } Stream stream = response.GetResponseStream();

Write to file:

int bufferSize = 2048;byte[] bytes = new byte[bufferSize];string fileSaveFolder; fileName = Guid.NewGuid().ToString();string fileSaveName = fileName + extName;string fileSavePath = fileSaveFolder + fileSaveName;FileStream fs = new FileStream(fileSavePath, FileMode.Create);int length = stream.Read(bytes, 0, bufferSize);while (length > 0){    fs.Write(bytes, 0, length);    length = stream.Read(bytes, 0, bufferSize);}stream.Close();fs.Close(); 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.