PDA

View Full Version : Excel file. How to choose an especific cell to write?


paulafernandes
03-31-2003, 10:13 AM
Hello!

Sometime ago I've posted a question how to create an excel file from ASP. Whammy give me this code and it worked just fine:

<%
Dim fs, f, thefile, Conn, dbquery, rs, linevalue, LeadColumns
thefile = Server.MapPath("yourfilename.csv")
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(thefile, 2, True)
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open 'Put your connection string here
Set rs = Server.CreateObject("ADODB.Recordset")

dbquery = "SELECT * FROM tablename ORDER BY whatever"
Set rs = Conn.Execute(dbquery)

For Each Item in rs.fields
LeadColumns = LeadColumns & """" & Replace(Item.Name,"""","") & ""","
Next
LeadColumns = Left(LeadColumns,Len(LeadColumns)-1)
f.WriteLine(LeadColumns)

Do While NOT rs.EOF
linevalue = "" 'reset linevalue to empty
For Each Item in rs.fields
linevalue = linevalue & """" & Replace(Item.Value,"""","") & ""","
Next
linevalue = Left(linevalue,Len(linevalue)-1)
f.WriteLine(linevalue)
rs.MoveNext
Loop

Set rs = Nothing
Conn.Close
Set Conn = Nothing

Set f = Nothing
Set fs = Nothing
%>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>Download/open the file</title>
</head>
<body>
<div>
<a href="yourfilename.csv">Click here</a> to download/open the file.
</div>
</body>
</html>

But now I have a different form from wich I want to create an excel file, and I have a LOT of information to put on.
So, I want to be able to choose the cell so I can write it on.
With this example, I can only write into cell A1.
How can I do it?....

Thank's
Paula

paulafernandes
04-03-2003, 03:43 PM
Hi!
Here I am again...
No one replied to this post, but I'm still with the same doubt!
Did I put little information?

I would like to know, if this isn't possible to do, what other ways is there to do it?

Thank's
Paula