Output an Excel file instance in an ASP program

Source: Internet
Author: User
Tags command line range access database

One way to take advantage of Excel in ASP is to link the Excel file as a database, and then do something similar to an Access database operation. However, this method is not always useful, and Excel is not a relational database. For a fixed format, there are complex cell merges in this format, border line style, there are patterns, there are formulas between the cells and so on, I think the most easy to understand is to open a template in the background of the file has been set up, and then insert the data where needed, save, output ...

The method mentioned here is to create an Excel object directly, which makes it easier to perform various operations on the Excel document in the background.

The point that the server side must also set is the operation permissions of the COM component. Type "DCOMCNFG" at the command line, then go to the COM component Configuration interface, select MicrosoftExcel, click the Properties button, and select all three single options to customize, and edit everyone to join all permissions. Restart the server when the save is complete.

It is important that other computers will not be able to complete the creation of Excel objects without setting them up.

But this method also has a drawback, in my actual operation, if the server has opened Excel file, and then execute the same file, there will be errors, temporarily still do not understand why, there may be some places did not set up well.

In addition, the instance code in the article referenced above is not fully formatted, many of these lines and space format is not accurate, if the code is complete, as long as the copy code, you can run successfully, and then slowly research changes, it is easy to get started, now put the revised code as follows (delete the part of the drawing diagram):

<%
On Error Resume Next
Straddr=server.mappath (".")
Set Objexcelapp=createobject ("Excel.Application")
Objexcelapp.displayalerts=false
Objexcelapp.application.visible=false
ObjExcelApp.WorkBooks.Open (straddr& "\templet\null.xls")
Set Objexcelbook=objexcelapp.activeworkbook
Set Objexcelsheets=objexcelbook.worksheets
Set Objexcelsheet=objexcelbook.sheets (1)
Objexcelsheet.range ("B2:k2"). Value=array ("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7")
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= "InternetExplorer"
Objexcelsheet.cells (4,1). Value= "Netscape"
Objexcelsheet.cells (5,1). Value= "Other"
Objexcelsheet.range ("B2:k5"). Select
SaveAs (straddr& "\temp\excel.xls")
Objexcelapp.quit
Set objexcelapp=nothing
%>
<! Doctypehtmlpublic "-//w3c//dtdhtml4.0transitional//en" >
<HTML>
<HEAD>
<TITLE>NewDocument</TITLE>
<metaname= "generator" content= "MicrosoftFrontPage5.0" >
<metaname= "Author" content= "" >
<metaname= "Keywords" content= "" >
<metaname= "Description" content= "" >
</HEAD>
<BODY>
</BODY>
</HTML>

Related Article

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.