Good day,
I have been searching for a way to format output using writeline/write (streamwriter)
using RTF tags and wondering if there is a syntax for this, if it exists. I have not
been able to find a resource which clearly explains how to “pretty” up output sent to a
file.
The reason why I am asking is because I want to “print” results from my program into
a file that, at the very least, would be centered, tabbed and even bolded where possible
without requiring the user to go and futz with it. I think I saw that Crystal Reports
won’t work with VB 2010 Express and, quite frankly, just want to create a file with
output.
The problem I am having is how I can make output look less like writeline did it
(you know, writeliney-ish) and more like someone took the time to make writeline
look like it did something awesome.
Here’s some code to show you what I’m trying to do:
sw.Write(" RATE QUOTATION ")
sw.WriteLine(" ")
sw.WriteLine(" ")
sw.WriteLine(mycompanyname)
sw.WriteLine(mycompanyaddress1 + ControlChars.Tab + "Phone:", companyphone)
sw.WriteLine(mycompanyaddress3 + ControlChars.Tab + "Fax:", companyfax)
sw.WriteLine(cityname, stateprovince, zippostal)
sw.WriteLine("Visit us online at:", websiteaddress)
sw.WriteLine(" ")
sw.WriteLine("Quoted by:", contactname + " " + "E-mail:", contactemail)
sw.Write("Date: ")
sw.WriteLine(DateTime.Now)
sw.WriteLine(" ")
sw.WriteLine(("Customer Name:" + " " + quotename.Text), "Company:" + " " + quotecompany.Text + " " + "Customer E-mail:" + " " + quoteemail.Text)
sw.WriteLine(("Phone:" + " " + quotephone.Text + ControlChars.Tab + "Fax:" + " " + quotefax.Text))
sw.WriteLine(" ")
sw.WriteLine("Shipment Details:")
Is there a way to control writeline in such a way that you can create an RTF via streamwriter and specify formatting tags, like centering and bold, etc? I’m trying to think of a way so that the RTF header information is created when streamwriter starts it’s business and prints what I want out. I don’t think there’s an elegant way to create a PDF either so I’m kind of opting for old school output for now.
Thanks in advance!
As promised, started playing with some code and thought I’d share it, although I’m still trying to figure out why vbNewLine doesn’t work. :/
Originally, I was trying to use streamwriter to embed RTF codes, like (\rtf1) and (\b) etc..but these do not work within writeline statements that I tried, such as:
writeline(“\b This is in bold \b0”)
So by pretending to have a richtext box (rtb), you can create a file that will allow font formatting and other text formatting (albeit still trying to figure out a few things lol),
which may be an alternative to streamwriter if you care about how output appears in a file.
Public Class Form1
End Class
I wanted to control the font and alignment and this seems to do the trick, although I’m trying to sort out using “tab” position and line feeds. I see that I can align left, center and right. Anyway, I hope this helps someone who might otherwise want a quick way to make a document where they can control the font.
Thanks!