1

I've been searching on ways to create letters using a C# Windows Form application in Visual Studio based on information from a local SQL server. I've seen some other topics but each answer seems to be really different.

My knowledge is pretty basic about this and wouldn't mind a step in the right direction. Is it actually possible? is there a better solution rather than creating word documents?

I only really need to be able to create a word document which has some text and and tables is this possible?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
r0bb077
  • 732
  • 2
  • 11
  • 33
  • 4
    Did you come across http://stackoverflow.com/questions/10412/how-can-a-word-document-be-created-in-c in your travels? There are some very good suggestions there. – dash Mar 29 '12 at 21:31
  • There are, as you've noticed, many approaches possible. However, the starting point it to know if you want to do it for Word 2007 or an earlier version. (and if 2007 or later, do you want it as a .doc or .docx file?) – David Mar 29 '12 at 21:32
  • As mentioned in the answer linked above, OpemXML is the way to go. Check it out: http://msdn.microsoft.com/en-us/office/bb265236 – Sorax Mar 29 '12 at 21:38
  • Thanks for the help guys, I'm using DocX and it's going pretty well so thanks again! – r0bb077 Mar 30 '12 at 00:11

2 Answers2

2
  1. If you are creating a document of same kind with different data then use a Word template (.dotx) and use content controls or bookmarks in the document.

Advantage: Saves your time in manipulating with formatting and alignment in the document

  1. Then use Open XML to just replace your content controls or bookmarks with the values.

Advantage: You dont need Word Interop assemblies to be deployed. Faster and recommended by Microsoft.

Kiru
  • 3,489
  • 1
  • 25
  • 46
0

Depending on your needs, you could either simply copy a pre-existing file, or if you need to modify the document from code, you can use Microsoft Office Automation. (see C# office 2010 automation)

Community
  • 1
  • 1
Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80