Lets Learn

Opinion Matters

Posts Tagged ‘Open XML’

Projects on Open XML

Posted by Ankush on March 26, 2012

Guys, 

Are you doing any projects on Open XML and SharePoint and need some help.

Then reach out to me..I would love to look into the issues and see if I can be of any help!!!!

 

Posted in Uncategorized | Tagged: , , , , | 1 Comment »

libOPC version 0.0.1 is released

Posted by Ankush on April 25, 2011

Source: http://blogs.msdn.com/b/dmahugh/archive/2011/04/19/libopc-version-0-0-1-released.aspx

Text taken from above article:

The first release of libOPC, a new API for Open XML development, was published on Codeplex last week. This API is the first open-source cross-platform API for developers working with Open Packaging Convention (OPC) packages as used by Open XML, XPS, and other formats. Full source code is available, and it’s written in portable C99, so can be used on all popular variants of Linux/Unix, Mac OS, Windows, Android, and many other platforms. The API uses other common cross-platform open-source APIs for some of the low-level details, including ZLIB for opening ZIP-compressed packages and libXMLfor parsing the XML streams from the parts in the package.

Historically, there have been two popular .NET APIs for Open XML development: System.IO.Packaging (which first appeared in .NET 3.0) and the Open XML SDK, released in early 2007. There’s also a COM-based native packaging API available for non-.NET Windows developers.

The libOPC API is roughly analogous to System.IO.Packaging, in that it’s focused on the details of OPC and MCE (parts 2 and 3 of IS 29500), but doesn’t provide higher-level abstractions for WordprocessingML, SpreadsheetML or PresentationML (as covered in parts 1 and 4 of IS 29500).  I say “roughly” because libOPC doesn’t yet address some of the things that System.IO.Packaging handles (e.g., digital signatures) but does include some more advanced capabilities not available in System.IO.Packaging, such as the opc_generate functionality described below, which is essentially the same as the document reflector functionality of the Open XML SDK.

The key new feature in libOPC is its cross-platform capabilities. If you’re working on a non-Microsoft platform, or working with embedded systems that have limited OS support for XML and ZIP, you now have a very fast, simple API that you can use to implement Open XML read and write capabilities in your applications. And libOPC is designed from the ground up to be wrapper-friendly, for use from programming languages other than C.

For full read, click on the above link!!

Posted in Open XML SDK | Tagged: , , | Leave a Comment »

Content Controls- A Complete Summary

Posted by Ankush on October 22, 2010

While generating a document from a database, it is very important that how you have designed the document. If you have a very good template then the insertion of the data becomes very easy. Word provides a very nice feature “Content Controls” to make this task easy. This blog post provides a collection of links which you can use .

So what is a Content Control. Here I what MSDN doc says:

Content controls are bounded and potentially labeled regions in a document that serve as containers for specific types of content. Individual content controls can contain content such as dates, lists, or paragraphs of formatted text. In some cases, content controls might remind you of forms. However, they are much more powerful, flexible, and useful because they enable you to create rich, structured blocks of content. Content controls also build on the custom XML support introduced in Microsoft Office Word 2003. Content controls enable you to author templates that insert well-defined blocks into your documents. Content controls enable you to:

• Specify structured regions in a template. Each structured region has its own unique ID so that you can read from and write to it. Examples of types of structured regions (or content controls) are combo boxes, pictures, text blocks, and calendars.

• Determine the behavior of content controls. Each content control takes up a portion of a document and, as the template author, you can specify what each region does. For example, if you want a region of your template to be a calendar, you insert a calendar content control in that area of the document, which automatically determines what that block of content does. Similarly, if you want a section of a template to display an image, create a picture content control in that area. In this way, you can build a template with predefined block types.

• Restrict the content of content controls. Each content control can be restricted, so that it cannot be deleted or edited. This is useful if, for example, you have copyright information in a template that the user should be able to read but not edit. You can also lock a template’s content so that a user does not accidentally delete portions of it. This makes templates more robust than in previous versions.

