Open XML SDK 2.7 for .NET Core release

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.

image

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) :


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();
}
}
}
}

and the project.json file :


{
"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"
}
}
}

2 réflexions au sujet de « Open XML SDK 2.7 for .NET Core release »

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *