We help IT Professionals succeed at work.

syntax WriteLine on generating file

Medium Priority
341 Views
Last Modified: 2012-05-05
i'm need to create xls file:

Dim file_being_created,fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
file_being_created= Server.MapPath("text.xls")
Set act = fso.CreateTextFile(file_being_created, true)
 
 
act.WriteLine("<html><body>")
act.WriteLine("<table border=""1"">")
act.WriteLine("<tr>")
act.WriteLine("<th nowrap>State</th>")
act.WriteLine("<th nowrap>Abbreviaton</th>")
act.WriteLine("</tr>")
 
 
act.WriteLine("<tr>")
act.WriteLine("<td align=""right"">California</td>" )
act.WriteLine("<td align=""right"">CA</td>" )
act.WriteLine("</tr>")
 
act.WriteLine("<tr>")
act.WriteLine("<td align=""right"">Ohio</td>" )
act.WriteLine("<td align=""right"">OH</td>" )
act.WriteLine("</tr>")
 
 
act.WriteLine("</table></body></html>")
 
' close the object (excel)
act.close


but my real report code is written out of <% %>
means look like html...and when come a plaxe for asp i just open the <%
and closing it again...

is there a way to avoid rewriting all the code into the  
act.WriteLine("???")

can't i jus open is some how one time  
act.WriteLine("
///
and close it after all my code endes?
Comment
Watch Question

Commented:
no but u can use this way offcourse


act.WriteLine("<html><body><table border=""1""><tr><th nowrap>State</th><th nowrap>Abbreviaton</th></tr>")

Open in new window

Try this


Dim file_being_created,fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
file_being_created= Server.MapPath("text.xls")
Set act = fso.CreateTextFile(file_being_created, true)
Dim htmlstr 
 
htmlstr = ""
htmlstr = htmlstr & "<html><body>"
htmlstr = htmlstr & "<table border=""1"">"
htmlstr = htmlstr & "<tr>"
htmlstr = htmlstr & "<th nowrap>State</th>"
htmlstr = htmlstr & "<th nowrap>Abbreviaton</th>"
htmlstr = htmlstr & "</tr>"
 
 
htmlstr = htmlstr & "<tr>"
htmlstr = htmlstr & "<td align=""right"">California</td>" 
htmlstr = htmlstr & "<td align=""right"">CA</td>" 
htmlstr = htmlstr & "</tr>"
 
htmlstr = htmlstr & "<tr>"
htmlstr = htmlstr & "<td align=""right"">Ohio</td>" 
htmlstr = htmlstr & "<td align=""right"">OH</td>"
htmlstr = htmlstr & "</tr>"
 
 
htmlstr = htmlstr & "</table></body></html>"
 
act.WriteLine(htmlstr)
' close the object (excel)
act.close

Open in new window

Commented:
wow nice one but still there is repetation of htmlstr and file size also increased 792 bytes to 913 bytes

Commented:
sory type i mean repetition  

Author

Commented:
still...it come's with code on the side...i understand that there is no other way then...
Right sasha85 Other than these options there are no work around for saving files.

Author

Commented:
i am going to rewrite 142 rows then...it will be very ugly...my notepad wont like this...:)
can you paste your 142 rows here? May be i cna help you get it quickly and also will show you how to do that very quickly

Commented:
It's unclear from the question why you are saving this text file.  It only really makes sense if it contains dynamic data.  What is the source of the data?
Commented:
If your looking to take some raw text and wrap it around HTML or XML tags via vbscript, your only other option (beyond mass copy/paste's inside notepad) would probably be to write your code to take a text file and put your tags around it.  it sorta depends on what your trying to accomplish in the end.

If your just trying to take some raw text and throw it into HTML with pretty fonts and tables and the like, then your probably better off doing this in MS Office.  Unless this is something your trying to do that needs to be run daily or something...

Author

Commented:
i got it all going with office...but i bump into a problem that i havn't thought about..
how can i insert asp codes and functions...if else for while...into act.WriteLine("
?

Author

Commented:
how can i put asp code inside the act.WriteLine?

Commented:
I would think you should still be able to put asp code inside of your writeline statement, as long as it's all encapsulated by the double quotes and that you watch for double quotes within the strings.  the script will treat it like a series of strings, which is what you would want.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.