0

I want to import/export the data from MS EXCEL in classic asp. I have done that part. But my problem is when we import and export the data from MS EXCEL we need to install the MS-OFFICE on the server. But my client does not want to install the MS-OFFICE on the server. So is there any to import/export from Excel without installing the MS-OFFICE on the server.

Thanks in advance

Thanks & Regards Jelly

jellysaini
  • 158
  • 5
  • 15

2 Answers2

1

I have done this many times back in the old days ;-) Unfortunately that code cannot be found this quickly. I found this example to import:

<%
Set ExcelConn = Server.CreateObject("ADODB.Connection")
Set ExcelRS = Server.CreateObject("ADODB.Recordset")
ExcelConn.Provider = "Microsoft.Jet.OLEDB.4.0"
ExcelConn.Properties("Extended Properties").Value = "Excel 8.0"
ExcelConn.Open "C:\Sample\Sample.xls"

'get data from sheet
sSQL = "SELECT * FROM Sample$"
set ExcelRS = ExcelConn.Execute(sSQL)

'loop through each record in Excel and write it to access
'might be slow, but will work

Do until ExcelRS.EOF 
myConn.Execute("INSERT INTO Sample_tbl(lname,fname,mi) VALUES ('" & ExcelRS("0") & "', '" & ExcelRS("1") & "','" & ExcelRS("2") & "')")

ExcelRS.MoveNext
Loop

ExcelRS.Close
set ExcelRS = NOTHING
objExcelConn.Close
set ExcelConn = NOTHING
objConnAccess.close
set objConnAccess = NOTHING
%>

And This tiny snippet for export, which pretty much comes down to adding the correct Content Type Heading:

<%@ Language=VBScript %>
<%  Option Explicit

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=sample.xls"
%>
<table>
    <tr>
        <td>Sample</td>
    </tr>
</table>
Hendrik Beenker
  • 1,120
  • 5
  • 17
0

I haven't done it myself, but I don't see why not.

You can use the MS Jet Database engine, which is probably already on your server https://stackoverflow.com/a/16051/882436

Alternatively, you can use this component: http://exceldatareader.codeplex.com/

And make it work via COM interop (so you can use it in classic ASP) like so: http://msdn.microsoft.com/en-us/library/zsfww439(v=vs.71).aspx

HTH

Community
  • 1
  • 1
Tom
  • 1,977
  • 1
  • 20
  • 19
  • This is .net. I am finding the solution in classic asp. – jellysaini May 24 '12 at 07:03
  • @jellysaini -- yes, you need to adapt the code to work with classic asp. With the OLEDB solution, use classic ADO to connect to an excel file. I'm sure there's plenty of other examples if you google for it. With the excel data reader, you need to adapt it to COM as described in link #3. – Tom May 24 '12 at 16:57