For people who play a lot with Office documents, and as a SharePoint developer (app, migration tools, etc) this is a day as usual, the Open XML SDK is a powerful companion.
The latest update of this nice SDK was released a year ago with a great upgrade, thanks to Eric White which replaced the System.IO.Packaging implementation. Last week was released the official SDK 2.7 which now moved to using Windows Base and supports .NET Standard 1.3, so it now works with .NET Core and .NET CLI.
And you know what ?!? It works like a charm !
Here is a sample code to generate a Word Document from a .NET Core (as well as for any .NET app) :
[code language= »csharp »]
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace CoreTest
{
public class Program
{
public static void Main(string[] args)
{
GenerateHelloOOXMLDocument("test.docx");
}
public static void GenerateHelloOOXMLDocument(string docName)
{
using (WordprocessingDocument package =
WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
{
package.AddMainDocumentPart();
package.MainDocumentPart.Document =
new Document(
new Body(
new Paragraph(
new Run(
new Text("Hello Open XML for .NET Core !")))));
package.MainDocumentPart.Document.Save();
}
}
}
}
[/code]
and the project.json file :
[code]
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"DocumentFormat.OpenXml": "3.0.0-*",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
[/code]