This article from: http://www.cnblogs.com/whitewolf/archive/2011/03/21/Aspose_Cells_Template1.html
This article will briefly record the powerful Excel operation component aspose. cells. The strength of this component is not to mention. For our reports, there will always be Excel export processing. If you use the COM component of Microsoft Excel, it will be okay for simple operations, however, redundant and complex templates are a headache. Under aspose. cells, it will be a simple task. He can import and export Excel files. In this section, he will talk about the powerful export functions of his excel template.
If you do not need to mention it, we will first use northwind for two small demos. Let's talk about the template syntax of aspose. Cells:
- & = Datasource. Field, & = [datasource]. [field] is a reference to the able and ry types. Multiple rows of data are generated vertically and downward from the current row.
- & = $ Data: A reference to a variable or array. Array existsSkip,Horizontal, etc.For more information, see the official website.
- & = Dynamic formula calculation; {r} current row, {c} current column, {-n}, {n} current row or column offset before or after N.
- & = It is a dynamic computing statement, such as an Excel or if statement. (If (logic_test, true_value, false_value ))
There are other more complex aggregate computing expressions. I will not talk about them here. If you are interested, please visit the official website. Let's take a simple example. Simply put, it's always impossible.CodePractice can describe everything:
Excel template 1:
Code: Add a data source in our code:
As follows:
View code
1 VaR SQL = @" Select * from MERs
2 Where MERs. City = 'London' " ;
3 VaR dt = Getdatatable (SQL );
4 DT. tablename = " MERs " ;
5 Workbookdesigner = New Workbookdesigner ();
6 Designer. Open (mappath ( " ~ /1.xls " ));
7 // Data Source
8 Designer. setdatasource (DT );
9 // Report Unit
10 Designer. setdatasource ( " Reportutils " , " XXXXX customer information " );
11 Designer. setdatasource ( " Reportadd " , " London " );
12 // Deadline
13 Designer. setdatasource ( " Reportdate " , Datetime. Now. tostring ( " Yyyy-mm-dd " ));
14
15 Designer. Process ();
16
17 Designer. Save ( String . Format ( " Report.xls " ), Savetype. openinexcel, fileformattype. excel2003, response );
18 Response. Flush ();
19 Response. Close ();
20 Designer = Null ;
21 Response. End ();
The code is very simple, that is, adding a datatable and several variable data sources. The generated Excel is:
This completes a simple multi-header data export report.
In demo2, we will try his statistical formula and function compute (using & = for calculation ):
Excel template 2: Order Details table of northwind
Code: different from the above, there are only a few words:
View code
1 VaR order = Getdatatable ( @" Select * from [Order Details]
2 Where [Order Details]. orderid = 10248 " );
3 Order. tablename = " Order " ;
4
5 Designer. setdatasource (order );
Excel effect:
Download all the code from an Excel template:
View code
1 Protected Void Page_load ( Object Sender, eventargs E)
2 {
3 VaR s = Aspose. cells. cellshelper. getversion ();
4 VaR SQL = @" Select * from MERs
5 Where MERs. City = 'London' " ;
6 VaR dt = Getdatatable (SQL );
7 DT. tablename = " MERs " ;
8 VaR order = Getdatatable ( @" Select * from [Order Details]
9 Where [Order Details]. orderid = 10248 " );
10 Order. tablename = " Order " ;
11 Workbookdesigner = New Workbookdesigner ();
12 Designer. Open (mappath ( " ~ /1.xls " ));
13 // Data Source
14 Designer. setdatasource (DT );
15 Designer. setdatasource (order );
16 // Report Unit
17 Designer. setdatasource ( " Reportutils " , " XXXXX customer information " );
18 Designer. setdatasource ( " Reportadd " , " London " );
19 // Deadline
20 Designer. setdatasource ( " Reportdate " , Datetime. Now. tostring ( " Yyyy-mm-dd " ));
21
22 Designer. Process ();
23
24 Designer. Save ( String . Format ( " Report.xls " ), Savetype. openinexcel, fileformattype. excel2003, response );
25 Response. Flush ();
26 Response. Close ();
27 Designer = Null ;
28 Response. End ();
29 }