Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating and Editing word document by using a program

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?

like image 505
killerCoder Avatar asked Feb 23 '23 15:02

killerCoder


2 Answers

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

C# tutorial

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

like image 83
sealz Avatar answered Mar 08 '23 06:03

sealz


Dont know about c# but Java has the Apache POI project which supports reading/writing word documents.

http://poi.apache.org/hwpf/index.html

like image 44
Kal Avatar answered Mar 08 '23 06:03

Kal