First, if the client calls excel, it must reduce the ie security level, so some illegal controls, such as 3721, are automatically installed, So I solve this problem: keep the original ie settings, add your site to a trusted site, and then change the security level of the secure site. In this way, a secure channel is set up for your site and illegal intrusion of 3721 is prevented, of course, the premise is that you want your customers to download a registry and install it. I do it myself and use it myself, so I have to follow me when I say everything, you need to convince the customer :).
Well, the next step is how to print it. Here I have won the report very much, and some very complicated ones, such as the student transcript. I need to calculate the credit points and print photos based on the academic year and semester, it is very troublesome for me to print the complete information to the client in terms of degree granting, student status handling, Grade 4 and grade 6, internship, minor score, and practice, I used excel to create a template first, and then called the template to fill in the data. The problem arises again. How can I organize so much data? For a long time, I suddenly had an idea, write an object separately for data extraction, so that my program is much simpler, and it is best for me to use it anywhere. I also said that the transcript shows that the data is very big and 150 pieces of data are required. Therefore, I chose a table as the data source, so that I do not have to generate any xml, and the data I want is displayed. OK to introduce Gettabledata. js: it is the data object I want. The main function is to extract data from the table GetTableData), and provide a method for outputting data getfielddata ), this basic function can meet most of my needs. This is an introduction I wrote by myself, for fear I forgot it later :). Let's take a look at what I don't know.
// The Obj parameter specifies the data source (Table defined). The first row of the field name is used by default.
// MoveNext method. The parameter is the number of digits that the table row moves up or down. A positive number moves down and a negative number moves up. For example, MoveNext (1) and. MoveNext (-1)
// The GetFieldData method is used to obtain the number of specified column names in the current row, for example,. GetFieldData ("exam result"): column name. GetFieldData (1): Index
// The Sort_desc method sorts the specified columns in descending order, for example,. Sort_desc ("School Year", "Semester ")
// The Sort_asc method is used to sort the specified columns in ascending order, for example,. Sort_asc ("score: number"): ":" The following parameter is used to change the column data type. This example is a number.
// The GetData method returns an array of data with a specific field value. If no field value exists, all records of this field are returned. you can perform other operations externally. We do not recommend that you process data directly, for example. getData ()
// Delete the current record, and Delete a row from the array, for example,. Delete
// UpdateField updates the specified index data index of the current row. If it is a number, it is the column index, which is a character and the name of the data field) for example: MyData. updateField ("course No.", MyData. getFieldData ("original course number "))
// Move the MoveFirst record to the first record of the data. Note that the data starts from the second row and the first row of the field name is used by default.
// Move the MoveLast record to the last record of the data
// Distinct returns the array of condition number dimensions for different records of the selected record and sorts the records in ascending order.
// Initialization, Obj: table Name, Leftlen: length of excess data on the left, Rightlen: length of excess data on the right,
// Rows attribute: number of rows in the array, cols: Number of Columns
In the sample code, Print_bzcjd.js prints a complex excel script,
- var xlBook = xls.Workbooks.Open("c:\\xsxycjb.xls");
- var xlsheet = xlBook.Worksheets(1)
This is a network template,
- var xlBook = xls.Workbooks.Open("http://you.com/\PrintTemplates\\xsxycjb.xls");
- var xlsheet = xlBook.Worksheets(1)
In this example, we basically show all the technologies required for excel printing, such as film and exit.
It should be noted that the table data can be hidden or retrieved without being displayed. In this way, a large amount of data can be added without affecting the interface.
Excel. js: This is the excel cleanup script. When the excel process is finished, it has not been released yet. If you clean it up, there will be no :.
This is a simple example. You can give a table name and then generate a table like this: MakeExcel ("TABLE1", true, "1.xls "), other parameters are optional.
- FunctionMakeExcel (Obj, ProceVisible, SaveAsFilename, SortType, SortField ){
- VarMyData =NewGetTableData (Obj, 0, 0 );
- VarMyrows = MyData. rows;
- VarI, j;
-
- Try{
- VarXls =NewActiveXObject ("Excel. Application");
- }
- Catch(E ){
- Alert ("To print this table, you must install the Excel spreadsheet software and use the" ActiveX control "in the browser. Your browser must allow the execution of the control. Click Help to learn about browser settings! ");
- Return "";
- }
- If(Typeof(ProceVisible) ="Undefined"){
- Xls. visible =True;
- }
- Else{
- If(ProceVisible ="True"){
- Xls. visible =True;
- }
- Else
- {
- Xls. visible =False;
- }
- }
- VarXlBook = xls. Workbooks. Add;
- VarXlsheet = xlBook. Worksheets (1 );
- Xls. Cells. Select;
- Xls. Selection. NumberFormatLocal ="@";
- For(I = 0; IFor(J = 0; jIf(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"){
- VarFname = 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;
- // Ends the excel process and exits
- Window. setInterval ("Cleanup ();", 1 );
- }
Edit recommendations]
- Document and window objects in JavaScript
- Introduction to the simulation of object-oriented technology in JavaScript
- Memory leakage of IE and the release of JavaScript Memory
- How to optimize the performance of JavaScript scripts
- The most common 25 classic tips in Javascript