Formatting Columns in Text File (StreamWriter for VB.NET)

Ok, i need to format columns in a simple text file that is then sent to a PrintPreviewDialog ...but my columns will not line up.  I wrote a custom 'spacer' ... then I tried the StreamWriter's built in formatting ... it WILL NOT line up.  The current code is below, and the output.

Dim TempFile As New System.IO.StreamWriter("temp")
        TempFile.WriteLine("Customer: " & CustomerName)
        TempFile.WriteLine("Order #: " & OrderNumber)
        TempFile.WriteLine("{0,15}{1,15}{2,15}{3,15}{4,15}{5,15}", "Quantity", "Size", "Monogram", "Pocket", "Price Each", "Total Price")

        For I As Integer = 0 To 140


        For Each Order As OrderEntry In OrderEntries

            If Order.Quantity <> 0 Then

                TempFile.Write("{0,15}", CStr(Order.Quantity))
                TempFile.Write("{0,15}", Order.Size)

                If Order.Monogram Then
                    TempFile.Write("{0,15}", "YES")
                    TempFile.Write("{0,15}", "NO")
                End If

                If Order.Pocket Then
                    TempFile.Write("{0,15}", "YES")
                    TempFile.Write("{0,15}", "NO")
                End If

                TempFile.Write("{0,15}", Order.Price.ToString("C"))
                TempFile.WriteLine("{0,15}", Order.ExtendedPrice.ToString("C"))
            End If


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It is virtually impossible to line things up attractively in this way due to different spacing in font sizes etc.

The only way you could do it is to use a fixed width font such as courier new in your viewer.

However, this is likely to be ugly.

The invoice you show is clearly doing something a biit more sophistiated than displaying a raw text file since it includes underlining.

I would suggest you look at writing to a delimited file or XML and then put the layout logic for this in whatever is drawing your invoice.   You could implement precise columns there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jigdogAuthor Commented:
Luckily, as this is not a professional/paid project, attractiveness is not an issue.  Your explanation is what I needed, and 'Courier New' allowed me to get the alignment correct.  Thanks so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.