Erika Ehrli - Adventures with Office Products & Technologies
MSDN & TechNet: Releasing Office, SharePoint, Exchange & Lync Centers and content for developers and IT professionals.

  • Erika Ehrli - Adventures with Office Products & Technologies

    Office Business Applications: What is it, and how can I get started?


    I’ve had this topic in my blog wish-list for a while and today is the day to talk about this. I have been listening the term “OBA” so I decided to research a bit on the topic to understand what is it and put together a list of resources that can help developers and architects get started. I realize some of you might already know about this, but I know some people are not familiar with this technology, so here goes a quick intro for all of you who want to know what is it and how to get started.

    What is it?
    Office Business Applications are a new category of business applications that connect line-of-business systems and processes with the people that use them through a familiar user interface: Microsoft Office. Basically, you have back-end systems (data access layer) and you can build a middle-tier of business logic to connect into business processes in line-of-business applications such as Enterprise Resource Planning (ERP), Customer Relationship Management (CRM), and Supply Chain Management (SCM), this is your business-logic layer. We are still missing the presentation layer. Instead of building a Web application, Windows client application, or use a specialized CRM UI, you use Microsoft Office programs as the presentation layer and let users interact and run business processes while using the programs that are already running. Finally, you can also integrate to SharePoint sites that use Web Parts to report data.


    I stole this little diagram from an MSDN article and I recommend reading Atanu's article: Building Better Business Applications Using the 2007 Microsoft Office System if you are interested in learning more about the architecture of OBA solutions.

    So why use Office as your presentation layer? One of the advantages of using Microsoft Office as a front-end to work on business processes is that it’s easier for users to work with an application that is already open. No need to have a context-switch between Office and a specialized CRM UI. Anyway, you have an open window running Outlook all day…

    Customers are building OBAs using Office 2003, SharePoint Portal Server 2003, and Visual Studio Tools for Office, so technically, you don’t have to use Office 2007 for an OBA. However, the 2007 Microsoft Office system, Office SharePoint Server 2007 and VSTO 2005 SE provide built-in features (such as workflow, Excel services, Ribbon extensibility, InfoPath Web forms, the Business Data Catalog, the Office Open XML File Formats and more) that help you get there with less code. Let’s just say it’s easier to build.

    How to get started?
    A good thing to know is that we released a couple of weeks ago the Reference Application Pack for Supply Change Management that will help you ramp-up.

    The OBA RAP for Supply Chain Management includes a reference application with scenarios for collaboration between the different levels of a multi-tier supply chain starting with a retailer, and then extending back through a manufacturer and a tier-1 supplier.  In addition to the application and associated templates and scripts, it includes a white paper outlining the architecture and implementation, and screen-capture demos.   The OBA RAP for Supply Chain Management is available for download at

    What are the pre-requisites?  What do I need to run the reference app?
    To use the OBA RAP for SCM, you need to have the following:
    • Windows Server 2003
    • Microsoft Office SharePoint Server 2007
    • Microsoft Office 2007
    • WinFX runtime June CTP
    • Visual Studio 2005
    • WinFX SDK June CTP
    • Visual Studio extensions for WF 2.2 & WinFX
    • VSTO “3”
    • SQL Server 2005
    • Active Directory

    The package includes:
    • A reference solution and a reference implementation for building Office Business Applications using Office 2007
    • An OBA for Supply Chain Management, with scenarios for collaboration between the different levels of a multi-tier supply chain starting with a retailer, and then extending back through a manufacturer and a tier-1 supplier
    • Downloadable bits, including:
    • Demo websites and site templates
    • Supporting documents (.doc, .xls) for reference scenarios
    • .NET Assemblies (workflows, utilities, activity libraries)
    • Web services (.asmx)
    • Reference data
    • XSLT files
    • BDC XML files
    • Scripts
    • White paper on how to architect and build a supply chain OBA
    • Screen-capture demos

    OBA: useful resources...

    • Channel 9: Javed Sikander: Office 2007- Office Business Application
    • Javed Sikander: OBA blog: Talk to Javed if you want to learn more about OBA.
    • OBA RAP for Supply Chain Management
    • Office Business Applications Developer Portal


  • Erika Ehrli - Adventures with Office Products & Technologies

    NEW must-read book for Microsoft Office Project VBA programmers!


    Some time ago I blogged about Project Developer Resources and I want to add a new resource to my list.

    Rod Gill (Project MVP) just contacted me to let me know about his new book! He compiled a lot of VBA code samples for working with Project (98-2007), so if you are a Project developer, you might consider getting this book:

    VBA Programming for Microsoft Office Project 1998-200X applies to all Micrsoft Project versions through Microsoft Office Project 2007 professional and standard editions with an introduction to new features in the 2007 version. MVP author Rod Gill brings his years of expertise into this first of a kind offering focusing exclusively on VBA programming for Project. Not only is this a must have for users who hope to maximize their Project client value through VBA programming and macros, it's a wonderful get started guide for Office VBA programming in general. Learn from one of the world's most reknown experts on Project VBA!

    You can find more information about this book here:

  • Erika Ehrli - Adventures with Office Products & Technologies

    Want a video blog?


    Videos are great eye candy for Web sites and blogs are the latest .com most popular content. So now imagine having them together. According to WIKIPEDIA, a blog that includes video is better known as Vlog and vlogging is the latest trend in blogging.

    The reason is simple: a lot of people love videos. It's a pleasure watching something funny or learning tricks while watching and listening to a demo. You are seeing and listening to the world and it's just taking what you can read somewhere a step further.

    Watching Webcasts, trying out Virtual Labs or downloading Screencasts will help you to reduce your learning curve for new technologies and MSDN is on top of it. The same happens with blogs. If you post code samples to your blog, you might consider trying to record a demo as a video and post it. Readers will get a better experience because they will get to see what the code is doing.

    I have been doing some research and here are some tips I want to share in case you are interested in exploring the concept.

    To start creating my own videos and I needed two things:

    1. The tools:

      I just got my license for Camtasia (and I promise nobody is paying me for the free marketing). I did my benchmark exercise to evaluate this software along with some others, and Camtasia offered the features I needed. You can consider it as a good option if you are planning to start recording demos. Of course once you record the video, you need to post it to a server so everyone can watch it.

    2. The code for embedding the videos:

      So here's the deal. You can have different video formats, such as:

    • AVI video files
    • Macromedia Flash (SWF) movie files
    • Windows Media (WMV) streaming media file
    • QuickTime (MOV) movie files
    • Custom production files


    I am interested in working with WMV files and using Windows Media Player client to embed videos into Web pages. Fortunately, there's and ActiveX control (WMPlayer.OCX) that you can use through script. Bad news is some blog sites will not allow you to run scripts and you will be limited to use HTML. One thing you can do is create an html page, host it in a different server (a lot of bloggers do the same with images) and use an IFrame to pull the video page to your blog. Here is some sample code that you can use to embed videos into HTML pages:

    <title>Render Video</title>
    <!-- This is the code you need. -->

    <script language="JavaScript">

    var WMP7;

    = new ActiveXObject("WMPlayer.OCX.7");
    else if (window.GeckoActiveXObject)
    = new GeckoActiveXObject("WMPlayer.OCX.7");

    // Windows Media Player 7 Code
    if ( WMP7 )
    document.write ('<OBJECT ID=MediaPlayer ');
    .write (' CLASSID=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6');
    .write (' standby="Loading Microsoft Windows Media Player components..."');
    .write (' TYPE="application/x-oleobject" width="400" height="400">');
    .write ('<PARAM NAME="url" VALUE="">');
    .write ('<PARAM NAME="AutoStart" VALUE="false">');
    .write ('<PARAM NAME="ShowControls" VALUE="1">');
    .write ('<PARAM NAME="uiMode" VALUE="mini">');
    .write ('</OBJECT>');

    // Windows Media Player 6.4 Code
    //IE Code
    document.write ('<OBJECT ID=MediaPlayer ');
    .write ('CLASSID=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 ');
    .write ('CODEBASE=,4,5,715 ');
    .write ('standby="Loading Microsoft Windows Media Player components..." ');
    .write ('TYPE="application/x-oleobject" width="400" height="400">');
    .write ('<PARAM NAME="FileName" VALUE="">');
    .write ('<PARAM NAME="AutoStart" VALUE="false">');
    .write ('<PARAM NAME="ShowControls" VALUE="1">');

    //Netscape code
    document.write ('    <Embed type="application/x-mplayer2"');
    .write ('        pluginspage=""');
    .write ('        filename=""');
    .write ('        src=""');
    .write ('        Name=MediaPlayer');
    .write ('        ShowControls=1');
    .write ('        ShowDisplay=1');
    .write ('        ShowStatusBar=1');
    .write ('        width=400');
    .write ('        height=400>');
    .write ('    </embed>');

    .write ('</OBJECT>');



    If you use the previous code and an IFrame, videos in your blog can look like this:

    This KB article has code samples to embed videos using VBScript or Jscript and here are some useful resources for working with the Windows Media Player object model and downloading the latest version:

    Happy Vlogging!


  • Erika Ehrli - Adventures with Office Products & Technologies

    Comments are welcome


    I didn't realize until yesterday that I accidentally blocked everyone to add comments to my blog for a while. I was trying to reply to some comments and even when comments were enabled, the Submit button was not doing a postback. At first I thought it was because I changed my template and added a bunch of CSS overrides, but that was not the problem.

    The problem (in case this is happening to you) is that I added a Technorati script to my blog. The script contains another form, so when the blog is rendered you have a form inside a form, and that's why a Submit button can't do postback.

    Everything started working when I removed the script, so if you want to leave comments, you can do it now.

    I apologize for the inconvenience,


  • Erika Ehrli - Adventures with Office Products & Technologies

    Developing Add-ins (XLLs) in Excel 2007


    If you are interested in learning about Microsoft Office Excel 2007 features that affect XLL add-ins and enable new XLL functionality, as well as changes to the XLL C API itself, we just published a great article by Steve Dalton that will help you get started.

    The intended audience for this article consists of Microsoft Visual C and Microsoft Visual C++ developers who already have experience developing Microsoft Office Excel add-ins, or XLLs. This article is not an introduction to XLL development although a brief overview is included. To make the most of this article, readers should be familiar with:

    • C and C++ language concepts and constructs. Code examples are written in C++.
    • Building DLLs that export functions.
    • The XLOPER data structure and other Excel data types, such as the floating point matrix structure (FP).
    • The add-in manager interface functions, such as xlAutoOpen and xlAutoClose.
    • XLOPER memory management (xlAutoFree, xlFree, and the use of xlbitDLLFree and xlbitXLFree).

    Read the article here:


  • Erika Ehrli - Adventures with Office Products & Technologies

    Developer Map for the 2007 Microsoft Office System - Image Map (draft)


    We have been saying everywhere that "the Microsoft Office System is a complete set of client applications, servers, and services that provide organizations with the means to create, manage, and enhance business solutions." We have also published a full load of content for every product since Beta 2. Yet, we realize that as a developer, sometimes it's hard to understand the big picture and how all the little pieces (features and product specifics) can work together to help you build a real-world solution.

    Office is a huge family of products and technologies and we have been working with all product teams to create an overall map that helps developers to visually understand how all the pieces of the puzzle relate to each other, but more important, provide information of where on MSDN you can find technical documentation related to specific features. We want to go deep to namespaces, class members, and schemas for each product to list them all together on a single place.

    As you can imagine, space is a huge limitation. While trying to put all this together, I happen to agree with the "Microsoft 2007 Office system – It's more than you think" slogan. Office is HUGE and there's limited space to place all PIA objects, namespaces, web services, product features, schemas, names, descriptions and relationships for more than 25 products and technologies. However, we have found a great way to summarize the most relevant ideas and make it fit all together.

    I can share with you that I have found the exercise to be fascinating. Just imagine how much fun we've had having on a single meeting room PMs for all product teams + Developer Platform Evangelism + Marketing + Office Developer Documentation group and work together as a team to build the treasure map.

    We are about to conclude this project, but in the meantime, I just couldn't wait to share with you a small version of our treasure map. I built this conceptual diagram using PowerPoint 2007 and then generated an image map that provides links to places on MSDN and You can hover the map and drill-down to find detailed information for each product and technology. Of course, this is a petite version, but soon, you'll get the complete treasure map.

    So here goes...


  • Erika Ehrli - Adventures with Office Products & Technologies

    Visual Studio Tools for Office 2005 Second Edition is here!


    Microsoft announced today the release of the Visual Studio Tools for Office 2005 Second Edition!

    Visual Studio 2005 Tools for the 2007 Microsoft Office System (Visual Studio 2005 Tools for Office Second Edition Beta, or VSTO 2005 SE Beta for short) is a free add-on to Visual Studio 2005 that empowers developers to build applications targeting the 2007 Office system. Developers can now harness the benefits of the 2007 Office system platform and create Office-based solutions using the professional development environment of Visual Studio 2005.

    Anyone who has a licensed version of Visual Studio 2005 Tools for Office or Visual Studio Professional and above (either standalone versions or via an MSDN Premium or Professional subscription) is eligible to download a free copy of VSTO 2005 SE Beta.  

    You can download it for free and start playing around with the new features. I love that you have more project templates for Office Add-ins than in previous releases. Specially, if you are interested in developing solutions with the Ribbon or Custom Task Panes and other Office 2007 features, I would strongly recommend you to download the Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System Beta.

    We also launched today a new MSDN page for the VSTO 2005 SE release where we will publish more articles related to the latest VSTO release.

    Check out the latest ones:

    Get a Hands-On Introduction to VSTO 2005 SE
    Get an Inside Look at VSTO 2005 SE Design

    Read Paul Stubbs's blog for more news.




  • Erika Ehrli - Adventures with Office Products & Technologies

    Office Development Bloggers OPML


    I have been experimenting with Outlook 2007 RSS Feeds and Windows Live. I have been adding a bunch of RSS feeds for the most popular blogs related to Office, SharePoint, and VSTO. I have to say it… I am surprised to see so many people devoted to blog about Office, at some point it looked like I was trying to stress-test Outlook while adding RSS feeds! I added ~60 RSS feeds and I thought it would be awesome if I could export my feeds to OPML, so I started playing around and discovered Outlook 2007 allows you to export your RSS Feeds and save them as an OPML file. Here's how…

    How-to export a collection of RSS Feeds in Outlook 2007

    You can export a collection of your RSS Feeds to an .opml file and then import from that file to another computer that you or someone else uses. This is a great way to share a collection of RSS Feeds with someone else or to make a backup of your RSS Feeds settings.

    You can choose which RSS Feeds to include in the exported .opml file.

    1. On the File menu, click Import and Export.
    2. Click Export RSS Feeds to an OPML file, and then click Next.
    3. Select the check boxes for each RSS Feed to include in the export.
    4. Click Next.
    5. Click Browse to navigate to the location where you want to save the .opml file.
    6. In the File name text box, type a name for the export file.
    7. Click Save, and then click Next.

      The .opml file is saved

    What is OPML?

    OPML stands for Outline Processing Markup Language. OPML is a standard that defines a set of XML elements and attributes to create outlines.

    Outlines can be used for specifications, legal briefs, product plans, presentations, screenplays, directories, diaries, discussion groups, chat systems and stories.

    In a nutshell, an OPML file has the following structure:

    <?xml version="1.0"?>
    <opml version="1.0">
    <title>OPML exported from Outlook</title>
    <dateCreated>Mon, 11 Sep 2006 18:04:15 -0700</dateCreated>
    <dateModified>Mon, 11 Sep 2006 18:04:15 -0700</dateModified>
      text="A discussion of what's new in Access 2007 (formerly "Access 12")"
    ="rss" xmlUrl=""/>
    outline text="Microsoft Excel 2007 (nee Excel 12)" type="rss"
    outline text="Office Rocker!" type="rss"
    outline text="doncampbell's weblog" type="rss"
    outline text="Doug Mahugh" type="rss"

    So why would you need OPML? Well, you can use it to share your RSS feeds with other people. OPML is one of those tech goodies inspired in the philosophy: knowledge is common wealth. Or if you are selfish, you can use it in your own benefit and add your OPML to other RSS feed reader tools.

    Read more about the OPML spec here.

    How-to import your OPML to Windows Live

    A cool place to read RSS feeds is Windows Live. No matter where you are, you can logon to Windows Live and read your favorite RSS feeds by importing your OPML file. Michael Coates tells you how.

    I followed the steps and found all my RSS feeds under "My Stuff", so now I can add Office Bloggers to my Windows Live site J.

    So, since I am not selfish, you can download my Office Development Bloggers OPML here (see attachment), and soon you will find it as a download on MSDN.



  • Erika Ehrli - Adventures with Office Products & Technologies

    New! 2007 Office System Virtual Labs


    From the Source Force to you…


    This is pretty cool. If you are interested in testing and playing around with the new 2007 Microsoft Office system client apps or Microsoft Office SharePoint Server 2007 without dealing with setup and installation, you might be interested in trying out the new 2007 Office System Virtual Labs.

    These are the latest ones…

    I already played around with the last one and it’s pretty neat. You get to work with a virtual machine and you can also download a lab manual with code that you can reuse later :).
    You can subscribe to the RSS feed or checkout the MSDN Virtual Labs page to see the latest ones.


  • Erika Ehrli - Adventures with Office Products & Technologies

    Office developer resources in your own language


    If you are into technology, you are mostly going to find documentation in English. However, if you speak another language, it’s always useful to find documentation in your own language. I am from Mexico and I am always pleased to find technical documentation in Spanish.

    Here is a list of international resources related to Office development that you might enjoy reading…

    Parlez-vous Français?…

    Office system 2007, c'est bien sûr une avalanche d'innovations, dont une nouvelle interface utilisateur qui facilite la découverte des fonctionnalités. Mais Office system 2007, c'est aussi une plateforme de collaboration et de gestion de contenus, avec laquelle vos applications métiers peuvent interagir.

    MSDN: Centre de développement Office et XML


    Non parlo italiano, ma potreste

    2007 Microsoft Office system è una soluzione avanzata che comprende applicazioni client e server, servizi e strumenti. Costruita sul formato XML e su una serie di tecnologie estendibili, ti consente facilmente di sviluppare applicazioni, dal business content management alla business intelligence, fino al project management e alla collaborazione in tempo reale.

    MSDN: Developer Center Microsoft Office

    Community italiane


    Sprechen Sie Deutsch?

    Microsoft Office in der Version 2007 bringt einige revolutionäre Neuerungen, z.B. in der Benutzeroberfläche - aber auch in der Art und Weise, wie Entwickler eigene Anwendungen unter dem Dach des weit verbreiteten Office Systems spielen lassen und dabei auf eine reichhaltige Fülle von Funktionen und Funktionalität zurückgreifen können.

    MSDN: Developer Center - Office Development


    Entwickler Communities:



    を利用した開発に慣れていない方には、このスクリーンキャストシリーズをお勧めします。Office 開発者 スクリーンキャスト バーチャル ツアーでは 2007 Microsoft Office System を利用した開発を始めるのに必要な学習教材を提供します。


    Office Online:


    Viva el Español!

    Microsoft Office System es una visión tecnológica que esta conformada por un conjunto de elementos totalmente integrados como: Programas, Servidores, Soluciones y Servicios, que permiten a los desarrolladores construír soluciones de negocios para conectar a la organización y a las personas con la información y los procesos de negocios rápida y fácilmente sobre una plataforma familiar.

    Acabo de darme el gusto de escribir algo en español en mi blog. Con todo gusto para la gente que habla español, ahí les van unas ligas que les pueden ser de utilidad:

    Artículos interesantes sobre desarrollo con Office:


    Comunidad Office System

    Office Online


    Por favor lean este artículo de Luis acerca de colaboración con SharePoint:

    Other worldwide resources:

    You can find more worldwide sites and international DLs here:

    International Discussion Groups:

    MSDN Worldwide Site

    Office Online Worldwide sites:

    I am planning to update this blog entry on a regular basis once I learn more about other resources. If you know about good international Office developer blogs and Web sites, please let me know and I will be glad to trackback.

    I have to say it, I had a lot of fun writing this blog entry :).


  • Erika Ehrli - Adventures with Office Products & Technologies

    Data-driven document generation with Word 2007 and the Office XML File Formats: Part 2


    So you are looking for a component/technology/solution to help you generate Office files (documents, workbooks, and presentations) using a server-side application, and of course, using managed code.

    I can tell you that this need has been brought to my attention at some conferences, questions in DLs, customer feedback, and as a common customer requirement when I was working as a consultant. You know that using automation and interop is definitely not an option. However, the Office XML File Formats are a great option.

    You can build a server-side application using Visual Studio to generate data-rich documents using the Office XML File Formats and  the .NET Framework 3.0 (aka Microsoft WinFX ). Here's how...

    In my previous blog entry I demonstrated how to build and Word 2007 template and connect an item in the data store. You built a customer letter document template with content controls that map to an XML file. In this blog entry, I will show you how to create a server-side data-driven document generation application that will allow you to select a company name to generate a custom letter. The application will retrieve customer data from a SQL Server database and use the customer letter document template to build a new document that displays customer data based on a user selection. The document will display the following information:

    • Company Name
    • Contact Name
    • Contact Title
    • Phone

    To create a server-side application that pulls data from a SQL Server database and generates a new Word 2007 document


    You can create a Web-based application that enables users to select a company name and generate a custom letter. The Web-based application retrieves customer data from a Microsoft SQL Server database, opens the customer letter document template, and creates a new document that displays customer data based on a user selection. This application does not require the use of Word 2007 or VBA. You can use your favorite managed code (Microsoft Visual Basic .NET or C#) language to build this application. To build this application, do the following:

    1. Open Microsoft Visual Studio 2005 or Microsoft Visual Web Developer 2005.
    2. Create an ASP.NET Web site and name it SqlServerSample.
    3. Connect the ASP.NET Web site to a Microsoft SQL Server database.
    4. Add a connection string to the Web.config file as follows:
      <add name="NorthwindConnectionString"
      ="data source=(local);database=Northwind; integrated security=SSPI;persist security info=false;"
      ="System.Data.SqlClient" />
    5. Add the CustomerLetterTemplate.docx to the App_Data folder.
    6. Download and install the Microsoft .NET Framework 3.0 (formerly Microsoft WinFX).
    7. Configure the assembly in the Web.config file as follows:
      <compilation debug="false">
      <add assembly="WindowsBase, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    8. Create a Web Form and replace the default.aspx code with the following sample code.

    The following sample shows how to bind to a Microsoft SQL Server database to retrieve data based on a customer selection and create a new document based on the CustomerLetterTemplate.docx.


    <%@ Page Language="VB" AutoEventWireup="true" %>
    <%@ Import 
    Namespace="System.Data" %>
    <%@ Import 
    Namespace="System.Data.SqlClient" %>
    <%@ Import 
    Namespace="System.IO" %>
    <%@ Import 
    Namespace="System.IO.Packaging" %>
    <%@ Import 
    Namespace="System.Xml" %>
    <!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns
    <head id
    ="Head1" runat="server">
        <title>Data-Driven Document Generation - SQL Server Sample</title>

    <script runat
    Private Const strRelRoot As String = ""
    Private Sub CreateDocument()
    ' Get the template file and create a stream from it
    Const TemplateFile As String = "~/App_Data/CustomerTemplate.docx"
    ' Read the file into memory
    Dim buffer() As Byte = File.ReadAllBytes(Server.MapPath(TemplateFile))
    Dim memoryStream As MemoryStream = New MemoryStream(buffer, True)
    ' Open the document in the stream and replace the custom XML part
    Dim pkgFile As Package Package.Open(memoryStream, FileMode.Open, FileAccess.ReadWrite)
    Dim pkgrcOfficeDocument As PackageRelationshipCollection pkgFile.GetRelationshipsByType(strRelRoot)
    For Each pkgr As PackageRelationship In pkgrcOfficeDocument
    If (pkgr.SourceUri.OriginalString "/"Then
    ' Add a custom XML part to the package
    Dim uriData As Uri = New Uri("/customXML/item1.xml", UriKind.Relative)
    If pkgFile.PartExists(uriData) Then
    ' Delete template "/customXML/item1.xml" part
    End If
    ' Load the custom XML data
    Dim pkgprtData As PackagePart pkgFile.CreatePart(uriData, "application/xml")
                    GetDataFromSQLServer(pkgprtData.GetStream, ddlCustomer.SelectedValue)
    End If
    ' Close the file
    ' Return the result
    "content-disposition""attachment; filename=document.docx")
    End Sub
        Private Sub 
    GetDataFromSQLServer(ByVal stream As Stream, ByVal customerID As String)
    'Connect to a Microsoft SQL Server database and get data
    Dim source As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
    Const SqlStatement As String = "SELECT CompanyName, ContactName, ContactTitle, Phone FROM Customers WHERE CustomerID=@customerID"
    Dim conn As SqlConnection = New SqlConnection(source)
    Dim cmd As SqlCommand = New SqlCommand(SqlStatement, conn)
    "@customerID", customerID)
    Dim dr As SqlDataReader cmd.ExecuteReader
    If dr.Read Then
    writer As XmlWriter XmlWriter.Create(stream)
    "CompanyName"CType(dr("CompanyName"), String))
    "ContactName"CType(dr("ContactName"), String))
    "ContactTitle"CType(dr("ContactTitle"), String))
    "Phone"CType(dr("Phone"), String))
    End If
    End Sub
        Protected Sub 
    SubmitBtn_Click(ByVal sender As ObjectByVal As EventArgs)
    End Sub

        <form id
    ="form1" runat="server">
                    Customer Letter Generator</h1>
                <table border
    ="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 12%">
    Choose a customer:</td>
                            <asp:DropDownList ID
    ="ddlCustomer" runat="server" AutoPostBack="True" DataSourceID="CustomerData"
    DataTextField="CompanyName" DataValueField="CustomerID" Width="301px">
                            <asp:SqlDataSource ID
    ="CustomerData" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers]" ProviderName="<%$ ConnectionStrings:NorthwindConnectionString.ProviderName %>">
            <br />
            <asp:Button ID
    ="Button1" runat="server" OnClick="SubmitBtn_Click" Text="Create Letter"
    Width="123px" />


    <%@ Page Language="C#" AutoEventWireup="true"%>
    <%@ Import Namespace
    ="System.Data" %>
    <%@ Import Namespace
    ="System.Data.SqlClient" %>    
    <%@ Import Namespace
    ="System.IO" %>
    <%@ Import Namespace
    ="System.IO.Packaging" %>
    <%@ Import Namespace
    ="System.Xml" %>

    <!DOCTYPE html PUBLIC 
    "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns
    ="" >
    <head id
    ="Head1" runat="server">
        <title>Data-Driven Document Generation - SQL Server Sample</title>
        <script language
    ="C#" runat="server">
    private const string strRelRoot "";

            private void 
    CreateDocument() {
    // Get the template file and create a stream from it
    const string TemplateFile @"~/App_Data/CustomerTemplate.docx";

    // Read the file into memory
    byte[] buffer File.ReadAllBytes(Server.MapPath(TemplateFile));
    MemoryStream memoryStream = new MemoryStream(buffer, true);
    buffer = null;

    // Open the document in the stream and replace the custom XML part
    Package pkgFile Package.Open(memoryStream, FileMode.Open, FileAccess.ReadWrite);
    PackageRelationshipCollection pkgrcOfficeDocument pkgFile.GetRelationshipsByType(strRelRoot);
    (PackageRelationship pkgr in pkgrcOfficeDocument) {
    if (pkgr.SourceUri.OriginalString == "/") {
                        // Add a custom XML part to the package
    Uri uriData = new Uri("/customXML/item1.xml", UriKind.Relative);

    (pkgFile.PartExists(uriData)) {
    // Delete template "/customXML/item1.xml" part
    // Load the custom XML data
    PackagePart pkgprtData pkgFile.CreatePart(uriData, "application/xml");
    GetDataFromSQLServer(pkgprtData.GetStream(), ddlCustomer.SelectedValue);

    // Close the file

    // Return the result
    Response.AddHeader("content-disposition""attachment; filename=document.docx");
    Response.ContentEncoding System.Text.Encoding.UTF8;




    private void GetDataFromSQLServer(Stream stream, string customerID) {
    //Connect to a Microsoft SQL Server database and get data
    String source ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
                const string 
    SqlStatement =
    "SELECT CompanyName, ContactName, ContactTitle, Phone FROM Customers WHERE CustomerID=@customerID";

    (SqlConnection conn = new SqlConnection(source)) {
    SqlCommand cmd = new SqlCommand(SqlStatement, conn);
    cmd.Parameters.AddWithValue("@customerID", customerID);
    SqlDataReader dr cmd.ExecuteReader();

    (dr.Read()) {
                        XmlWriter writer 
    writer.WriteElementString("CompanyName", (string)dr["CompanyName"]);
    writer.WriteElementString("ContactName", (string)dr["ContactName"]);
    writer.WriteElementString("ContactTitle", (string)dr["ContactTitle"]);
    writer.WriteElementString("Phone", (string)dr["Phone"]);

    protected void SubmitBtn_Click(object sender, EventArgs e) {

        <form id
    ="form1" runat="server">
                <h1>Customer Letter Generator</h1>
                <table border
    ="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 12%">
                            Choose a customer:</td>
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers]" ProviderName="<%$ ConnectionStrings:NorthwindConnectionString.ProviderName %>">
            <br />
    Text="Create Letter"
    Width="123px" />

    If you build and run this application, you will see something like this:
    As you can see, the code is simple and optimized for performance and memory. You can start building data-driven document solutions using this code. If your data source is an Access database, Web service, Oracle database, text file, or any other data source, it doesn't matter. Bottom-line, you only need to change the data access layer code. What matters the most is that using this technology you will be able to build server-side applications that generate Office documents using managed-code. I just love the potential that the Office XML File Formats provide and many thanks to Tristan Davis for sharing his knowledge on how to do this :). 
    Finally, I found out today that Microsoft published a virtual lab related with the Office XML File Formats and I wanted to share this as well:
    Programmatic Manipulation of the Microsoft Office Open XML Formats

    Learn how to manipulate Microsoft Office system documents using the Microsoft Office Open XML Formats without the 2007 release. Work through scenarios involving programmatically manipulating documents using the Microsoft Office Open XML Formats.

  • Erika Ehrli - Adventures with Office Products & Technologies

    Data-driven document generation with Word 2007 and the Office XML File Formats: Part 1


    Last week I had a chance to write some interesting code samples. I missed coding a lot, and I felt a little rusty after working in different projects. But I had a lot of fun and I want to share with you one of the samples I wrote: A simple ASP.NET 2.0 solution that retrieves data from SQL Server and generates a Word 2007 document using the Office XML File formats, WinFX, and XML Mappings in Word 2007.

    One of the most common requirements for applications that work with data is "data-driven document generation." No matter what the data source is -could be an Access database, SQL database, Web service, SharePoint list, Excel spreadsheet, XML file, Word document, or multiple sources. The typical "export data and create Word documents" feature is a common need.

    How to do it? Two simple steps:

    1. The Word part: Create a Word 2007 document template.
    2. The Cool app part: Create an application that pulls data from a datasource and generates new documents based on the Word 2007 document template.

    Word 2007 allows you to build data-driven document generation solutions. You can create a document template with a custom XML part and use Content Controls to bind to custom XML data using XML Mapping. Next, you can create a managed application to build a new document based on the template. The managed application will open the document template, retrieve data from a SQL Server database to build a new custom XML part, replace the template’s custom XML part , and save it as a new document.

    This little sample will show you how to build a document template from scratch and create a server-side application that generates documents that display data stored in a SQL Server database. How did I learn to do this, well, believe it or not, I watched the following Office Dev Con session:

    CD305—Word 2007 XML Programmability: Data/View Separation and Rich Eventing for Custom XML Solutions

    Presenter: Tristan Davis; 59 minutes (180 MB)
    In this session, we introduce new XML capabilities, then dive into the functionality of the Office XML data store and how it can be leveraged to build solutions that will strongly tie Word documents to your business processes.

    ..and then asked Tristan Davis some questions related with XML Mapping.

    Business Scenario: Custom Customer Letter

    To demonstrate how to build and Word 2007 template and connect an item in the data store to a SQL Server database, you will first build a customer letter document template with content controls that map to an XML file. Next, you will create a server-side data-driven document generation application that will allow you to select a company name to generate a custom letter. The application will retrieve customer data from a SQL Server database and use the customer letter document template to build a new document that displays customer data based on a user selection. The document will display the following information:

    • Company Name
    • Contact Name
    • Contact Title
    • Phone

    To create a Word template and define the XML Mappings for each content control.

    Use the following steps to create a Microsoft Office Word 2007 template.

    1. Open Word 2007.

    2. Create a document.

    3. Create content controls to bind to a node in the data store.

    What are content controls? Content controls are predefined pieces of content. There are several types of content controls, including text blocks, drop-down menus, combo boxes, calendar controls, and pictures. You can map these content controls to an element in an XML file. Using XPath expressions, you can programmatically map content in an XML file to a content control. This enables you to write a simple and short application to manipulate and modify data in a document. 

    4. Set the XML mapping on the content control.

    XML mapping is a feature of Word 2007 that enables you to create a link between a document and an XML file. This creates true data/view separation between the document formatting and the custom XML data.

    To load a custom XML part, you must first add a new data store to a Document object by using the Add method of the CustomXMLParts collection. This appends a new, empty data store to the document. Because it is empty, you cannot use it yet. Next, you must load a custom XML part from an XML file into the data store, by calling the Load method of the CustomXMLPart object, using a valid path to an XML file as the parameter.

    5. Add four plain text content controls in the following order.

    • Content control for Company Name
    • Content control for Contact Name
    • Content control for Contact Title
    • Content control for Phone

    6. Save the template document as C:\CustomerLetterTemplate.docx.

    To set an XML mapping on a content control

    Note In this procedure, you map the content control to a sample custom XML file. You will create a valid custom XML file, save it to your hard drive, and add a data store to the document that contains the information to which you want to map.

    1. Create a text file and save it as c:\CustomerData.xml.

    2. Paste the following into the text file and save it: 

    <?xml version="1.0"?>
    <CompanyName>Alfreds Futterkiste</CompanyName>
    <ContactName>Maria Anders</ContactName>
    <ContactTitle>Sales Representative</ContactTitle>

    3. Now, map each content control to bind to the <CompanyName>, <ContactName>, <ContactTitle>, and <Phone> and nodes of the previous custom XML part.

    4. Open the Visual Basic editor and run the following VBA code to add a data store to your template document.

    This sample code demonstrates how to attach an XML file to a document, so that it becomes an available data store item.

    ' Load CustomerData.xml file
    4).Load ("c:\CustomerData.xml")

    To create an XML mapping, you use an XPath expression to the node in the custom XML data part to which you want to map a content control. After you add a data store to your document (and the data store points to a valid XML file), you are ready to map one of its nodes to a content control. To do this, pass a String containing a valid XPath to a ContentControl object by using the SetMapping method of the XMLMapping object (via the XMLMapping property of the ContentControl object).

    5. Open the Visual Basic editor and run the following VBA code to bind content controls to items in the data store.

    Dim strXPath1 As String
    ActiveDocument.ContentControls(1).XMLMapping.SetMapping strXPath1

    Dim strXPath2 As String
    ActiveDocument.ContentControls(2).XMLMapping.SetMapping strXPath2

    Dim strXPath3 As String
    ActiveDocument.ContentControls(3).XMLMapping.SetMapping strXPath3

    Dim strXPath4 As String
    ActiveDocument.ContentControls(4).XMLMapping.SetMapping strXPath4

    You have your template file and you are ready to start your document generation application. I love ASP.NET and I created a server-side application to show you how to generate documents on the server using the Office XML File Formats. You can build a document generation application using Win Forms, a console application, a shared Add-in or your preferred application depending of your business needs.

    If you want to learn more about Word 2007 and document templates, read this article:

    This blog entry is too long already, so I will split it here and leave you with the intrigue of what part 2 will bring. Stay connected and you will soon know the happy ending for this walkthrough.



  • Erika Ehrli - Adventures with Office Products & Technologies

    Microsoft Office System Developers Conference 2006 Videos available on MSDN!


    Ready to go public with our surprise gift for you :).

    When you go to a conference, you always miss some sessions. It's kind of hard to go to all of them, so you get to organize your schedule and pick some. Then you go to a lot of sessions and start learning all this new information, but you wish you could have some kind of outline or pointer to help you remember all this new information. So the session ppt slides are always nice to have. If you couldn't make it to conference, even better!

    Last year when I went to PDC I published in my blog links to all the Office & SharePoint track PPT slides. This blog entry came to be quite successful and people were delighted to find a pointer to the slides. Of course, after some months the slides from PDC are no longer available.

    Now, imagine if instead of finding some plain ppt slides, you could actually watch the session with audio and get to see the demos. I am sure you would be quite pleased. The idea got my mind spinning when I had a chance to attend the Microsoft Office Systems Developers Conference and a team of five people believing you would be delighted to find this recorded sessions on MSDN made it happen. Seems kind of easy, but this was a lot of work since we are publishing more than 3,600 hours of video. We are just stubborn and sure this content is worth all the hard work.

    Office offers a big set of programs, servers, services, tools and technologies that you can integrate to build solutions. The Office System Developers Conference featured more than 60 breakout sessions that cover little pieces of Office development and organized solutions in eight technical tracks. You can find the videos for each track here:

    Microsoft Office System Developers Conference 2006 Videos:

    The videos are awesome! I am sure you will be very happy to watch them. However, keep in mind the following:

    • The videos are long. Some of them are over 70 minutes, so if you don't have time to watch them online, you can right-click on the title and save them to your hard drive for watching later.
    • These videos are raw unedited footage of the actual conference sessions, so some of them start with some notes about evaluating sessions, shuttles, "shut down your cell phones" and so on.  You will find notes on MSDN clarifying when the actual session begins (only for videos with long intros).

    I hope you have fun watching them and learn more about what's new in Office.


  • Erika Ehrli - Adventures with Office Products & Technologies

    10 News from Office DevLand


    I have been working in all sort of after Beta 2 projects and I couldn’t blog for the last two weeks. I missed my blog! While I was getting other things rolling, I kept a little blog to-do list with some things I wanted to share with you and now ten potential blog entries were turned into a single blog entry that looks more like a newsletter.

    Here goes a list of ten new cool things from Office DevLand that you should not miss.

    1.       New Office Live Channel 9 interview:  This Channel 9 video is great because it shows you what is Office Live and why should developers care. You will be able to watch how it works and how to get it.

    2.       New Office Live Developer Portal: We launched recently a new page on MSDN where we will start to add new content that shows how-to build solutions using Office Live.

    3.       New Office Small Business Accounting blog for developers: Martha  Arellano, who is a Software Design Engineer, started a new blog where she plans to share cool code to build SBA solutions. She wrote a cool blog entry where she shows how-to implement the ISdkAddInDriver interface.

    4.       Outlook 2007 and Getting Things DoneGetting Things Done is a set of best practices and tools used to help you to manage all your tasks/projects,  have drive to results, and be efficient to manage your time. Outlook 2007 contains a set of features that help you practice this methodology and Melissa MacBeth wrote a great blog entry where she explains how-to get started with Getting Things Done in Outlook 2007.

    5.       New Ribbon Extensibility Channel 9 interview: Savraj Dhanjal and Eric Faller talk to Scoble and show you how to write code to extend the Ribbon. Loved this interview!

    6.       What You Need To Know About Using Office As A Development Platform: Great MSDN magazine article written by Andrew Whitechapel and John Peltonen. The article talks about the range of fundamental requirements that make Office a serious development platform.

    7.       Office Business Applications + Office SharePoint Server = LOBI:  LOBI and OBA were announced at Tech Ed this year. If you want to learn more about the business applications you can create using these technologies, read the Building Office Business Applications white paper written by Javed Sikander and visit the new OBA Developer Portal.

    8.       Develop without Borders Challenge:  If you are a passionate developer, want to experiment with Office 2007, and love to help others, register to the Developer Without Borders Challenge.  The goal of this contest is to design an application on the Microsoft 2007 Office system. There are cool prizes, but the best part is that you can help solve a business problem for a charity.

    9.       2007 Office System resources: Here is a list of all the 2007 Office System and new technologies product portals  where you can find the latest articles, code samples, and videos by product:

    ·         Programs

    o   Access 2007

    o   Excel 2007

    o   InfoPath 2007

    o   Outlook 2007

    o   PowerPoint 2007

    o   Project 2007

    o   Small Business Accounting

    o   Word 2007

    ·         Servers

    o   SharePoint Server 2007

    o   Project Server

    ·         Services

    o   Office Live

    ·         Tools & Technologies

    o   Visual Studio Tools for Office

    o   XML in Office 2007

    o   .NET in Office 2007

    o   Office Business Applications

    o   Ribbon

    o   Windows SharePoint Services

    ·         Office Integration

    o   Unified Communications Developer Portal


    You can also download the updated developer help files for the Microsoft 2007 Office System here.

    Office World Cup Tools: I know the World Cup is over, but I could not stop giving a mention to ALX AND1N0 from El Salvador for developing this amazing World Cup Tracker in Excel, this is a great sample of someone who is really passionate of Excel development. He localized the application and used cool macros. Also, check out another cool World Cup tracker application in Access developed by Marteen Van Reek and he also shares the final statistics and images from the World Cup. Very cool!

    Finally,  I have an amazing surprise for all of you: We have been working on publishing something VERY cool, but we have had so much content on our queue for the last months, that we had to wait a little bit to get this live. Sometime very soon, you will find something AMAZING on the MSDN Office Develop Center. I will blog again once we go live, since I am sure you will be delighted!

    See you around,


  • Erika Ehrli - Adventures with Office Products & Technologies

    2007 Office System: Developer Posters


    Have you seen the .NET Framework posters for developers? I love them! There are tons of marketing posters, of course, but the ones I find quite useful are roadmap and object model posters. The roadmap posters organize different technologies in a way that helps you understand how everything works together. Object model posters on the other hand, provide a graphic view of top level namespaces and key objects and are great in-the-wall reference documentation. If you have a bad memory (like me) and you just can’t find a way to memorize methods, properties, and events for each namespace of the .NET framework, you might need one of this posters.

    Office development is a huge story, we have lots of products and inside each product, tons of objects and namespaces. We have been working on three posters that cover some key technologies related to Office development and we published last week the first two posters

    • Developer Map for SharePoint Products and Technologies: It’s hard to place something big as SharePoint on a limited squared space. However, Mike Ammerlan found a great way of doing this and designed a great roadmap that was later transfomed into a poster. For me the value of this poster is that it helps you understand the difference between Windows SharePoint Services "v3" and the new Microsoft Office SharePoint Server 2007.


    I think posters are a great option to help you get started and understand the overall picture of a new technology, they are also good elements for decorating your walls. If you have feedback related to the posters, please let me know. We are still working on the last one, so feedback is quite valuable at this point.



  • Erika Ehrli - Adventures with Office Products & Technologies

    Open XML File Formats: What is it, and how can I get started?


    While being at Tech Ed, a lot of people were interested in finding a way to programmatically generate documents without Interop. Some of the business scenarios contemplated generating over 5,000 documents and some IT professionals were interested in finding the best option. A great option to solve this business need is: The Open XML File Formats.

    Some people have been following the news and are even ahead of most of us already building solutions to generate documents using the Open XML File Formats. Some other people are not familiar with this technology and want to learn more about this, so here is a quick introduction for those of you who want to learn more about: What is it, and how you can get started. I have to warn you that this is going to be a long blog entry, but I promise it's worth the reading.

    What is it?

    The new formats improve file and data management, data recovery, and interoperability with line-of-business systems. They extend what is possible with the binary files of earlier versions. Any application that supports XML can access and work with data in the new file format. The application does not need to be part of the Microsoft Office system or even a Microsoft product. Users can also use standard transformations to extract or repurpose the data. In addition, security concerns are drastically reduced because the information is stored in XML, which is essentially plain text. Thus, the data can pass through corporate firewalls without hindrance.

    The new Open XML File Formats take advantage of the Open Packaging Conventions, which describe the method for packaging information in a file format and describe metadata, parts, and relationships. The new Open XML Format, with a few minor exceptions, is written entirely in XML and is contained in a .zip file. This creates significant advantages over the old binary file format:

    • The file size is much smaller because of ZIP compression.
    • The file is much more robust because it is broken up into different document parts. Should one part become damaged (for example, a part describing headers), the rest of the document remains intact and still opens successfully.
    • The file is easier to work with programmatically because of the new structure. For example, it is easier to access embedded content, such as images, because they are stored in their native format inside the file.
    • Custom XML is also easier to work with because it is stored in its own part, separate from the XML that describes the bulk of a document.

    The old binary file format was created when priorities in software differed from the priorities of today. Back then, the ability to transfer a Word document from computer to computer using a floppy disc ranked very high, and the tight structure of a binary format worked well. As software advanced, other priorities became clear, such as the ability to write code against a file format and make it as robust as possible. XML is a clear solution.

    Microsoft began to address this issue in previous versions of Microsoft Office by introducing SpreadSheetML and WordprocessingML. However, only now, with the 2007 release of Microsoft Office, have the goals that were conceived as far back as 1999 been accomplished fully. By including the XML File Format inside a ZIP container, the benefit of a small compressed file format is also realized. Excel 2007 and PowerPoint 2007 share this new file format technology, described by the Open Packaging Conventions. Together, the shared formats are called the Microsoft Office Open XML Formats. The new Word 2007 XML Format is the default file format, although the old binary file format is still available in the 2007 Microsoft Office system.

    An easy way to look inside the new file format is to save a Word 2007 document in the new default format and then rename the file with a .zip extension. By double-clicking the renamed file, you can open and look at its contents. Inside the file, you can see the document parts that make up the file, along with the relationships that describe how the parts interact with one another. However, it is important to note that, with a few exceptions defined within the Open Packaging Conventions, the actual file directory structure is arbitrary. The relationships of the files within the package, not the file structure, are what determine file validity. You can rearrange and rename the parts of an Word 2007 file inside its .zip container if you update the relationships properly so that the document parts continue to relate to one another as designed. If the relationships are accurate, the file opens without error. The initial file structure in a Word 2007 file is simply the default structure created by Word. This default structure enables developers to determine the composition of Word 2007 files easily.

    Contents of a sample document in a ZIP file

    How can I get started?

    The easiest way to modify a Word 2007 XML file programmatically is to use the System.IO.Packaging class in the Microsoft® Windows® Software Development Kit (SDK) for Beta 2 of Windows Vista and WinFX Runtime Components. Using this technology, you can easily update header and footer files programmatically across numerous Word 2007 documents stored on a server.

    We published recently some resources that might be of your interest if you are trying to learn more about the Open XML File Formats:

    Open XML Snippets

    • Open XML: Get OfficeDocument Part: Given an Open XML file, retrieve the part with the relationship type.

    Microsoft Office Excel Snippets

    • Excel: Add Custom UI: This snippet adds a custom UI Ribbon part to a given workbook.
    • Excel: Delete Comments by a specific User: This snippet deletes all comments from a given user from a given workbook.
    • Excel: Delete Worksheet: This snippet deletes the specified worksheet from within a given workbook and resets the selected worksheet to the next one on the list. Returns true if successful, false if failure.
    • Excel: Delete Excel 4.0 Macro sheets: This snippet deletes all the Excel 4.0 Macro (XLM) sheets from a given workbook.
    • Excel: Retrieve hidden rows or columns: This snippet returns a list of hidden row numbers or column names from a given workbook and worksheet.
    • Excel: Export Chart: Given a workbook and title of a chart, this snippet exports the chart as a Chart (.crtx) file.
    • Excel: Get Cell Value: Given a workbook, worksheet and cell address, this snippet returns the value of the cell as a string.
    • Excel: Get Comments as XML: Given a workbook, this snippet returns all the comments as an XmlDocument.
    • Excel: Get Hidden Worksheets: This snippet returns a list containing the name and type of all hidden sheets in a given workbook.
    • Excel: Get Worksheet Information: This snippet returns a list containing the name and type of all sheets in a given workbook.
    • Excel: Get Cell for Reading: Given a workbook, worksheet and cell address, this snippet demonstrates how to navigate to the cell to retrieve its contents. The cell must exist for the function to find it.
    • Excel: Get Cell for Writing: Given a workbook, worksheet and cell address, this snippet demonstrates how to navigate to the cell to set its value. If the cell does not exist, the snippet creates it.
    • Excel: Insert Custom XML: Given a workbook and a custom XML value, this snippet inserts the custom XML into the workbook.
    • Excel: Insert Header or Footer: Given a workbook, worksheet and text to insert and a header or footer type, this snippet inserts the header or footer with the given text into the worksheet.
    • Excel: Insert a Numeric Value into a Cell: Given a workbook, worksheet, cell address and numeric value, this snippet inserts the value into the cell.
    • Excel: Insert a String Value into a Cell: Given a workbook, worksheet, cell address and string value, this snippet inserts the value into the cell.
    • Excel: Set Recalc Option: Given a workbook and a RecalcOption, this snippet sets the recalculation property to the new option.

    Microsoft Office PowerPoint Snippets

    • PowerPoint: Delete Comments by User: Given a presentation and a user name, this snippet deletes all comments by that user.
    • PowerPoint: Delete Slide by Title: Given a presentation and slide title, this snippet deletes the first instance of a slide with that title (titles are not unique).
    • PowerPoint: Get Slide Count: This snippet returns the number of slides in a given presentation.
    • PowerPoint: Get Slide Titles: Given a presentation, this snippet returns a list of the slide titles in the order presented.
    • PowerPoint: Modify Slide Title: Given a presentation, old slide title, and new slide title, this snippet changes the first instance of a slide with the given title to the new value. The snippet returns true if successful, false if not successful.
    • PowerPoint: Reorder Slides: Given a presentation, an original position, and a new position, attempt to place the slide from the original position into the new position within the deck. If the original position is outside the range of the number of slides in the deck, use the last slide. If the new position is outside the range of slides in the deck, put the selected slide at the end of the deck. The snippet returns the loctation wher the slide was placed, or -1 on failure.
    • PowerPoint: Replace Image: Given a presentation, slide title and image file, this snippet replaces the first image on the slide with the given image.
    • PowerPoint: Retrieve Slide Location by Title: Given a presentation and a slide title, this snippet returns the 0-based location of the first slide with a matching title.

    Microsoft Office Word Snippets

    • Word: Accept Revisions: Given a document and an author name, this snippet accepts the revisions by that author.
    • Word: Add Header: Given a document and a stream containing valid header content, add the stream content as a header in the document.
    • Word: Convert DOCM to DOCX: Given a macro-enabled document (.docm), this snippet removes the VBA project and converts the file to a macro-free Word Document (.docx).
    • Word: Remove Comments: Given a Word Document, this snippet removes all the comments.
    • Word: Remove Headers and Footers: This snippet removes all headers and footers from a given Word document.
    • Word: Remove Hidden Text: This snippet removes any hidden text in a given document.
    • Word: Replace Style: Given a document and valid header content, this snippet adds the content as a header in the document.
    • Word: Retrieve Application Property: Given a document name and an app property, this snippet returns the value of the property.
    • Word: Retrieve Core Property: Given a document name and a core property, this snippet returns the value of the property.
    • Word: Retrieve Custom Property: Given a document name and a custom property, this snippet returns the value of the property.
    • Word: Retrieve Table of Contents: Given a document name, this snippet returns a table of contents as an XmlDocument.
    • Word: Set Application Property: This snippet sets a property’s value given a document name, application property and value. The snippet returns the old value if successful.
    • Word: Set Core Property: Given a document name, a core property, and property value, this snippet sets the property value.
    • Word: Set Custom Property: Given a document name, a custom property, and a value, this snippet sets the property’s value. If the property does not exist, create it. Returns true if successful, false if not.
    • Word: Set Print Orientation: Given a document name, this snippet sets the print orientation for all sections in the document.

    Download them here!

    Finally, if you want to stay current with new resources to work with the Open XML File Formats, go to the XML in Office Developer Portal. We launched this portal recently to create a special section of the MSDN Office Developer Center where you will find bloggers, technical articles, code samples, developer documentation, and multimedia presentations on working with XML in Office.

    Happy Office XML programming!
  • Erika Ehrli - Adventures with Office Products & Technologies

    Tech Ed 2006 Pictures (Office System)


    I loved Tech Ed this year! Office 2007 is driving a lot of awareness and I was happy to be there to experience that. I was hanging out at the Visual Studio Tools for Office booth and I enjoyed a lot talking to Partners, MVPs, ISVs, and IT professionals that wanted to learn more about VSTO v3 and the 2007 Microsoft Office System. For me it's always fascinating to listen about development projects related with Office. I go there thinking I will be able to share some knowledge, but it's always people who teach me about new things and I enjoy taking about great ideas for tools, software development projects, third-party components and listen to feedback about things we could be doing better.

    Here are some pictures that I wanted to share with you:

    The Office System lounge was full at all times. We had demos about InfoPath, SharePoint Designer, SharePoint Server, VSTO, Groove, Visio, Office Professsional, and more.

    I could see people were quite interested about new products and technologies, but overall, I saw a lot of interest of people to start experimenting and learning how to work with:

    • Excel Services
    • InfoPath Web based forms
    • Open XML File Formats
    • SharePoint Designer
    • SharePoint Enterprise Content Management
    • Integration of Windows Workflow Foundation and SharePoint
    • Outlook new object model
    • Working with Web parts and SharePoint
    • SharePoint Server 2007

    Chalk Talks about SharePoint products and technologies and 2007 Office System were delivered every 20 minutes. What I like about Chalk talks is that you get to see few slides and great demos. Since the audience is small, you can shoot questions to the speaker. I loved this format and enjoyed hanging out to watch some of them.

    Here I am with Randy Byrne, Ryan Gregg, and Tom Devey. We were sharing the VSTO booth and had a lot of fun together. We were giving out the 7 Development Projects for Microsoft Office SharePoint Server 2007 and Windows SharePoint Services 3.0 book as pancakes, and the funniest part is that we ran out of copies for ourselves!

    Randy and I celebrated our birthdays wearing the blue uniform.

    Boston is a beautiful city and there are lots of good spots to take pictures. I took this picture outside the New England Acuarium, where the Office team was throwing a party for Office and SharePoint MVPs and Partners.
    Here we are at the 2007 Office System MVP & Partner Appreciation Party having fun, talking, and having lobster for dinner! I am sure the Office and SharePoint MVPs and Partners enjoyed being here. 
    Jay Paulus, Heather Newman, Justin Chandoo, and Sarah Jamieson planned all the logistics for everything that had to do with the Office System at Tech Ed 2006. They worked a lot to make everything perfect and they were very happy as you can see.
  • Erika Ehrli - Adventures with Office Products & Technologies

    Tech ED 2006: News for Office and SharePoint Developers


    I am here at Tech ED at Boston and I am having a lot of fun talking to developers and IT professionals who want to learn more about Office 2007, Office SharePoint Server 2007, and Visual Studio Tools for Office.

    We have an Office System booth area where you can find experts for different Office and SharePoint products and technologies. I am at the Visual Studio 2005 Tools for the Microsoft Office System booth and we are running demos to show some of the coolest things you can do with VSTO. We are also answering questions about the Open XML File Formats (people are quite interested in that and are asking and asking).

    If you are here at Tech ED visit the Office booth, I love to talk to people and listen to the approaches used to solve business needs using different Office products and technologies. Also we are providing some handouts that you might interested in such as...

    For people who are not here I will write another blog entry tomorrow with some pictures and a list of available resources on the MSDN Office Developer Center where you can find developer information covered at most of the current Tech Ed Office sessions, chalk talks, and hands on labs.

  • Erika Ehrli - Adventures with Office Products & Technologies

    Blogs for the Office blog lovers


    Blogs are a fantastic way to get news to the community. I am sure the developer community is quite aware of everything that is going on with the new version of Office thanks to all the -very nice- people that are blogging about new enhancements and features for different Office programs, servers, services, tools, and technologies.

    I made a blog entry some time ago where I shared a list of Office 2007 (12) bloggers and I was surprised to see that some people enjoyed the list. It was my personal commitment to make this go a step further, and so I made my new sport to start pulling Office bloggers' RSS feeds on the MSDN Office Developer Center.

    We currently have 89 different bloggers pulled across the site, and I am sure we missed a lot! My goal is to add internal and external Office bloggers to the list as soon as I discover them.

    The complete list of Office bloggers is listed on the Community - Blogs page. You can also find bloggers who are talking about specific products and technologies on the different Community pages:

    These are only some of the pages, you will see I got the RSS fever and you will find blogs everywhere!

    If you think we missed a great Office blogger that we should list, please let me know. Blogs are born every day and I will be glad to continue growing the list. I am sure I forgot about great Office bloggers like Don Campbell!

    Report Office bloggers here and enjoy!


  • Erika Ehrli - Adventures with Office Products & Technologies

    How-to enable the Developer tab in the Ribbon bar


    I am a new user to Office 2007 (Beta 2) and I am having fun discovering things around. If you already downloaded the 2007 Microsoft Office system Beta 2 and you are ready to start experimenting with Office, here is a nice trick related to the very cool Ribbon bar.

    The Ribbon provides a Developer tab that groups a set of commands related to Office programmability and extensibility. The following figure shows the Developer Ribbon (Word 2007).

    Developer tab in the Ribbon UI

    By default, the Developer tab is disabled. Why? My personal guess: Regular end-users don't know about Office programmability and extensibility, so they might never use the Developer tab. On the other hand, developers are a different set of users that have a completely distinct way of working with programs, solving problems, and discovering things. Developers have a great research spirit and will easily find how-to enable the Developer tab. Here's how...

    To show the Developer tab

    1. Open a 2007 Office System application, for example Word 2007.
    2. Click the Microsoft Office Button, and then click Word Options.
    3. In the Top options for working with Word section of the Word Options dialog box, click Personalize.
    4. Select Show Developer tab in the Ribbon, as shown in the next figure.
    5. Click OK.

      The Word Options dialog box

      Note   When you are in developer mode, you see the Developer tab in the Ribbon UI.

    Once you get this running and start playing around, the next step is to start researching about extending the Ribbon. You can extend the Ribbon to show custom tabs and command chunks. The new Ribbon page inside MSDN contains great resources (blogs, videos, articles and downloads) that will allow you to get started with extending the Ribbon.

    Don't miss Frank's articles and blog, he is a great writer and will be sharing more on extending the Ribbon with you guys.

  • Have fun with the Beta,


  • Erika Ehrli - Adventures with Office Products & Technologies

    Football World Cup 2006 Excel workbooks


    Have you ever thought about all the data that is stored in Microsoft Office Excel workbooks around the world? Excel workbooks are an extraordinary data store, but they also offer great potential as a resource of dynamic information that can move across data-management workflows and business processes.

    The previous paragraph was stolen from my last column. Of course, when I wrote this article I was not thinking about some other cool and interesting data that you can store in Excel workbooks. My mind is set to think about Office programs as work-related applications and I am always thinking about ways that will help developers discover cool features (such as SpreadsheetML) to solve business problems. I sometimes forget about all the fun that applications like Excel can provide.

    The 2006 Fifa World Cup is starting this month, and some people are starting to create Excel templates that can help you keep track of the results of the game matches for you.

    You can download the 2006 World Cup Tracker. An Excel template published recently on Office Online (English version).

    I am also attaching a very cool Excel workbook (Mundial 2006) that my friend Juan Balmori from Mexico shared with me. This Excel workbook helps to track game statistics and is a great option if you are looking for a template in Spanish.

    Also, Franck Halmaert, the Office PM in France, sent me this great link for a French version.

    Have fun watching the games and forget about work for a while :).

  • Erika Ehrli - Adventures with Office Products & Technologies

    What's new for developers in the 2007 Microsoft Office System?


    Hi everyone!

    I had to stop blogging for a while because we were working on building an improved MSDN Office Developer Center. However, I will blog a lot starting from today to let you know about resources, developer tips, and best practices for the 2007 Microsoft Office System.

    The 2007 Microsoft Office System Beta 2 was announced today! We have been working a lot on creating new Office 2007 content and to redesign the site and here are some pointers to resources you should see!

    Check out..

    I will be blogging shortly about specific content items. In the meantime enjoy!

  • Erika Ehrli - Adventures with Office Products & Technologies

    New Office Live Blog and 2007 Microsoft Office System demos


    The Office Live thing...

    If you want to learn more about Office Live, you should not miss Chris Beiter's blog. Chris is a Program Manager on the Solution Developer Platform portion of Office Live's next release. So for those of you who are interested in the developer story for Office Live, stick around Chris's blog.

    The Office 2007 Demo thing...

    Have you seen the MSDN TV shows published recently? If you can't wait to get to the demo, here are the links that jump into the fun part:

    Access show

    Excel show

    SharePoint show  

    Have a great weekend!


  • Erika Ehrli - Adventures with Office Products & Technologies

    How to: Magic with SharePoint 2003, uploading files using a Web service


    Some time ago I blogged about my intentions of uploading files to a SharePoint Document Library site from a local folder using some kind of Web service. After doing some research and some tests, I found a very easy way to do that and now I want to share with you the approach I followed since you might find it useful as well.


    To build this solution, you need to install Office SharePoint Portal Server 2003 and follow the next steps:

    • Create a Document Library
    • Grant access to the users that will upload files to the Document Library:

    To install the Web service:

    1. Download ODC_WritingCustomWebServicesSampleSPPT.EXE.
    2. Extract the download contents to your hard drive and Run build.bat.
      • Note: This will install the Web service on the _vti_bin virtual directory inside the Default Web Site.
    3. Open the IIS Management Console (INETMGR) and navigate to the the _vti_bin virtual directory (inside the Default Web Site).
    4. Find SPFiles.asmx, right click, and Browse.
    5. Navigate to http://localhost/_vti_bin/SPFiles.asmx to validate if you have installed successfully the Web Service.

    To consume the Web Service:

    1. From your managed application, add a reference to the http://localhost/_vti_bin/SPFiles.asmx Web Service.
    2. Call the Web service DocumentLoader
    3. Create a helper class to upload files. You can use the helper class I created.
      using System;

      /// <summary>
      /// A sample SharePointHelper class to upload files
      /// </summary>
      public class SharePointUploadHelper {
      private string _sharepointDocumentLibrary;

      SharePointUploadHelper() {

      public string UploadDocumentsToSharePoint(string fileName) {

            DocumentLoader.SPFiles svcDocLoader 
      = new DocumentLoader.SPFiles();
      svcDocLoader.PreAuthenticate = true;
      svcDocLoader.Credentials CredentialCache.DefaultCredentials;

      strPath fileName;
      strFile strPath.Substring(strPath.LastIndexOf("\\") + 1);
      strDestination _sharepointDocumentLibrary;

      FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open);
      [] binFile = new byte[(int)fStream.Length];
      fStream.Read(binFile, 0, (int)fStream.Length);
      result svcDocLoader.UploadDocument(strFile, binFile, strDestination);

    4. Create a Web Form, Win Form, or console application that will require a user to upload files.
    5. Call the UploadDocumentsToSharePoint method of the SharePointUploadHelper class, for example:
      protected void btnLoadFile_Click(object sender, EventArgs e)
              SharePointUploadHelper fh 
      = new SharePointUploadHelper();
      serverTempFilePath Server.MapPath(@"/yourApplication");
      lblUploadResults.Text fh.UploadDocumentsToSharePoint(serverTempFilePath);
    6. Open the configuration file (i.e. Web.config) and turn on impersonation.
      <identity impersonate="true" />
    7. Add a configuration key that points to the SharePoint Document Library where you will upload files.
      <add key="SharePointDocLibrary" value="http://myServerName/myDocumentLibrary"/>
    8. Build your application
    9. Run and test the application, and there, a great web service.

    I can tell you it works, just keep in mind the download is a code sample.



  • Erika Ehrli - Adventures with Office Products & Technologies

    More news on 2007 Microsoft Office System


    Hi all,

    Just a little blog entry to let you know about a new MSDN TV show and a new section of MSDN where we will start adding 2007 Microsoft Office System content.

    The new MSDN TV Show: Building Custom Solutions with Excel Services

    Danny Khen and Shahar Prish recorded an MSDN TV show about Excel Services that you should not miss.

    Danny Khen and Shahar Prish talk about and demonstrate Excel Services.




    Excel Services let users calculate, display, and explore Excel workbooks on the server side. This presentation covers the reasons behind Excel Services, the benefits of using them, and a demonstration of using a Web service to incorporate Excel-based business logic into your own server solutions.

    Danny and Shahar start by talking about the new features and potential development scenarios where you can use Excel Services and close their show with a great demo where you get to see some code. They run an ASP.NET web form that queries an Excel Spreadsheet using Excel Services.

    Future Versions

    Last Friday we launched a new page where we will start adding 2007 Office System content. Visit the Future Versions page to learn more about what's new for developers in the 2007 Microsoft Office System.



  • Page 6 of 8 (188 items) «45678