Description: This is a small example of an experiment, when used in a real project, the general object[,] object data originates from the database.
1. Experimental environment
Development platform: Visual Studio 2010
Test Template: Jbtest
excel:office2007 Excel
2. Components used in the project
Why do you choose ASP. Because Office and Visual Studio are Microsoft's development software, with good compatibility, with the above-mentioned. dll components, you can easily implement the import of Excel templates and the export of Excel data.
The ExcelQuicker.dll dynamic link library needs to be downloaded online and referenced in the project to be used. I use this version earlier, the version number is 2.2.0.0. Now the updated version may have modified some functions and the name of the class, please refer to use later.
3. Webconfig Configuration
4. Project Structure
The above is the overall structure of the project, where the test page is Default.aspx. The excelquicker.xml in the Lib directory is the configuration document for the Excelquicker component, Message.xml is the wrong information to import the error times.
5. Report Printing
First in the implementation of the printed page background reference namespace: using Excelquicker.framework;
Use the interfaces provided by the corresponding classes in the Excelquicker.framework space to implement the new report
Eqapplication objapp = new Eqapplication (strFileName, Eqreportformat.excel, strtemplate, false);
Eqworksheet objWS = new Eqworksheet ("Report data");
The data is written to an Excel document similar to VBA programming, please refer to the code for detailed features: Default.aspx.cs
Eqrange range = new Eqrange (Objdata, 11, 5, 15, 5); From "11 Rows 5 Columns" to "22 Rows 5 Columns"
Objws.add (range);
Default.aspx.cs Backstage Main code:
protected void Dy_click1 (object sender, EventArgs e)
{
String WJM;
String strtemplate = "Jbtest.xls";//Template file name
Initialize ();//Call the Excel quicker initialization function
String strFileName = session["Yhid"]. ToString ();
String strFileName = "Wangling";
WJM = strFileName;
WJM = Wjm + "_" + strtemplate;
Set_excel (WJM, strtemplate);//Generate and set this Excel table
Response.Redirect (".. \\ExcelQuicker\\TempReports\\ "+ WJM);
}
public void Initialize ()
{
Eqconfiguration.xmlfilename = Httpruntime.appdomainapppath + "Excelquicker\\lib\\message.xml";
Eqconfiguration.language = "EN";
Eqconfiguration.temporaryfilepath = Httpruntime.appdomainapppath + "excelquicker\\tempreports\\";
Eqconfiguration.outputfilepath = Httpruntime.appdomainapppath + "excelquicker\\tempreports\\";
Eqconfiguration.templatefilepath = Httpruntime.appdomainapppath + "jb\\xls\\";
}
void Set_excel (String strFileName, String strtemplate)
{
Eqapplication objapp = new Eqapplication (strFileName, Eqreportformat.excel, strtemplate, false);
Eqworksheet objWS = new Eqworksheet ("Report data");
object[,] objdata, ObjData3, ObjData4, ObjData5, OBJDATA6, ObjData7;
Objdata = new object[5, 1];//for storing data to be populated in Excel
OBJDATA3 = new object[8, 1];
OBJDATA4 = new object[1, 1];
ObjData5 = new object[3, 1];
OBJDATA6 = new object[8, 1];
ObjData7 = new object[8, 1];
String Ren, ren1, Ren2, Ren3;
Objdata[0, 0] = Congye. Text;//Employee End-of-term
objdata[1, 0] = Guanli. Text;//Unit Head
objdata[2, 0] = Zaigang. Text;//Staff
Objdata[3, 0] = Laowu. Text;//Labor dispatch personnel
Objdata[4, 0] =qita0. Text;//Other practitioners
ren = "188" + "person";
Ren1 = "22" + "person";
Ren2 = "33" + "person";
Ren3 = "44" + "person";
Objdata4[0, 0] = average number of ren;//directly engaged in production and business activities
Objdata5[0, 0] = ren1;//: Engineering Technician
objdata5[1, 0] = ren2;//: First-class construction engineer
objdata5[2, 0] = ren3;//of which: on-site construction personnel
Eqrange range = new Eqrange (Objdata, 11, 5, 15, 5); From "11 Rows 5 Columns" to "22 Rows 5 Columns"
Objws.add (range);
Eqrange range4 = new Eqrange (OBJDATA4, 30, 3, 30, 3); From "11 Rows 5 Columns" to "22 Rows 5 Columns"
Objws.add (RANGE4);
Eqrange range5 = new Eqrange (OBJDATA5, 32, 6, 34, 6); From "11 Rows 10 Columns" to "22 Rows 10 Columns"
Objws.add (RANGE5);
Objdata7[0, 0] = Pingjun. Text;
objdata7[1, 0] =zaigangpj0. Text;
objdata7[2, 0] = laowupj0. Text;
Objdata7[3, 0] = qitapj. Text;
Range7 1-average number of people in the season//
Eqrange Range7 = new Eqrange (OBJDATA7, 16, 5, 19, 5);
Objws.add (Range7);
Objdata3[0, 0] =congyeg. Text;//Payroll of employees
objdata3[1, 0] = Zaizhig. Text;//Payroll for Employees
objdata3[2, 0] = Laog. Text;//Payroll of labor dispatch personnel
Objdata3[3, 0] = Qitag. Text;//Payroll for other practitioners
Eqrange range3 = new Eqrange (OBJDATA3, 21, 5, 24, 5); From "11 Rows 10 Columns" to "22 Rows 10 Columns"
Objws.add (Range3);
Objdata6[0, 0] = congyepjg. Text;
objdata6[1, 0] = zaigangpjg. Text;
objdata6[2, 0] =laowupjg. Text;
Objdata6[3, 0] = qitapjg. Text;
Eqrange Range6 = new Eqrange (OBJDATA6, 25,5,28, 5);
Objws.add (Range6);
Fill in the information of the person who submitted
string ryxx = "unit owner:" + DF. Text + "Statistics in charge:" + XF. Text + "Fill in person:" + TF. Text;
Objdata = new object[1, 1];
Objdata[0, 0] = ryxx;
Range = new Eqrange (Objdata, 35, 1, 35, 1);
Objws.add (range);
The following fill in the header unit name
Objdata = new object[1, 1];
Objdata[0, 0] = "Excel Tabular data export test";
Range = new Eqrange (Objdata, 7, 1, 7, 1);
Objws.add (range);
Objapp.add (OBJWS);
Try
{
Objapp.output ();
}
catch (Exception)
{
Objapp.dispose ();
}
}
6. Effects
interface to fill in the data, the input into the corresponding Excel document
After filling in the data, click the Export Excel button, the interface appears
Results after printing to Excel
The above small example download: Demo.zip
. NET to print Excel reports