ASP Excel Technical Summary

Source: Internet
Author: User

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 ASPCodeI like to use FrontPage. It turns out that if the FrontPage is opened (on the server side), the object creation may be unstable, and sometimes it may fail. 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

The following is a reference clip:
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

The following is a reference clip:
Objexcelapp. workbooks. Add

Set objexcelbook = objexcelapp. activeworkbook

Set objexcelsheets = objexcelbook. worksheets

Set objexcelsheet = objexcelbook. Sheets (1)

3. Read existing Excel files

The following is a reference clip:
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

The following is a reference clip:
Objexcelbook. saveas straddr & "\ temp \ table.xls"

5. Save the Excel file

The following is a reference clip:
Objexcelbook. Save (saved successfully during the test. An error is reported on the page .)

6. Exit the Excel operation.

The following is a reference clip:
Objexcelapp. Quit must exit

Set objexcelapp = nothing

3. Generate a data table using ASP Excel

1. Insert data within a range

The following is a reference clip:
Objexcelsheet. range ("B3: K3 "). value = array ("67", "87", "5", "9", "7", "45", "45", "54", "54 ", "10 ")

2. Insert data into a cell

The following is a reference clip:
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

The following is a reference clip:
Objexcelapp. charts. Add

2. Set chart types

The following is a reference clip:
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

The following is a reference clip:
Objexcelapp. activechart. hastitle = true

Objexcelapp. activechart. charttitle. Text = "A test chart"

4. Use table data to set Images

The following is a reference clip:
Objexcelapp. activechart. setsourcedata objexcelsheet. Range ("A1: K5"), 1

5. directly set graphic data (recommended)

The following is a reference clip:
Objexcelapp. activechart. seriescollection. newseries

Objexcelapp. activechart. seriescollection (1). Name = "=" "333 """

Objexcelapp. activechart. seriescollection (1). Values = "= {1, 4, 5, 6, 2 }"

6. Bind a chart

The following is a reference clip:
Objexcelapp. activechart. Location 1

7. Display Data Tables

The following is a reference clip:
Objexcelapp. activechart. hasdatatable = true

8. Display legend

The following is a reference clip:
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" to each file will help improve this situation, because it will always execute "application. Quit" regardless of whether the file produces errors.ProgramNo dead process is left after execution.

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.