简体   繁体   中英

Programmatically creating word document via open office

I am looking to do a mail merge in Word using their interop libraries. However having issues getting word installed on my developer machine due to IT at work.

Is it possible to programmatically interact with OpenOffice as an alternative? Ideally in C#

There are a handful of third-party C# libraries that can do this, such as OfficeWriter (who I work for) and others.

Using the library and your Word document you simply call a method, passing in the data to be mail merged. The API is usually pretty strait forward:

using (WordTemplate wordTemplate = new WordTemplate())
{
    wordTemplate.Open("YourFilePath.docx");

    // yourData is a a DataTable in this case, 
    // but SetDataSource has many overloads
    wordTemplate.SetDataSource(yourData);

    wordTemplate.Process();

    wordTemplate.Save("OutputFilePath.docx");
}

Microsoft provides a development platform for handling Word (.docx), Excel (.xlsx) and PowerPoint (.pptx) files without installing the softwares. The feature is avaliable like a SDK.

Look this: http://msdn.microsoft.com/en-us/office/bb265236.aspx

If you wanna more help, please try something and post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM