Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to Excel

Status
Not open for further replies.

5ilver5aracen

Programmer
Oct 24, 2004
32
0
0
GB
Hi
I need to copy certain records from an Access DB to an Excel Spreadsheet for a client to download. I can connect to the SS using ADO but thats as far as I have got. I can't seem to write any data to the SS. I have a feeling that I haven't set the sheet up properly. I don't really understand Named Ranges. Could someone point me in the right direction please? Many thanks in advance.
 
if all the data is to go on one worksheet, why not just write a text file, tabbed delimited and save as a csv file?
 
try something like this

where conn is your connection string

<%
Response.ContentType = "application/vnd.ms-excel"



Set rs=conn.execute"select * from tblname")

totalfields=rs.fields.count -1
rows = rs.GetRows()

%>
<TABLE BORDER=1>
<TR>
<%
For i = 0 to totalfields
%>
<TD><B><% = rs(i).Name %></B></TD>
<% Next %>
</TR>
<%
firstrec = LBound(rows, 2)
lastrec = UBound(rows, 2)
firstfield = LBound(rows, 1)
lastfield = UBound(rows, 1)


For r = firstrec To lastrec
%>
<TR>
<% For c = firstfield To lastfield %>
<TD VALIGN=TOP><% = rows(c, r) %></TD>
<% Next %>
</TR>
<%
next


rs.close
conn.close
set rs = nothing
set conn = nothing
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top