.NET About the generation of enterprise Excel report

xiaoxiao2021-03-06  40

In a general enterprise application development, it will involve the generation of reports, and the format of the general report is generated in an Excel format. For the generation of various reports, it has always been the pain in the hearts of the programmer. Because every report is written for many programmers, it means to write a big break code, and some reports may be extremely complicated and irregular. At the time, the programmer will waste the programmer to write and debug these code. If there is any way to write the code as little as possible, and can achieve the generation of various Excel reports, let's transfer to the topic.

We have to generate an Excel report, in fact, we only need two things:

1. What is the style of the report, which field should be filled, which column should be filled, the font size, color, cell height, width, whether the cell is merged, whether it is cross-line, is a transverse report (so-called horizontal " Report, I have been customized as: an Excel report is a record that records or has a record and its associated record. If a order report is usually generated by a order head and its related order details, this is me Custom horizontal report) or longitudinal report (so-called longitudinal report, I have been customized as: A report is generated by a recordset, if you want to generate a report that records a class student situation, you have to put this class The student record must be exported to this report, this report is basically a statistical report, and a report may have tens of thousands of records or more. This is the longitudinal report of my customized report) and so on.

2. Data of the report, have a report style for us, we know which data should be filled in which data, specific data, we can behave in the form of DataTable or DataSet The form is expressive, as for how to use it, you can define it.

Now we know that generating an Excel report As long as you have style and data, you can generate a report you want. The generation is not difficult, but our difficult is to describe the style of this report, how to describe .

For the description of the style we can use two ways:

1. Directly use XML to describe that the primary description of this XML description file can be as follows (lifetime description, it is not very specified):