Patrick's Bytes

2, July 2008

Office Tips: Line Breaks Without Bullets

Filed under: Office,Word — patrickyong @ 11:37 am

Tested on Word 2007

When you’re creating a bulleted or numbered list in Microsoft Office Word or Microsoft Office PowerPoint, you might want an item to appear in the list without a bullet or without incrementing the number. You can start a new line without a bullet by pressing SHIFT+ENTER. The next time you press the ENTER key, the new line will continue the bulleted or numbered list.

27, May 2008

Replace content of <w:t> element inside Content Controls with data bound value from Custom XML part

Filed under: LINQ,OpenXML,Word — patrickyong @ 4:47 pm

In my previous post I discovered that Content Controls in WordprocessingML files which has data binding to a CustomXML part will not render properly. However, this ONLY apply if you programmatically replaces the CustomXML part but never modify the value of <w:t> within the <w:sdt> element just like in this Eric White’s video on YouTube or as per mentioned in the book [Pro SharePoint Solution Development] in Chapter 7 .

To make things clearer, lets look at the screen shots below. For a Word 2007 document with CustomXML data bound(AND also with the CustomXML modified programmatically), below is what it looks like by default when you open it with Office 2003 (or XP and 2000), the data does not appear (below).

image

Even though you see there is no problem when open it up with Office 2007 (below)

image

This is because the Compatibility Pack for Office 2007 File Format does not render the value data bound inside the <w:databinding> element but instead its take the value in <w:t> element, shown below:

<w:sdt>
– <w:sdtPr>
<w:dataBinding w:xpath=”/root[1]/name[1]” w:storeItemID=”{b6aa39be-c6d5-40ca-a66e-93dbd069104f}” />
  <w:id w:val=”3411243″ />
– <w:placeholder>
  <w:docPart w:val=”DefaultPlaceholder_22675703″ />
  </w:placeholder>
  <w:showingPlcHdr />
  <w:text />
  </w:sdtPr>
– <w:sdtContent>
– <w:p w:rsidR=”006D15FD” w:rsidRDefault=”00F43988″>
– <w:r w:rsidRPr=”00583873″>
– <w:rPr>
  <w:rStyle w:val=”PlaceholderText” />
  </w:rPr>
<w:t>Click here to enter text.</w:t>
  </w:r>
  </w:p>
  </w:sdtContent>
  </w:sdt>

So I created a generic project using the latest OpenXML SDK (April 08 CTP) and together with LINQ to XML to modify the content within <w:t> element with the value from the CustomXML part. You can download my full source code here, but basically this is how my solution works:

XNamespace w = @”http://schemas.openxmlformats.org/wordprocessingml/2006/main”;

        public void Convert(string fileName)
        {
            using (var wordDoc = WordprocessingDocument.Open(fileName, true))
            {
                var mainPart = wordDoc.MainDocumentPart;

                XmlReader reader;

                reader = XmlReader.Create(mainPart.GetStream(FileMode.Open, FileAccess.Read));

                XDocument mainXml = XDocument.Load(reader);

                string xpath;
                XElement t;
                var bindings = mainXml.Descendants(w + “dataBinding”);

This is where the magic works, grab XPath attribute value from all the <w:databinding> elements and then replace it into <w:t> element using GetValueFromCustomXmlParts method (details do refer my source code)

                foreach (XElement binding in bindings)
                {
                    xpath = binding.Attribute(w + “xpath”).Value.ToString();

                    t = binding.Parent.Parent.Descendants(w + “t”).First();
                    string textValue = GetValueFromCustomXmlParts(mainPart.CustomXmlParts, xpath, myns);

                    t.ReplaceNodes(textValue);

                }

                XmlDocument temp = new XmlDocument();
                temp.Load(mainXml.CreateReader());
                temp.Save(wordDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write));
            }
        }

After that the Word 2007 document can be opened in Office 2003 and data are rendered successfully. This solution also works in other none-MS Office productivity suites such as ThinkOffice and WordPerfect.

