How to add content control in a Word 2007 document using OpenXML - ms-word

I want to create a word 2007 document without using object model. So I would prefer to create it using open xml format. So far I have been able to create the document. Now I want to add a content control in it and map it to xml. Can anybody guide me regarding the same???

Anoop,
You said that you are able to creat the document using OpenXmlSdk. With that assumption, you can use the following code to create the content control to add to the Wordprocessing.Body element of your Document.
//praragraph to be added to the rich text content control
Run run = new Run(new Text("Insert any text Here") { Space = StaticTextConstants.Preserve });
Paragraph paragraph = new Paragraph(run);
SdtProperties sdtPr = new SdtProperties(
new Alias { Val = "MyContentCotrol" },
new Tag { Val = "_myContentControl" });
SdtContentBlock sdtCBlock = new SdtContentBlock(paragraph);
SdtBlock sdtBlock = new SdtBlock(sdtPr, sdtCBlock);
//add this content control to the body of the word document
WordprocessingDocument wDoc = WordprocessingDocument.Open(path, true); //path is where your word 2007 file is
Body mBody = wDoc.MainDocumentPart.Document.Body;
mBody.AppendChild(sdtBlock);
wDoc.MainDocumentPart.Document.Save();
wDoc.Dispose();
I hope this answers a part of your question. I did not understand what you ment by "Map it to XML". Did you mean to say you want to create CustomXmlBlock and add the ContentControl to it?

Have a look for the Word Content Control Toolkit on www.codeplex.com.
Here is a very brief explanation on how to do what you are attempting.
You need to have access to the developer tab on the Word ribbon. To get this working click on the Office (Round thingy) in the top left hand corner and Select Word Options at the bottom of the menu. On the first options page there is a checkbox to show the developer toolbar.
Use the developer toolbar to add the Content controls you want on the page. Click the properties button in the Content controls section of the developer bar and set the name and tag properties (I stick to naming the name and tag fields with the same name).
Save and close the word document.
Open the Content control toolkit and then open your document with the toolkit. Use the left hand pain to create some custom xml to link to your controls.
Now use the bind view to drag and drop the mappings between your custom xml and the custom controls that are displayed in the right panel of the toolkit.
You can use the openxml sdk 1.0 or 2.0 (still in ctp) to open your word document in code and access the custom xml file that is contained as part of the word document.
If you want to have a look at how your word document looks as xml. Make a copy of your word document and then rename it to say "a.zip". Double click on the zip file and then navigate the folder structure. The main content of the word document is held under the word folder in a file called "document.xml". The custom xml part of the document is held under the customXml folder and is generally found in the file named "item1.xml".
I hope this brief explanation get you up and running.

Related

Set the text of a control via macro in Libre Office Draw

I have designed a document in Libre Office Draw, and now need to personalize it by filling certain controls (mainly labels) with names read from a text file.
Reading from a text file was trivial, but am facing difficulties in obtaining a reference to a control placed in a Libre Office Draw document; all the functions mentioned were related to controls placed on a dialog, and did not seem applicable in this case.
This might be the first lead into reaching my goal:
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
But then, how to find a control placed on 'document' named, say, "MyLabel1"? Once the label is filled, the document would need to be exported to PDF.
Thanks a lot!
To export a LO Draw document to PDF from Basic you can use the following code.
Sub ExportToPDF
sURL = convertToURL("d:\temp\lo_draw.pdf")
dim mFileType(0)
mFileType(0) = createUnoStruct("com.sun.star.beans.PropertyValue")
mFileType(0).Name = "FilterName"
mFileType(0).Value = "draw_pdf_Export"
thisComponent.storeToURL(sURL, mFileType())
End Sub
To figure out how to get access to the "labels" please provide a sample LO Draw document.

What's this red "A" on my property?

This is a property in an ibd diagram using sysml1.3.
I don't know what this red letter A is in the low right corner. It's the only item that has it. I guess I have done something to get it but I don't know what and googling it has not given any answer. Can someone explain it?
It contains an attachment (Linked Document). Use Ctrl-Alt-D to view it. Use the context menu to delete (or edit) it.
I would just add that in some cases by default EA (v 14) can open document like diagrams - in full view, especially for CTRL+ALT+D shortcut (or right click on element with Linked Document and after selecting from context menu option Linked Document).
For below flows EA can open Dynamic Document tab by default, as preview next to the i.e. Element Properties, instead of Linked Document:
Start > Explore > Properties > Linked Document or
Show > Portals > Window > Document > Linked Document
Default Document tab by default instead of Linked Document
On Dynamic Document you won't find option to delete Linked Document:
Delete is not available for Dynamic Document
Just switch to the Linked Document, from hamburger select delete and that's it:
Delete is available for Linked Document

