Summary and analysis of Excel technology under ASP

Source: Internet
Author: User

ASP Excel Technical Summary

Directory
I. Environment Configuration
Ii. Basic ASP operations on Excel
3. Generate a data table using ASP Excel
Iv. Generate a Chart using ASP Excel
V. Solutions for viewing, downloading and deleting Excel files on the server
Vi. Appendix
Body
I. Environment Configuration
Server-side environment configuration from the perspective of reference materials, Microsoft series configuration should be all done, that is:
1. Win9x + PWS + Office
2. Win2000 Professional + PWS + Office
3. Win2000 Server + IIS + Office
Currently, the test is successful in the latter two environments. There are no special requirements for the Office version. Considering the uncertainty and compatibility of the client configuration, it is recommended that the Office version on the server end be too high to prevent the client from being correctly displayed after download.
Two accidental discoveries of server-side environment configuration are as follows:
1. The author developed the WPS2002 with Kingsoft installed on the machine. As a result, the Excel Object creation problem always occurs. After WPS2002 is uninstalled, the error disappears.
2. I developed ASP code and liked to use FrontPage. I found that if the FrontPage is opened (on the server side), the object creation is unstable, and sometimes it succeeds or fails. After the extension test, we found that if the Office series software runs on the server side, it is difficult to create an Excel object.
The operation permission of the COM component must also be set on the server side. Type "DCOMCNFG" in the command line to go to the COM component configuration page. select Microsoft Excel and click the Properties button. All three single options are customized. In the editing window, add Everyone to all permissions. Restart the server after saving the file.
Client environment configuration does not find anything special, as long as the Office and IE are installed, the general version seems to be OK.

Ii. Basic ASP operations on Excel
1. Create an Excel Object
Set objExcelApp = CreateObject ("Excel. Application ")
ObjExcelApp. DisplayAlerts = false no warning is displayed
ObjExcelApp. Application. Visible = false: the interface is not displayed.
2. Create an Excel file
ObjExcelApp. WorkBooks. add
Set objExcelBook = objExcelApp. ActiveWorkBook
Set objExcelSheets = objExcelBook. Worksheets
Set objExcelSheet = objExcelBook. Sheets (1)
3. Read existing Excel files
StrAddr = Server. MapPath (".")
ObjExcelApp. WorkBooks. Open (strAddr & "\ Templet \ Table.xls ")
Set objExcelBook = objExcelApp. ActiveWorkBook
Set objExcelSheets = objExcelBook. Worksheets
Set objExcelSheet = objExcelBook. Sheets (1)
4. save an Excel file
ObjExcelBook. SaveAs strAddr & "\ Temp \ Table.xls"
5. Save the Excel file
ObjExcelBook. Save (saved successfully during the test. An error is reported on the page .)
6. Exit the Excel operation.
ObjExcelApp. Quit must exit
Set objExcelApp = Nothing

3. Generate a data table using ASP Excel
1. Insert data within a range
ObjExcelSheet. range ("B3: k3 "). value = Array ("67", "87", "5", "9", "7", "45", "45", "54", "54 ", "10 ")
2. Insert data into a cell
ObjExcelSheet. Cells (3, 1). Value = "Internet Explorer"
3. Select a range
4. Draw a rough line on the left of the cell
5. Draw a rough line on the right of the cell
6. Draw a thick line above the cell
7. Draw a rough line under the cell
8. Set the background color for cells.
9. Merge Cells
10. Insert rows
11. Insert Columns

Iv. Generate a Chart using ASP Excel
1. Create a Chart
ObjExcelApp. Charts. Add
2. Set Chart types
ObjExcelApp. ActiveChart. ChartType = 97
Note: Two-dimensional line chart, 4; two-dimensional pie chart, 5; two-dimensional column chart, 51
3. Set the Chart title
ObjExcelApp. ActiveChart. HasTitle = True
ObjExcelApp. ActiveChart. ChartTitle. Text = "A test Chart"
4. Use table data to set Images
ObjExcelApp. ActiveChart. SetSourceData objExcelSheet. Range ("A1: k5"), 1
5. directly set graphic data (recommended)
ObjExcelApp. ActiveChart. SeriesCollection. NewSeries
ObjExcelApp. ActiveChart. SeriesCollection (1). Name = "=" "333 """
ObjExcelApp. ActiveChart. SeriesCollection (1). Values = "="
6. Bind a Chart
ObjExcelApp. ActiveChart. Location 1
7. Display Data Tables
ObjExcelApp. ActiveChart. HasDataTable = True
8. Display legend
ObjExcelApp. ActiveChart. DataTable. ShowLegendKey = True

V. Solutions for viewing, downloading and deleting Excel files on the server
There are many solutions for browsing, "Location. href = "," Navigate "," Response. redirect "can be implemented. We recommend that you use the client method, because it gives the server more time to generate an Excel file.
The download implementation requires some trouble. It is a good solution to download components from a ready-made server on the Internet or develop a component by yourself. Another method is to operate the Excel component on the client, and save the Excel file on the client to the client. This method requires the client to enable the operation permission of the insecure ActiveX Control. Considering the trouble of notifying each customer to set the server as a trusted site, we recommend that you use the first method to save trouble.
The deletion scheme consists of three parts:
A: an Excel file generated by the same user is composed of the same file name. The file name can contain user ID or SessionID to ensure that strings are not repeated. In this way, the previous file is automatically overwritten when a new file is generated.
B: When the Session_onEnd event is set to be triggered in the Global. asa file, delete the Excel temporary file of this user.
C: delete all files under the temporary directory when the Application_onStart event is set in the Global. asa file.
Note: It is recommended that the directory structure \ Src code directory \ Templet template directory \ Temp temporary directory

Vi. Appendix
When an error occurs, it is a headache to see an Excel dead process. Adding "On Error Resume Next" before each file will help improve this situation, because it will be executed to "Application. quit ensures that no dead processes are left after each program is executed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.