image

Disclamer: This is just a quick fix or rather a proof of concept on how to solve the <w:databinding> element problem on a simple Word 2007 document, there are  many situations (or more complex document layout) I haven’t tested the solution on. Do download my solution at your own risk. If you bump into problems do let me know, but my help will only be on best effort basis.

By the way, here is Eric’s video on the new OpenXML SDK

[YouTube=http://www.youtube.com/watch?v=t_FYHd234ng]
YouTube – Open XML SDK demo and road map

image

23, May 2008

Compatibility Pack for Office 2007 file format does not render <w:dataBinding>

Filed under: OpenXML,Word — patrickyong @ 10:01 am

I created a Word 2007 file with data binding to a CustomXML part

clip_image001

When I open it in Word 2003 with the capability pack installed, the data is not displayed.

clip_image003

After some investigation, I open up the document.xml (just rename the word file extension to .zip instead of .docx) and realize that the compatibility pack only renders the content inside <w:t> tag and ignores the XPath binding on the <w:dataBinding> tag. Below is a part of my document.xml, notice the blue colored text.

<w:sdt>
– <w:sdtPr>
  <w:dataBinding w:xpath=”/root[1]/name[1]” w:storeItemID=”{b6aa39be-c6d5-40ca-a66e-93dbd069104f}” /> 
  <w:id w:val=”3411243″ />
– <w:placeholder>
  <w:docPart w:val=”DefaultPlaceholder_22675703″ />
  </w:placeholder>
  <w:showingPlcHdr />
  <w:text />
  </w:sdtPr>
– <w:sdtContent>
– <w:p w:rsidR=”006D15FD” w:rsidRDefault=”00F43988″>
– <w:r w:rsidRPr=”00583873″>
– <w:rPr>
  <w:rStyle w:val=”PlaceholderText” />
  </w:rPr>
 
<w:t>Click here to enter text.</w:t>
  </w:r>
  </w:p>
  </w:sdtContent>
  </w:sdt>

If you are creating a WordML document thru this manner and want to enable it for users of older version of Word, remember to update your <w:t> tag as well.

14, May 2008

Where is that &$#@ command in Office 2007?!

Filed under: Excel,Office,PowerPoint,Word — patrickyong @ 8:32 am

 

Sounds familiar? This is the No. 1 complain for first time user of Office 2007 because of the new Ribbon user interface, quite a number of commands have been repositioned. I keep on telling people that after a couple of weeks they will get used to the new UI and actually be happy with it. Honestly at least I do (whether or not I working with Microsoft)

Search

So for the rest of us, Office Labs launched a new Office add in called Search Commands. It helps you find commands, options, wizards, and galleries in Microsoft Office 2007 Word, Excel and PowerPoint. Just type what you’re looking for in your own words and click the command you need. Search Commands also includes Guided Help, which acts as a tour guide for specific tasks. (pic above)

Go here for more details.

9, April 2008

Office Developer Conference ’08 contents now online

image

The slides from ODC 2008 are made available on the OBA Central website.

The slides are categorized into a few categories:

  • Architecture (those planning a full scale deployment of OBA should read this!)
  • Client (incl. coverage of some lesser know product for OBA i.e. Access & Groove)
  • Executive
  • Server (ala SharePoint, look out for stuffs on BI and Authentication)
  • Services (SOA & S+S)

One of the cool thing I saw from the slides is a 3d Silverlight webpart for Plant Floor OBA RAP (pic below).

image

http://www.obacentral.com/ODC

30, March 2008

MS Word for FREE

Filed under: Word — patrickyong @ 5:46 pm

I guess this headline sure caught your attention. Actually you still can’t go to Low Yat today and asked for a free copy, don’t even try come to 29th floor KLCC either!

You see, I just discovered that the last DOS based version of MS Word (v5.5) has been made available by Microsoft since 1999 after they released it as a Y2k fix.

You can download the program here. Below is a screen shot.

 image

5, March 2008

Office Live Workspace available worldwide

Filed under: Excel,Office,Office Live,Outlook,PowerPoint,Word — patrickyong @ 2:28 am

Microsoft just launch the beta version of Office Live Workspace after allowing pre-registration for US based customers few months ago. Good news is this time it is available worldwide. Goto this URL to sign in using your Windows Live/ Hotmail ID http://workspace.office.live.com/

Upon signing in you will get a screen as below, notice that there is an ‘Install Office Add-in’ button. This is a less than 1Mb .msi file download which gives you integration on Word, Excel and PowerPoint. image

I look at Office Live Workspace as a online extension of the Office client. There is a personal document library for you which you also can share with other people. Then for Outlook you can synchronize your tasks, appointments, contacts and even notes on your workspace.

image

On the help file it stated that the integration is available for Office 2003 and XP as well. Cool, FREE new features for older version of Office product. How many vendor does that?


Integration with Office 2003

Integration with Office 2007

17, January 2008

VSTO Reloaded

Today the MSE team did a Tech Preview to fellow developers on Visual Studio 2008 which actually available for MSDN subscribers late last year and is available for sales now.

My session is about Visual Studio Tools for Office (VSTO) 2008 and a lot of productivity enhancements have been put inside the package in this current version. They include but not limited to:

  1. Better UI Development on Office UI
    • Form Regions in Outlook
    • Custom Task Pane
    • Custom Ribbon for Excel, Word and PowerPoint.
    • No relearn, leverage on Windows Form Development skill
    • Windows Form able to host WPF app and extends this capability via Custom Task Pane
  2. SharePoint Workflow development
    • No more manual writing of workflow.xml, feature.xml (both are SharePoint feature config files) and deployment script
    • Streamline development process from 15 steps to 3 steps in VSTO 2008
  3. Word Content Control data binding with VSTO addin
    • Bringing unstructured data from Word documents to a structured world
    • Able to attach custom XML such as RosettaNet or UNeDoc which as industry based XML schema to Word data.
  4. Easy deployment of VSTO – Office Addin via Click Once
    • No more reliant on CASPOL
    • Transparent to end users

vstodemo

I demo a cool VSTO addin for Word 2007 hosting a WPF user control with colossal effect and acting as a client to a WCF services at the back end. The data access is done using LINQ for XML. After that I will publish

It is based on an article in MSDN Dec 2007 issue but the source codes there is not working for RTM version of VS 2008. Many thanks for fellow MS staff Andrew Whitechapel for making it work for VS2008 RTM.

You can download the slides and working version of the source code here. They are hosted on Windows Live Skiydrive/ Folders.

Slides in PDF

Slides in XPS

Source Code in C#

I will come out with a tutorial for the SharePoint Workflow later and also a VB9 version of the source code. So stay tuned. 🙂

3, July 2007

Working with WordprocessingML Content Controls

Filed under: OpenXML,Word — patrickyong @ 5:28 am

 

Screencast
http://msdn2.microsoft.com/en-us/library/bb291003.aspx

Working with Content Controls
http://msdn2.microsoft.com/en-us/library/bb243344.aspx

Building Word 2007 Document Templates Using Content Controls
http://msdn2.microsoft.com/en-us/library/bb264571.aspx

Linking Word 2007 Content Controls to Custom XML
http://blogs.msdn.com/acoat/archive/2007/03/01/linking-word-2007-content-controls-to-custom-xml.aspx

Word 2007 Content Control Toolkit

XML Mapping with Word and SharePoint
http://channel9.msdn.com/Showpost.aspx?postid=273005

Mapping Control Controls via Word 2007 
http://www.click2learn.ch/help/Pages/MappingControlControlsviaWord2007.aspx

Linking Word 2007 Content Controls to Custom XML
http://blogs.msdn.com/acoat/archive/2007/03/01/linking-word-2007-content-controls-to-custom-xml.aspx

Blog at WordPress.com.