libreoffice base macro parametric open close get current form name

libreoffice Base 4.3.3.2
Opening a Form page by name and then close the current page form like this work:
oForm = ThisDatabaseDocument.FormDocuments.getByName("SecondForm")
oForm.Open
oFormC = ThisDatabaseDocument.FormDocuments.getByName("CurrentForm")
oFormC.Close
but is there a way to close oFormC without writing by hand his name?
trying with:
oFormC = Event.Source.Model.Parent
oFormC = ThisDatabaseDocument.FormDocuments.getByName(Event.Source.Model.Parent)
oFormC = getParent()
return an error of var not set
Can't find any help in documentation.
The term 'form' in LibreOffice/OpenOffice is confusing because it refers both to the entire document (typically a Writer file) and also to each group of form controls inside that document. So each form document can have many forms (meaning a group of controls) inside it, and forms (groups of controls) can have sub-forms.
This code gets a form document (a Writer file embedded inside a Base file):
oDoc = ThisDatabaseDocument.FormDocuments.getByName("SecondForm")
This code gets the form that is a group of controls and that contains the control which triggered the macro: oForm = Event.Source.Model.Parent
Another way to get a group of controls inside the form document in which the macro was triggered: oForm = ThisComponent.drawpage.forms.MainForm
Replace "MainForm" with your actual form name - form here meaning a group of controls. You can see the names of forms and subforms that are inside a form document by opening the Form Navigator window. Make sure the toolbar Form Design is visible; the Form Navigator icon is the sixth from the left or top, looks like a rectangle with a compass in the upper right corner.
You may have guessed from the previous code how to close the document that is active when the macro is triggered:
ThisComponent.close

Cannot add a third content field

I'm kinda new to typo, so maybe I am just missing something.
I'm trying to add a third content field to Typo3 4.5.
What I've done so far.
Edit my template and added a new block
Added the block via TemplatVoila > Update Mapping > Modify DS / TO with Element Preset "Page-Content Elements [Pos.: 0]
Mapped it to the new block in the template
But I am missing something as the new field isn't showing up in the Page edit screen.
EDIT: I've found the Block in the "Edit page properties" but how to show it on standard edit screen?
Any added content area will appear automatically in your TV-View-module. So if you dont see it in there, then
you may have duplicate fields names
wrong column positions
or the existing template is using a »beLayout«-section, which shows only the first two content areas (see example in reference http://docs.typo3.org/typo3cms/extensions/templavoila/ExtTemplavoila/StaticDataStructures/ExampleForBelayout/Index.html)
The TemplaVoila template is split into TS (TemplaVoilà Template Object) and DS (TemplaVoilà Data Structure) records, may you paste the content of the field „Data Structure XML“ of the DS record here? In there are all necessary information.
The two template files should be located in your general storage folder, your TypoScript root file should be there as well.

Purpose for Word Open XML and content controls binding

For word report generation, I am looking at binding XML to content controls to see if it is any easier than to use Word Interop and hardcode index reference to content controls to assign values to them.
However, I don't really understand how to do it.
My work flow is entering information in Excel and then generate an XML file to have content controls populated by XML, however, what I read is the other way round: Word Control Control Toolkit and descriptions where the XML is populated by user entering information in Word, and then programmer to unzip docx file to retrieve the XML file.
How can I populate content controls with XML?
There are samples on generating Word documents from Word templates, XML and data bound content controls # http://worddocgenerator.codeplex.com/
Set up the mapped content controls in the 'template' docx using the content control toolkit or similar. Do this using a sample XML file containing your Excel data.
Now you have that template document, at run time you can inject your XML file into it (ie replace the custom xml part it contains, with your instance data), in C# or Java or whatever.
When the user opens the document in Word 2007/2010, the information in the custom XML part will automatically be copied into the bound controls, and visible to the user.
Note that content control data binding doesn't easily support repeating data (eg populating table rows) in Word 2007/2010, though there are ways to do it.