|
|||||||
| ASP Discussion and technical support for using and deploying Active Server Pages. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
reading an excel file
Hi
I have an excel document and I am trying to read it using asp or php but to no good. could somebody give me some suggestions for that. I tried the following code but it needs that the data in a column either be a number or text and not both or I get errors.PHP Code:
|
|
#2
|
|||
|
|||
|
your problems are caused by the excel driver guessing what the datatype of the column is. it examines the first 8 rows of each column and uses the majority datatype for all the rows, all the rows with other types come back as nulls.
here's an example of it working. you need to change your connection string to get it going basically. its the addition of "IMEX=1" that makes it work with different datatypes in the same column. Code:
<html>
<body>
<%
writeExcelData()
%>
</body>
</html>
<%
function writeExcelData()
Dim rs,sql,i
sql = "SELECT * FROM [TestData$];"
if runsql(sql,rs) then
%>
<table border="1">
<thead>
<tr>
<%
For I = 0 To rs.Fields.Count - 1
Response.Write "<th>" & rs.Fields.Item(I).Name & "</th>"
Next
%>
</tr>
</thead>
<tbody>
<%
Do While Not rs.EOF
Response.Write "<tr>"
For I = 0 To rs.Fields.Count - 1
Response.Write "<td>" & rs.Fields.Item(I).Value & "</td>"
Next
Response.Write "</tr>"
rs.MoveNext
Loop
%>
</tbody>
</table>
<%
rs.Close
end if
Set rs = Nothing
end function
function runSQL(SQL,rs)
on error resume next
dim myrs
set myRs = createobject("ADODB.recordset")
myRs.Open SQL,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("x1_data.xls") & ";Extended Properties=""Excel 8.0;IMEX=1;""", 1, 3
set rs = myRs
if err then
runSQL = false
response.write err.description
else
runSQL = true
end if
end function
%>
|
|
#3
|
||||
|
||||
|
And don't know if this might help at all:
Connection String Home Page http://www.carlprothman.net/Default.aspx?tabid=81
__________________
J. Paul Schmidt www.Bullschmidt.com - Freelance Web and Database Developer www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips |
|
#4
|
|||
|
|||
|
First of all there are a lot of tools which work with excel files,and I know one of it-Excel file repair tool,as far as I know it is free,software keep several copies of your workbook in different places, you can avoid the loss of information as a result of data corruption or virus attack,ecover corrupted information in Microsoft Excel format, please download Excel files repairing tools right now and try to repair your Excel files with MS Excel repair tool,can open and recover damaged documents in Microsoft Excel format,sove next problems on example if your document was seriously damaged, for example due to HDD failure, MS Excel repairing tool will show these areas to be pretty large,very good solution to repair Excel files.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|