• Map the contents of a content control to data in a custom XML part that is stored with the document. For example, if you insert a document parts content control that contains a table of stock prices, you can map the table cells to nodes in an XML file that contain the current stock prices. When the prices change, an add-in can programmatically update the attached XML file, which is bound to each cell, and the new, updated prices automatically appear in the table.

The easiest way to create a content control is through the user interface (although you can also create them programmatically). To create a content control through the user interface (UI), select the text that you want to turn into a content control and then choose the content control type you want from the content controls section of the Developer ribbon. This creates a content control around the selected text.

Content Controls are a powerful features when it comes to feeding the data into document in an ASP.NET app. If you have created a document template and content control’s mapping is set then you can just replace one XML file and Word will pick the new data.

So here is the list.

Goal: Get the data from SQL Server and feed the Word document. The application is a Web application.

Solution: Create a Word template with content controls.  Bound them with an XML file. Use Open XML to manipulate the document and change the content of the XML file. The advantage of using content control is, they can be easily bound  to an XML file.

• Create a new Word document, drag few content controls onto the document surface. Create an XML file and create a node for every content control

Data-driven document generation with Word 2007 and the Office XML File Formats: Part 1
http://blogs.msdn.com/erikaehrli/archive/2006/08/11/word2007DataDocumentGenerationPart1.aspx

• There are 2 ways by which you do the mapping [ Nodes <-> Content Control]. Using Code, which is already  explained in the above article. If you would like to use an application, there is sample application available which can help you.

Word 2007 Content Control Toolkit
http://www.codeplex.com/wikipage?ProjectName=dbeOnce this is done, the sample XML file which you created, will be a part of the  document package, so you just need to change the content of the XML nodes and when you will open the document, it will reflect the dynamic data.

• Now you need to use Open XML, get the data from SQL and replace the XML contents it in the document. Following article  explains this[It has the sample code as well]

Data-driven document generation with Word 2007 and the Office XML File Formats: Part 2
http://blogs.msdn.com/erikaehrli/archive/2006/08/11/word2007DataDocumentGenerationPart2.aspxCreting documents by using Open XML Format SDK 2.0 (Part 3 of 3)
http://msdn.microsoft.com/en-us/library/dd469465.aspx#CreateDocswithOpenXMLSDK_TakingAdvantageofBoundContentControlsIf you would like to do this through Open XML SDK 2.0, then following article explains about this.

Creating Data-Bound Content Controls using the Open XML SDK and LINQ to XML
http://blogs.msdn.com/ericwhite/archive/2008/10/19/creating-data-bound-content-controls-using-the-open-xml-sdk-and-linq-to-xml.aspxTaking Advantage of Bound Content Controls
http://blogs.msdn.com/brian_jones/archive/2009/01/05/taking-advantage-of-bound-content-controls.aspx
So basically once the template is created, you can use Open XML SDK and do something like. Here I simply get the xml, delete the old XML file and add the new one.

========
string templatePath = Server.MapPath(“./Templates/ModelTemplate.docx”);
string custXMLFilePath = Server.MapPath(“./CustomXML/Model.xml”);
using (wdDoc = OpenXML.WordprocessingDocument.Open(templatePath, true))
{
OpenXML.MainDocumentPart mainPart = wdDoc.MainDocumentPart;
mainPart.DeleteParts<OpenXML.CustomXmlPart>(mainPart.CustomXmlParts);
XmlDataDocument custXML = new XmlDataDocument();
custXML.Load(custXMLFilePath);
OpenXML.CustomXmlPart custXMLPart = mainPart.AddNewPart<OpenXML.CustomXmlPart>();
using (Stream s = custXMLPart.GetStream(FileMode.Create))
{
custXML.Save(s);
}
}
=========
Inserting Repeating Data Items into a Word 2007 Table by Using the Open XML API
http://msdn.microsoft.com/en-us/library/cc197932.aspxCreating Valid Open XML Documents by Using the Validation Tools in the Open XML Format SDK
http://msdn.microsoft.com/en-us/library/dd633612.aspx

Let me know what you think about this::

Ankush

Posted in Open XML SDK, Word | Tagged: , , , | Leave a Comment »

 
%d bloggers like this: