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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web form to output to Excel?

Status
Not open for further replies.

marta99

Programmer
Nov 11, 2002
12
US
Hello,

I am looking for a way to create a web form and have the output saved in an Excel database format (comma delineated).

Users will be requesting a free magazine and the fulfillment house wants the output in Excel format.

Any suggestions?

Thanks!
 
Well firstly, Excel format and Comma Delimited (CSV) format are not the same thing.

If they want a CSV file then you simply need to output each "field" followed by a comma and a return at the end of each "record".

If they want an actual Excel file (from which they can make a CSV) then, if you are using ASP you can do something like this at the start of your page

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

Then get your data however you need to

Then output an HTML table containing your data, something like (from a site I built - might not be optimum code as I'm not really an ASP coder!)

Code:
<%
	 'create an HTML table
	 Response.Write("<table border='1'>")
	 
	 'loop through the field names to get the column headings (field names)
		Response.write("<tr>")
	  j=2 'row counter
	  for i = 0 to oRSstickers.Fields.Count -1
		Response.write("<td><b>" & oRSstickers(i).Name & "</b></td>")
	  Next
	  Response.Write("</tr>")

	 'here comes the data!
	 Do while NOT oRSstickers.EOF
		Response.Write("<tr>")
		Response.Write("<td>" & oRSstickers("id") & "</td>")
		Response.Write("<td>" & oRSstickers("date") & "</td>")
		Response.Write("<td>" & oRSstickers("name") & "</td>")
		Response.Write("<td>" & oRSstickers("email") & "</td>")
		Response.Write("<td>" & oRSstickers("telephone") & "</td>")
		Response.Write("</tr>")
	
		oRSstickers.MoveNext
	Loop
	Response.Write("</table>")

%>

You can do a similar thing with PHP although I've not done it (as far as I can recall) and I don't have an example to hand. A quick Google should turn up something.

Foamcow Heavy Industries - Web design and ranting
Buy Languedoc wines in the UK
 
Hi

And if you use Perl look at the Spreadsheet::WriteExcel module. Is incredibly easy too use.

By the way, CSV is just theoretically a list of values separated by comma, like this :
[tt] Don Wilson,Bloodfist[/tt]

Practically the values may contain commas :
[tt] "Wilson, Don",Bloodfist[/tt]

And of course quotation marks too :
[tt] 'Wilson, Don "The Dragon"',Bloodfist[/tt]
[tt] "Wilson, Don \"The Dragon\"",Bloodfist[/tt]
[tt] "Wilson, Don ""The Dragon""",Bloodfist[/tt]

And here you can see the problem : CSV is not a standard format, and softwares could implement the escaping if quotation marks in different ways.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top