• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

syntax WriteLine on generating file

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?
0
sasha85
Asked:
sasha85
  • 4
  • 3
  • 3
  • +2
4 Solutions
 
GawaiCommented:
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

0
 
Ashish PatelCommented:
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

0
 
GawaiCommented:
wow nice one but still there is repetation of htmlstr and file size also increased 792 bytes to 913 bytes
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GawaiCommented:
sory type i mean repetition  
0
 
sasha85Author Commented:
still...it come's with code on the side...i understand that there is no other way then...
0
 
Ashish PatelCommented:
Right sasha85 Other than these options there are no work around for saving files.
0
 
sasha85Author Commented:
i am going to rewrite 142 rows then...it will be very ugly...my notepad wont like this...:)
0
 
Ashish PatelCommented:
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
0
 
PaulHewsCommented:
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?
0
 
WylkellCommented:
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...
0
 
sasha85Author 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("
?
0
 
sasha85Author Commented:
how can i put asp code inside the act.WriteLine?
0
 
WylkellCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now