Using ASP to transfer HTML format to Excel

Source: Internet
Author: User

So far, there are several ways to use ASP technology to create Excel data tables, and you can also use server-side Excel 8.0 VBA components to build spreadsheets. However, in some cases the server may not be able to handle the amount of information involved or be unable to assume the resulting workload, so you have to sacrifice some of the processing performance provided to the client. This article will focus on the client-side data table processing issues. Excel 97 has some special properties that can handle HTML-formatted data streams just as you do with spreadsheets, and this particular ability is only available in Excel 97 or later, and users need to build similar Excel spreadsheet data streams to handle them more effectively.

So does the browser have a similar function? Internet Explorer (IE) 3.0 or later can display Microsoft Excel worksheets like Excel, provided the client needs to load Excel. If the user opens the IE browser and enters the Excel worksheet file name as Url,ie, the worksheet opens. IE uses the file name extension to identify whether it is a MIME format file and launches the appropriate application, IE converts the file to Application/vnd.ms-excel and starts Excel for the user to view the relevant tabular data when IE processes the Excel MIME format file.

This article discusses how to build an ASP home page that spreads HTML data to an Excel spreadsheet. With this technology, IE browsers can display HTML data tables like Excel. In the following example, the ASP home page launches a component that processes the employee table records stored in Nwind sqlsever 6.5 and displays the table as an HTML table.

Create an HTML table

First set up the ASP home page, add the home page to the Visualinterdev project, the file name is contenttype.asp, as shown in Figure A. Then add the code shown by code A to the home page, and the first line of code can change the mimetype of the page involved to Excelmimetype. The following lines of code will start the component we established earlier to get the data for the Ador record area. The code, as shown in Listinga, loops through the record area and creates an HTML table that includes records for each row in the employee table.

Code A:code for adding new ASP page to Visual InterDev Project

<%@ language=vbscript%>
<%response.contenttype = "application/vnd.ms-excel"%>
<%
Dim Objemployee, RS
set objemployee=server. CreateObject ("Empreport.employee")
Set rs = objemployee.getemployee ()
' Draw a Table
%>
<TABLE>
<tr>
<td><strong><font face= "Size=4>employee
Report</font></strong ></td>
</tr>
<tr>
<td>employee id</td>
<td>first Name</TD
<td>last name</td>
<td>title</td>
</tr>
<%
Do While not Rs.eof
%>
<tr>
<td>
<%=rs ("EmployeeId")%></td>
<td>
<%= RS ("LastName")%></td>
<td>
<%=rs ("FirstName")%></td>
<td>
<%= RS ("Title")%></td>
</tr>
<%
Rs.movenext
Loop
%></table>

When you have finished entering your code, save and browse the home page. The home page is like Figure B. Note that all the rows in the spreadsheet do not have any formatting. When we use the EXCELVBA component to create a work table, we can use VBA to adjust the table. However, it is more difficult to format a table normally using HTML, unless you can easily display and read the data about the HTML table. We can do this with ASP home technology, and we can implement all the features currently supported by MicrosoftExcel, including the SUM function. It should be noted that the work table created using HTML does not include some standard notation, such as <HTML> and <BODY>. When we create an HTML table that swaps data with an Excel worksheet, try not to use the <HTML>,<BODY>,<HEAD> notation in the ASP home page, because Excel worksheets usually don't have the right markings.

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.