ASP operation Excel technology summary

xiaoxiao2021-03-06  76

ASP Operation Excel Technical Summary Directory First, Environment Configuration II, ASP's Basic Operation of Excel Third, ASP Operation Excel Generates Data Table 4, ASP Operation Excel Generates Chart Figure 5 1. Environmental Configuration Server-side Environment Configuration Views on the reference, Microsoft's series of configurations should be done, namely: 1. Win9X PWS Office2. Win2000 Professional Pws Office3. Win2000 Server IIS Office is currently the successful environment of the author. The version of Office does not have special requirements, take into account the uncertainty and compatibility features of client configuration, and it is recommended that the server-side Office version should not be too high to prevent the client from being downloaded after downloading. The server-side environment configuration has two accidental discovery: 1. The author develops the machine's original WPS2002, and the results of the Excel object have always been issued, and after uninstalling the WPS2002, the error disappears. 2. The author develops ASP code likes to use FrontPage, and the results are found to find that if the FrontPage is open (server-side), the object creates unstable phenomenon, and it is time to succeed. After the expansion, found that the Office series software is running in the server side, and the creation of the Excel object is difficult to succeed. The server side must also set is the operation permission of the COM component. Type "DCMCNFG" on the command line, enter the COM component configuration interface. After selecting Microsoft Excel, click the Properties button to select a custom, and the EVERYONE is added to all permissions. Restart the server after saving. The client's environmental configuration did not find anything particularly parallel, as long as office and IE can be installed, the version is generally like. Two, ASP basic operation of Excel 1, the Excel object the establishment set objExcelApp = CreateObject ( "Excel.Application") objExcelApp.DisplayAlerts = false does not display a warning objExcelApp.Application.Visible = false display interface 2, the new Excel file objExcelApp.WorkBooks .addset objExcelBook = objExcelApp.ActiveWorkBookset objExcelSheets = objExcelBook.Worksheetsset objExcelSheet = objExcelBook.Sheets (1) 3, has been read Excel files strAddr = Server.MapPath ( ".") objExcelApp.WorkBooks.Open (strAddr & "/ Templet / Table.xls ") set objExcelBook = objExcelApp.ActiveWorkBookset objExcelSheets = objExcelBook.Worksheetsset objExcelSheet = objExcelBook.Sheets (1) 4, save Excel files objExcelBook.SaveAs strAddr &" /Temp/Table.xls"5, save Excel files objExcelBook.Save (The author is saved during testing, the page is wrong.

6, exit Excel Operation Objexcelapp.quit must exit set objectExcelapp = Nothing 3, ASP operation Excel generates data table 1, insert data Objexcelsheet.Range within a range ("b3: k3"). Value = array ("67" , "87", "5", "9", "7", "45", "45", "54", "54", "10") 2, inserted data Objexcelsheet.cells in a cell. 3, 1) .Value = "Internet Explorer" 3, select one range 4, the left painted thick line 5 left, the unit grid is the thick line 6, the cells are painted on the cell 7, the cells can be used at the lower edge 8, the cell setting Background color 9, combined unit 10, insert line 11, insert column four, ASP operation Excel generation chart Figure 1, create a chart map Objexcelapp.Charts.adD2, set Chart map Objexcelapp.activechart.ChartType = 97 Note: 2D Pacing chart, 4; two-dimensional cake diagram, 5; two-dimensional column, 513, set Chart diagram title Objexcelapp.activeChart.hastitle = trueObjexcelapp.actiVhart.Charttitle.text = "a test chart" 4, set by Table Data Artwork objExcelApp.ActiveChart.SetSourceData objExcelSheet.Range ( "A1: k5"), 15, the pattern data set directly (recommended) objExcelApp.ActiveChart.SeriesCollection.NewSeriesobjExcelApp.ActiveChart.SeriesCollection (1) .Name = "=" "333 "" "Object.SeriesCollection (1) .values ​​=" = {1, 4, 5, 6, 2} "6, binding chart map Objexcelapp.activeChart.Location 17, display data table Objexcelapp.activeChart.hasDataTable = True8, display legend objexcelapp.activechart.DataTable.showleg Endkey = true 5, server-side Excel file browsing, downloading, deleting solution browsing solutions, "location.href =", "navigate", "response.redirect" can be implemented, recommended for client-side methods, reason is given The server generates an Excel file for more time. The implementation of the download is troublesome. Downloading components on an online homeD server or custom development a component is a better solution. Another method is to operate the Excel component at the client, and save the server-side EXCEL file to the client. This approach requires the client to open an operation permission of unsafe ActiveX controls, considering that each customer sets the server set to trusted sites, it is more expensive to use the first method. The delete scheme consists of three parts: A: The excel file generated by the same user is confident that the user ID number or sessionID number can be confidently not repeated string with the same file name, file name. This automatically overrides the previous file when the new file is generated.

B: Set the SESSION_ONEND event in the global.asa file to delete the user's Excel temporary file. C: When setting the Application_onstart event in the global.asa file, delete all the files in the temporary directory. Note: Recommended Directory Structure / SRC Code Directory / Templet Template Directory / Temp Speech Directory Sixth, the appendix is ​​a very headache. Plus "On Error Resume next" before each file will help improve this, because it will execute it to "Application.quit" regardless of whether the file generates an error, guarantees that each program is not left process. Supplement two points: 1, other Excel specific operations can be solved by recording macros. 2, the server-side open SQL Enterprise Manager will also generate problems.

Seven examples of <% On Error Resume NextstrAddr = Server.MapPath ( ".") Set objExcelApp = CreateObject ( "Excel.Application") objExcelApp.DisplayAlerts = falseobjExcelApp.Application.Visible = falseobjExcelApp.WorkBooks.Open (strAddr & "/ Templet /Null.xls")set objExcelBook = objExcelApp.ActiveWorkBookset objExcelSheets = objExcelBook.Worksheetsset objExcelSheet = objExcelBook.Sheets (1) objExcelSheet.Range. ( "B2: k2") Value = Array ( "Week1", "Week2", "Week3 "," Week4 "," Week5 "," Week6 "," Week7 "," Week8 "," Week ") Objexcelsheet.Range (" B3: K3 "). Value = Array (" 67 "," 87 "," 5 "," 9 "," 7 "," 45 "," 45 "," 54 "," 54 "," 10 ") Objexcelsheet.Range (" B4: K4 "). Value = array ( "10", "10", "8", "27", "33", "37", "50", "54", "10", "10") Objexcelsheet.Range ("B5: K5") .Value = array ("23", "3", "86", "64", "60", "18", "5", "1", "36", "80") Objexcelsheet.cells (3 1) .Value = "Internet Explorer" objects (4, 1) .Value = "netscape" objectsheet.cells (5, 1) .value = "帖子 j"). SelectobjexceLApp .CHARTS.ADDObjexcelapp.acti veChart.ChartType = 97objExcelApp.ActiveChart.BarShape = 3objExcelApp.ActiveChart.HasTitle = TrueobjExcelApp.ActiveChart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"

转载请注明原文地址:https://www.9cbs.com/read-108921.html

New Post(0)