0

I have to make some Word Integration as part of an exam project. My problem is that I am rather new to Microsoft Word integration in C#. I have the Assemblies I need, and I got everything set-up ready to write code pretty much. The document will be generated from scratch.

But I am just starring at the blinking cursor, not really knowing how to start.

I have to take a StringBuilder (which should hold stuff like escape characters for new lines, perhaps italic bold, etc kind of formatting as well.) The StringBuilder will be given from another part of the application written by my friend.

Would you suggest that this is delivered in another form than a StringBuilder Object?

And where should I start with all this? It's a bit overwhelming.

Thanks

OmniOwl
  • 5,477
  • 17
  • 67
  • 116
  • It is not clear what kind of integration are you talking about. You need to write a Word document from scratch or you need just to open a word document, fill some parts of a document and save the doc back to disk? – Steve Apr 18 '13 at 09:21
  • The first option. I'll add it to the question. – OmniOwl Apr 18 '13 at 09:23
  • check this one: http://stackoverflow.com/questions/10412/how-can-a-word-document-be-created-in-c after you have created the document in any of the ways suggested in the answers, populating it with your string builder content is a simple task. – Davide Piras Apr 18 '13 at 09:29
  • Do you need to create new word document in C#...type text...add shapes and images etc??? – Rohit Apr 18 '13 at 09:33
  • @Kyle Not shapes and images. Just text. But might have to do some footer/header stuff too. – OmniOwl Apr 18 '13 at 09:40

1 Answers1

0

Try this

you need to add Microsoft.Office.Interop.Word reference

Word._Application oWord;
Word._Document oDoc;
object oMissing = Type.Missing;
oWord = new Word.Application();
oWord.Visible = true;

//Add Blank sheet to Word App
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); 

oWord.Selection.TypeText("Write your text here");
//FOrmatting your text
oWord.Selection.Font.Size = 8;
oWord.Selection.Font.Name = "Zurich BT";
oWord.Selection.Font.Italic = 1
oWord.Selection.Font.Bold = 1

oDoc.Content.Application.ActiveWindow.ActivePane.View.SeekView = //Havent tested the  
                                                             //header and footer part
Word.WdSeekView.wdSeekCurrentPageFooter;
oDoc.Content.Application.Selection.TypeText(“Martens”);

I guess this might be what you are looking for

Rohit
  • 10,056
  • 7
  • 50
  • 82
  • That works perfectly! Thanks. This gave me a nice insight into generating the Doc. The footer part worked too. – OmniOwl Apr 18 '13 at 10:40