Reputation: 407
I was wondering if it is possible to create a Microsoft Word Document programmatically (through Java, C#, or another language). Is it also possible to do things like adding text or changing the font?
I know that we can start other programs from the command prompt, but what I want to do is to create the document programmatically without using the UI of Microsoft Word.
Can this be done?
Upvotes: 5
Views: 3911
Reputation: 1424
You may try Aspose.Words for .NET or Aspose.Words for Java. These components can work with .NET or Java programming languages respectively, and allow you to create or edit Word documents. Moreover, you do not need to install Microsoft Office on the machine your code is running on.
Disclosure: I work as developer evangelist at Aspose.
Upvotes: 1
Reputation: 5408
in C# Import the COM reference Microsoft Word Object Library
using Microsoft.Office.Interop.Word;
You can then set variables for paragraphs, tables, etc
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
I am unfamiliar how to do it in JAVA but I am sure it is possible
It can also be done in VB.net (naturally!) Tutorial
Upvotes: 4
Reputation: 41142
It depends on the Word document version you are targeting. It can be Word 95 (classical Word), Open XML, RTF, etc.
RTF might be the simplest to handle, Open XML is normalized so the docs are available, .doc format has been reverse engineered, so it is known, and I think there is indeed a Java library to handle it.
The exact answer depends on your exact needs...
Upvotes: 1
Reputation: 3720
Though I don't understand the real purpose of doing that, the answer is YES.
Not only the word, any microsoft document for that matter. Usually every little functionality in office are made as COM/COM+ component. You will be able to have access to most of them from other programming languages. You'll be accessing them as COM APIs.
Microsoft documentation pretty much would explain on what APIs are available and how to program them.
Upvotes: 0
Reputation: 12119
You can use Open XML SDK 2.0 to programmatically create a word document.
Upvotes: 1
Reputation: 24910
Dont know about c# but Java has the Apache POI project which supports reading/writing word documents.
http://poi.apache.org/hwpf/index.html
Upvotes: 2