excel|js| Printing | solution | Control doing web Development everyone has encountered the problem of printing, for complex form printing is really a headache, this article describes the use of Excel printing solution.
First of all, if the client calls Excel must reduce the IE security level, so that some illegal controls, such as 3721 or anything are automatically installed, so I resolved: Keep the original IE settings, add your site to the trust site, and then change the security site security level, This will give your site a secure channel, and to prevent the illegal invasion of 3721, of course, if you want to let your customers download a registry and install, I do it by myself, so I have to user is what I say follow me to do, you need to convince the customer:).
OK, then the next step is how to achieve the print, here I have a very good report, and some very complex, such as student transcripts, need to be in accordance with the school year, semester calculation credits, print photos, degree grant, status of treatment, 46 grades, internships, minor achievements, practice, etc. So how can I print this information completely to the client is very troublesome, all I use Excel, first make a template, and then call the template fill data, the problem again, so much data how to organize it, groping for a long time, suddenly have an idea, the extraction of data alone to write an object, So my program is much simpler, and the best is that I can use it anywhere. Also said that the transcript, the data is very large, more than 150 data, so my data source selected the table, so do not have to bother to generate what XML, the display is the data I want. OK introduce gettabledata.js: It is the data object I want, the main function is to extract data from table (Gettabledata), and provide a method of output data (GetFieldData), this basic function can meet most of my needs. This I wrote a brief introduction, afraid of later I forgot:), we see what is not clear I add.
The obj parameter specifies the source of the data (qualifying table), and the default first behavior field name row
MoveNext method, the parameter is the number of digits that the row of the table moves up or down, the positive numbers move downward, and the negative numbers go up. MoveNext (1),. MoveNext (-1)
The GetFieldData method obtains the number of specified column names for the current row, as follows:. GetFieldData ("Exam results"): Column name. GetFieldData (1): Index
The Sort_desc method arranges the specified columns in descending order, such as. Sort_desc ("school year", "semester")
The Sort_asc method arranges the specified columns in ascending order, such as. SORT_ASC ("Test score: Number"): ":" The parameters after the Change column data type, this example is a numeric
The GetData method returns an array of data for which the field value is a specific value, and returns all of the field records if there are no field values. You can perform other processing externally and do not recommend handling data directly: such as. GetData ()
The Delete method deletes the current record, and the array decreases by one line, such as:. Delete
Updatefield updates the specified index data for the current row (index, if the index is a number, is the column, is the character, is the name of the data field) such as: Mydata.updatefield ("Course number", Mydata.getfielddata ("Original course number"))
MoveFirst records are moved to the first record of the data, note that the data starts with the second row, the default first behavior field name row
MoveLast a record to the last record of the data
Distinct returns an array of the number of criteria for the different records of the selected record, sorted in ascending order
initialization, obj:table name, Leftlen: Left extra data length, Rightlen: Right excess data length,
Rows property: Array of rows, cols: Number of columns
In the sample code Print_bzcjd.js He is a script that prints complex Excel,
var xlbook = xls. Workbooks.Open ("C:\\xsxycjb.xls");
var xlsheet = xlbook.worksheets (1)
This is the use of network templates,
var xlbook = xls. Workbooks.Open ("http://you.com/\printtemplates\\xsxycjb.xls");
var xlsheet = xlbook.worksheets (1)
This force example in the basic printing of Excel needs of the technology are displayed, such as pictures, exit or something.
Here to explain that the table data can be hidden, do not show also can be taken out, so you can add a lot of data to come in without affecting the interface.
Excel.js: This is the script to clean up Excel, when the Excel process is finished, it has not been launched, clean up, there is no vs.: (.
This is a simple example, you give him a form name on it, and then generate a table, that is: Makeexcel ("TABLE1", True, "1.xls"), other parameters can not.
function Makeexcel (Obj,procevisible,saveasfilename,sorttype,sortfield) {
var mydata= new Gettabledata (obj,0,0);
var myrows=mydata.rows;
var i,j;
try {
var xls = new ActiveXObject ("Excel.Application");
}
catch (e) {
Alert ("To print the table, you must have the Excel spreadsheet software installed, and the browser must use ActiveX controls, and your browser must allow the control to be executed.") Click "Help" to learn how to set up your browser! ");
Return "";
}
if (typeof (procevisible) = = "undefined") {
Xls.visible = true;
}
else{
if (procevisible== "true") {
Xls.visible = true;
}
Else
{
Xls.visible = false;
}
}
var xlbook = xls. Workbooks.Add;
var xlsheet = xlbook.worksheets (1);
Xls. Cells.select;
Xls. selection.numberformatlocal = "@";
for (i=0;i<mydata.rows; i++) {
for (J=0;j<mydata.cols; j + +) {
if (typeof (Mydata.getfielddata (j)) = = "Number") {
Xlsheet. Cells (i+1,j+1). numberformatlocal = "0.00_";
}
Xlsheet. Cells (i+1,j+1). Value= Mydata.getfielddata (j);
}
Mydata.movenext ();
}
if (saveasfilename== "" | | | typeof (saveasfilename) = = "undefined") {
var fname = xls. Application.getsaveasfilename ("*.xls", "Excel spreadsheets (*.xls), *.xls");
if (fname!= "") {
Xlbook.saveas (fname);
}
}
else{
Xlbook.saveas (Saveasfilename);
}
Xlbook.close (Savechanges=false);
Xls.visible = false;
Xls. Quit ();
Xls=null;
End Excel process, exit finish
Window.setinterval ("Cleanup ();", 1);
}
Turn from: Dynamic Network production guide www.knowsky.com