"Textwriter sw" Formatting

Asked

Viewed 54 times

0

I am using "Textwriter sw" to send to Word turning the textboxs into doc the problem I need some formatting. How do I set paragraph size, line spacing, etc... The code I’m using to send to Word is similar to the below:

String strtxt22 = textBox7.Text;
String strtxt23 = textBox8.Text;
TextWriter sw = new StreamWriter(@"c:\\Gold Business - Cadastro Funcionário.doc");
sw.WriteLine(strtxt22);
sw.WriteLine(strtxt23);
  • I don’t know the Word file format, but you can’t just send a text. You have to write a binary in the correct format. It is extremely complicated. You will probably prefer to use some library. If it is .docx it’s a little easier, just a little.

  • By the above method transforms the text of the textboxs into doc I already tested here what I would like to know is how to format; paragraph size, space between lines and etc...

  • 1

    Does not transform into the format of doc, turns into rtf. Functioning does not mean that you are right and there is only right and wrong. " worked on my computer in the specific situation I tested" is not an option. I helped in what I could.

1 answer

0

There is a package in Nuget called "Docx". It does exactly what you need.

Code example:

var paraFormat = new Formatting();
paraFormat.FontFamily = new System.Drawing.FontFamily("Calibri");
paraFormat.Size = 10D;

 doc.InsertParagraph(headlineText, false, headLineFormat);
 doc.InsertParagraph(paraOne, false, paraFormat);

Source: Example taken from codeproject

Browser other questions tagged

You are not signed in. Login or sign up in order to post.