From the perspective of reference materials, the configuration of the Microsoft series should be done from the reference data, that is: 1. Win9X+PWS+Office 2. Win2000 Professional+PWS+Office 3. Win2000 Server+IIS+Office This article contains this article ASP reading operation to generate an example code tutorial for generating excel files. Detailed explanation of the relevant reading operations in the article generates Excel technology and knowledge. Welcome to give you some support and help in this area. Intersection The following is the details:
ASP operation Excel technology summary
Table of contents
1. Environmental configuration
2. ASP's basic operation of Excel
3. ASP operation Excel generates data table
4. ASP operation Excel generates chart diagram
Fifth, the server side Excel file browsing, downloading, and deleting solutions
6. Appendix
text
1. Environmental configuration
From the perspective of the reference information, the configuration of the Microsoft series should be done, that is,:
1. Win9x+PWS+Office
2. Win2000 Professional+PWS+Office
3. Win2000 Server+IIS+Office
At present, the author's successful environment is the latter two. The Office version does not have special requirements. Considering the uncertainty and lower compatibility characteristics of the client configuration, it is recommended that the server -side Office version should not be too high to prevent the client from being displayed correctly after downloading.
There are two accidental discovery of the server environment configuration::
1. The author developed the WPS2002 with Kingsoft on the machine. As a result, the EXCEL object creation always had problems. After uninstallation of WPS2002, the error disappeared.
2. The author develops an ASP code like to use FrontPage, but found that if FrontPage is opened (server side), the object creation is unstable, and sometimes success and unsuccessful. After the expansion inspection, it was found that if the Office of the Office series is running on the server, the creation of the Excel object is difficult to succeed.
One point must be set on the server side is the operating authority of the COM component. Type the DCOMCNFG in the command line, enter the COM component configuration interface, select the Microsoft Excel, click the attribute button, select the three single options, and add the EVENE to the ownership in the editor. Re -start the server after saving.
The client's environment configuration is not found to be particularly particular about it. As long as it is installed with Office and IE, it seems that the versions are common.
2. ASP's basic operation of Excel
1. Establish an excel object
set object = createObject (Excel.application)
Objexcelapp.displayalerts = false does not show warnings
objexcelapp.application.visible = false does not display the interface
2. Create an excel file
objexcelapp.workbooks.add
set object = object = object
set objectsheets = Objexcelbook.Worksheets
set objexcelsheet = Objexcelbook.Sheets (1)
3. Read the existing Excel file
straddr = Server.mappath (.)
Objexcelapp.Workbooks.open (Straddr & /Templet/table.xls)
set object = object = object
set objectsheets = Objexcelbook.Worksheets
set objexcelsheet = Objexcelbook.Sheets (1)
4. Save the excel file
ObjexcelBook.saveas Straddr & /TEMP/table.xls
5. Save the excel file
Objexcelbook.save (successfully saved during the test, the page is wrong.)
6. Exit Excel operation
objexcelapp.quit must exit
set objexcelapp = Nothing
3. ASP operation Excel generates data table
1. Insert data within a range
objexcelsheet.range (B3: K3). Value = Array (67, 87, 5, 9, 7, 45, 54, 54, 10)
2. Insert data in a unit grid
objexcelsheet.cells (3,1). Value = Internet Explorerr
3. Select a range
4. Draw thick lines on the left side of the cell
5. Draw thick lines on the right side of the unit grid
6. Draw thick lines on the cell
7. Draw thick lines under the cell
8. Cell setting background color
9. Merge cell grid
10. Insert line
11. Insert column
4. ASP operation Excel generates chart diagram
1. Create a chart diagram
objexcelapp.charts.add
2. Set the type of chart diagram
objexcelapp.activeChart.charttype = 97
Note: two -dimensional folding line diagram, 4; two -dimensional cake chart, 5; two -dimensional column figure, 51
3. Set the title of Chart
objexcelapp.activeChart.hastitle = TRUE
objexcelapp.ActiveChart.charttitle.text = a test chart
4. Set the graphic through the data of the form
objexcelapp.activeChart.Setsourcedata Objexcelsheet.range (a1: k5), 1, 1
5. Set the graphics data directly (recommended)
object
objexcelapp.activeChart.SeriesCollection (1) .name = = 333
objexcelapp.activeChart.seriesCollection (1). Values = = {1,4,5,6,2}
6. Binded chart diagram
objexcelapp.ActiveChart.Location 1
7. Display data table
objexcelapp.activeChart.hasdatatable = TRUE
8. Display legends
objexcelapp.activeChart.datatable.showlegendkey = TRUE
Fifth, the server side Excel file browsing, downloading, and deleting solutions
There are many solutions for browsing. Location.href =, Navigate, Response.ReDirect can be implemented. It is recommended to use the client method, because it gives the server more time to generate excel files.
The realization of download is more troublesome. Use the ready -to -download component on the Internet or customize a component by yourself. It is a better solution. Another method is to operate the Excel component on the client, which is stored on the client by the client to operate the server side Excel file. This method requires the client to open the operation authority of an unsafe ACTIVEX control. Considering that each customer is notified to set the server as a trusted site, it is recommended to use the first method.
Delete the scheme consisting three parts:
A: The Excel file generated by the same user uses the same file name, file name available user ID number or sessionid number, etc. It is confident that no duplicate strings are confident. In this way, the new file is automatically covered with a file.
B: When setting the session_onnd event in the global.asa file, delete the user's Excel temporarily stored file.
C: When the Application_onstart event is presented in the global.asa file, delete all files in the temporary directory.
Note: Suggested directory structure/src code directory/templet template directory/temp temporary storage directory
6. Appendix
The death process of Excel appeared when errors occurred. It was a headache. Adding On Error Resume Next to each file will help improve this situation, because it will persist in the Application.quit regardless of whether the file is wrong or not to ensure that the death process will not be left after each program is executed.
Two points:
1. Other Excel specific operations can be solved by recording macro.
2. The server -side opening SQL enterprise manager will also cause problems.
7. Example
The program code (for alixixi.com) is as follows: