An instance of creating an Excel file dynamically with a component

Source: Internet
Author: User
Tags range
excel| Create | Dynamic An instance of creating an Excel file dynamically with a component

There is an Excel article in the essence that is dynamically created in ASP, but in fact we will find that if we use set Myexcelchart = Server in ASP. CreateObject ("Excel.Sheet") is not workable. If you do this, you receive the following error message:
Only InProc server components should is used. If you are want to use localserver components, you must set the AspAllowOutOfProcComponents metabase. Please consult the "Help" file for important considerations The details of this error message you can see:
Http://msdn.microsoft.com/workshop/server/components/outproc.asp
Therefore, in order to automatically generate Excel files on the server or must be implemented through the component (personal opinion, if you have a better method please tell me:-)).
Design environment: VB6.0
Operating Environment: NT4.0 (SP5) +iis4.0+mts
1. Create a new DLL project. Project name is P_excel, class name is C_excel
2. Select "Microsoft Excel 9 Object Library" in "Project"-> "References".
3. Code
Option Explicit

Dim oexcel as Excel.Application
Dim osheet as Excel.Worksheet
Dim Otitle as Excel.Range

Public Sub Createexcel ()
Set oexcel = New Excel.Application
oExcel.Visible = False
OExcel.Workbooks.Add
Set osheet = oexcel.workbooks (1). Worksheets ("Sheet1")
Osheet.activate
Set otitle = Osheet.range ("A1")
Otitle.value = "Excel Title"
OTitle.Font.Bold =-1
OTitle.Font.Size = 18
OTitle.Font.Name = "Arial"
Osheet.saveas "Allen.xls"
oExcel.Quit
Set oexcel = Nothing
End Sub
4. Compile and generate P_excel.dll
5. Use MTS to register P_excel.dll
6.ASP file code and set the virtual directory where you want to generate Excel files to write permissions to the user in IIS.
Excel.asp
<%
Set Myexcel=server.createobject ("P_excel.c_excel")
Myexcel.createexcel
Set myexcel=nothing
%>
7. Run excel.asp, we can find the generated Excel file in the related directory.

Recommendations for improvement:
1. Adding properties to the P_excel.dll (Range,value) enables you to dynamically generate an Excel document from the records returned from a query in the database.
2. Increase the email function to automatically send the generated Excel file to the relevant users.

If you have any other suggestions, please let me know.:-)




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.