ASP: import data (image) to excel final ASP operation Excel

Source: Internet
Author: User

I believe there are many useful users. Program Export data to excel. it is convenient to export some text data. There are many optional methods, such as splicing text strings. CVS format (separated by commas and carriage returns, opened in Excel by default). For example, XLS files are treated as data and operated using SQL. what should I do when I need to export image data? This requires the Excel. Application object.

In fact, Excel is used. the application can perform all the operations that the officeexcel software can perform. The function is quite powerful. however, each of us has limited learning energy and cannot be familiar with it. as a result, I used a large number of keywords to search on Baidu and Google, hoping to get some valuable things. however, I did not find the full version. Most of them asked, andCodeIt contains many obvious errors and functional defects. It is worth noting that a large number of sites directly copy others' sites.ArticleAnd it's still a poor article. Hey, don't look for it! Buddha said that I would not go to hell, so I did this job for everyone.

I first found a collection of VBA manuals. Fortunately, it is in chm format. open the vbaexcelxl10.chm in it. Well, it is good. It is indeed a good manual. However, it is not a tutorial, but it is tearful... No way, so I had to watch it. after all, the manual is a manual. It does not involve convenient operations in some details or complete the logical association of each part of the content. after careful analysis, bold predictions, careful thinking, and a large number of tests, the hot pot, the hot pot, the fire sea, it was not easy to achieve it perfectly. now, I want to upload it to web630.net overnight. I just hope that you will remember this site, and I hope that the technical sites will have more original articles to contribute to the development of the Chinese program industry.Copy codeThe Code is as follows: <%
Rem initializes the working environment of excelapplication
Dim excelapp, ebook, esheet
Set excelapp = Createobject ("Excel. application") 'create an Excel Object
Excelapp. displayalerts = false' no warning is displayed
Excelapp. application. Visible = false' the interface is not displayed.

Rem initializes Excel Data
'Excelapp.workbooks.open(server.mappath(appszzz.xls ") 'Open the Excel worksheet and replace the following line
Set ebook = excelapp. workbooks. add' create an Excel worksheet
Set ebook = excelapp. workbooks (1) 'references the first work book
Set esheet = ebook. worksheets (1) 'reference the first Worksheet

Rem Data Import
Dim I, IMG
I = 1
For I = 1 to 5
Esheet. cells (I, 1). value = "Field 1" & I
Esheet. cells (I, 2). value = "Field 2" & I
Esheet. cells (I, 3). value = "Field 3" & I
Esheet. cells (I, 4). Select the 4th cells in row I.
Set img=esheet.pictures.insert(server.mappath(”people.jpg ") 'insert an image in the preceding position and obtain the image reference.
IMG. Top = IMG. Top + 2' adjust the image position, the same below, otherwise it will hold the table edge
IMG. Left = IMG. Left + 2' unit: lbs
Esheet. Rows (I). rowheight = IMG. height + 4' adjust the height of the current row so that it is automatically the same as the Image Height
Next

Rem saves the above work
'Ebook. save' if you want to open an existing Excel file, you can use this line instead of the following line.
Ebook. saveas server.mappath(appszzz.xls ")
Set esheet = nothing
Set ebook = nothing
'Excel app. quit' must exit; otherwise, the Excel process will remain in the operating system.
Set excelapp = nothing
%>

When ASP reads or writes data to exce, Excel is treated as a database and operated using SQL statements. related Articles are available in many places on the Internet. This article is for your reference only as an auxiliary material for ASP to guide data (picture) final edition to excel. Copy code The Code is as follows: <%
Dim Conn, RS, SQL
Sub dbopen ()
Dim DB: db1_server.mappath(”zzz.xls ")
Set conn = server. Createobject ("ADODB. Connection ")
On Error resume next
Conn. Open "provider = Microsoft. Jet. oledb.4.0; extended properties =" "Excel 8.0; HDR = yes" "; Data Source =" & DB
The default value of rem hdr is yes, indicating that the first line is used as the field name, otherwise it is regarded as the content
For excel2007, REM should be: "provider = Microsoft. Ace. oledb.12.0; extended properties = Excel 12.0; Data source=xxx.xlsx ;"
If err. Number <> 0 then
Err. Clear
Response. Write ("Response. End ()
End if
On Error goto 0
End sub
Sub dbclose ()
If isnotblank (conn) then
Conn. Close ()
Set conn = nothing
End if
End sub
Function isnotblank (byref tempvar)
Isblank = true
Select case vartype (tempvar)
Case 'empty & null
Isblank = false
Case 9 'object
If typename (tempvar) = "nothing" or typename (tempvar) = "empty" then
Isblank = false
End if
End select
End Function

call dbopen ()
SQL = "select * from [sheet1 $]" 'Note the table name syntax, $
set rs = Conn. execute (SQL)
while not Rs. EOF
response. write (RS (0) & ",")
response. write (RS (1) & ",")
response. write (RS (2) & "
" & vbcrlf)
Rs. movenext
Wend
Rs. close: Set rs = nothing
call dbclose ()
%>

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.