. Net Enterprise Excel report generation

Source: Internet
Author: User
Tags ranges

In general enterprise application development, report generation is involved, and the general report format is Excel format. The generation of various reports has always been a pain point for programmers, because for many programmers, every time they write a report, they need to write a large piece of code to implement it, in addition, some reports may be extremely complex and non-standard, which will waste a lot of time for programmers to write and debug the code. Is there any way to minimize the write of the code, in addition, we can generate various Excel reports. Next we will turn to the subject.

To generate an Excel report, we only need two things: 1. the report style, that is, where the field should be filled, what should be filled in the column, the font size, color, cell height, width, and whether the cells are merged and cross-row, cross-column or horizontal report (the so-called horizontal report, which is defined as an Excel report generated with a record or a record and its associated records, for example, an order report is usually generated by an order header and its related order details. This is my custom horizontal report) or a vertical report (so-called vertical report, custom: A report is generated by a record set. to generate a report that records the student status of a class, to export the student records of this class to this report, this report is basically a statistical report. A report may have tens of thousands or more records, this is my custom vertical Report) and other report styles.

2. the report data has a report style for us. We know which cells or cells should be filled with the data and the specific data, which can be expressed in the form of a able, it can also be expressed in the form of DataSet. You can define the data format as you like.

Now we know that as long as the style and data are available to generate an Excel report, we can generate a report we want. It is not difficult to generate data, however, the difficulty is what is used to describe the report style and how to describe it.

We can use two methods to describe the style:

1. directly use XML to describe the content of this xml description file. The content of this description file can be described as follows (for example, the description of a column is not very standard ):

Reference content is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Style>
<ExcelStyle Sort = "portrait" Space = "1">
<Ranges>
<RangeStyle>
<Range CellWidth = "2.0" CellHeight = "20" CellBord = "1" CellBackColor = ""> </Range>
<TitleCell TitleName = "part No." TitleStartxPos = "1" TitleEndxPos = "1" TitleStartyPos = "1" TitleEndyPos = "1"> </TitleCell>
<DataCell DataName = "PartNo" DataStartxPos = "2" DataEndxPos = "14" DataStartyPos = "34" DataEndyPos = "34" IsMerger = "False" Align = "XlHAlign. xlHAlignLeft "IsToArray =" True "IsDateTime =" False "Interval =" 1 ">
</DataCell>
<TitleFont TitleFontName = "" TitleFontSize = "9" TitleFontColor = "Black" TitleFontBold = "False" TitleFontItatic = "False" TitleFontPosition = "Center"> </TitleFont>
<DataFont DataFontName = "" DataFontSize = "11" DataFontColor = "Black" DataFontBold = "True" DataFontItatic = "False" placement = "False" DataFontPosition = "Center">
</DataFont>
</RangeStyle>
</Ranges>
</ExcelStyle>
</Style>

In this XML, the node Excelstyle attribute Sort describes whether the entire Excel format is vertical or horizontal (the so-called vertical or horizontal, as described above ), the attribute Space describes the number of blank rows between the rows of each record in the report. Ranges is the parent node of RangeStyle of all the following subnodes. For a report, there are usually many RangeStyle nodes. RangeStyle actually begins to describe which cells or fields to fill in. For example, the node Range defines the attributes of cell height, width, Border width, and color. TitleCell defines the attributes of the Title, such as the Title name and the cell in which the Title is defined. The node DataCell defines which field in the data to help determine, from which unit to fill in, whether the cell is to be merged, alignment, and the interval between the field row and row. Node Title Font defines the Title Font attributes, such as size, color, italic, bold, and alignment. Node DataFont defines the data font attributes, such as size, color, italic, bold, and alignment. A RangeStyle node defines a field. If you want to fill in many fields in your report, there will be many RangeStyle nodes to describe. This xml style definition file can be generated by writing a tool by myself. I have a ready-made generation tool called ExcelStyle, but it is still very simple and inconvenient to use, however, you can generate the style you need. Which of the following can I send to you? (I don't know how to download it ).

2. the combination of XML Description files and Excel templates is complicated for some reports, especially those horizontal reports. In this case, a ready-made Excel template is required, with an Excel template, we can refer to the template to generate an xml style definition file. When generating a report, we only need to know which Excel template is used and which XML style file is used, after binding our data, even complex reports can be generated.

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.