Lets Learn

Opinion Matters

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 7 other followers

  • Blog Stats

    • 72,499 hits
  • Ankush

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

libOPC version 0.0.1 is released

Posted by Ankush on April 25, 2011

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

Text taken from above article:

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

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

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

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

For full read, click on the above link!!

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

Debug a SharePoint Workflow

Posted by Ankush on April 25, 2011

Its been a while since I blogged anything. Main reason was, I was on vacation and since then I have come back, I was really really busy.  It was really good to visit places like Mathura and Muzaffarnagar (my birthplace). Anyway, here I am with my first blog after my vacation.

Recently I worked on case where customer has developed a workflow to send multiple emails (using SMTP Server) when an item was added to the list. The workflow was getting fired but it sending emails only for the first list item. For the second list item, it was kind of stuck(because there was no email sent for the second list item and so forth).

I started with very basic troubleshooting steps, like checking ULS logs, Event Viewer and nothing major was there.  I wish I could have debugged the workflow but it was not possible to install Visual Studio on the problematic server. I wish I could have got workflow debug information and then I got one. As we know it is very painful to debug the workflow. So the easy thing is, open
the web.config and have these entries present

<system.diagnostics>
<switches>
<add name=”System.Workflow LogToFile” value=”1″ />
<add name=”System.Workflow.Runtime” value=”All” />
<add name=”System.Workflow.Runtime.Hosting” value=”All” />
<add name=”System.Workflow.Runtime.Tracking” value=”All” />
<add name=”System.Workflow.Activities” value=”All” />
<add name=”System.Workflow.Activities.Rules” value=”All” />
</switches>
</system.diagnostics>
</configuration>

This will create a log file under C:\WINNT\system32\inetsrv.

Once you have the log file, you can view what activates being executed and if there was any error. And this really helped.  I was able to pin point one activity where the second workflow instance was stuck and it turns out that customer was keeping a constant task id. We changed this to create an new one for each workflow instance and it worked.

Try this in your workflow projects and see if this helps!! And if it does, post a comment here.!!!

Posted in Sp 2007 | Tagged: , , , | Leave a Comment »

How to Insert a Hyperlink in Excel using Open XML SDK 2.0

Posted by Ankush on March 4, 2011

Consider a scenario, you want to insert a hyperlink in Excel 2010 (or Excel 2007) file programmatically using a web application. You should not use Office Object Model in a web application, Please refer http://support.microsoft.com/kb/257757. So what we can do??

As we know that Office 2007 and 2010 file format is XML based (just rename any Office 2007/2010 document to .zip and you can see a lots of XML files which makes a document and they are simply zipped in a one file). To manipulate these files, MS has introduced a library, Open XML SDK 2.0. The SDK is built on the System.IO.Packaging API and provides strongly-typed classes to manipulate documents that adhere to the Office Open XML File Formats Specification. The Office Open XML File Formats specification is an open, international, ECMA-376, Second Edition and ISO/IEC 29500 standard. The Open XML file formats are useful for developers because they are an open standard and are based on well-known technologies: ZIP and XML.

The Open XML SDK 2.0 simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML SDK 2.0 encapsulates many common tasks that developers perform on Open XML packages, so that you can perform complex operations with just a few lines of code. Some benefits if you use Open XML SDK:

Open Format: These formats use XML and ZIP, and they are fully documented. Anyone can get the full specs on the formats and it is a royalty free license for anyone that wants to work with the files.

Compressed: Files saved in these new XML formats are less than 50% the size of the equivalent file saved in the binary formats. This is because we take all of the XML parts that make up any given file, and then we ZIP them. We chose ZIP because it’s already widely in use today and we wanted these files to be easy to work with.

Robust: Between the usage of XML, ZIP, and good documentation the files get a lot more robust. By compartmentalizing our files into multiple parts within the ZIP, it becomes a lot less likely that an entire file will be corrupted (instead of just individual parts). The files are also a lot easier to work with, so it’s less likely that people working on the files outside of Office will cause corruptions.

Backward compatible: You don’t have to use the new version of Office to take advantage of these formats. You can use Office Compatibility pack to open the Office 2007 document in older version.

Binary Format support: You can still use the current binary formats with the new version of Office. In fact, people can easily change to use the binary formats as the default if that’s what they’d rather do.

New Extensions: The new formats has new extensions (.docx, .pptx, .xlsx) so you can tell what format the files you are dealing with are, but to the average end user they’ll still just behave like any other Office file. Double click & it opens in the right application.

Is also important to know that what SDK CAN’T do:

The Open XML SDK 2.0:

  • Does not replace the Microsoft Office Object Model and provides no abstraction on top of the file formats. You must still understand the structure of the file formats to use the Open XML SDK 2.0.
  • Does not provide functionality to convert Open XML formats to and from other formats, such as HTML or XPS.
  • Does not guarantee document validity of Open XML Formats when you use the Open XML SDK 2.0 or if you decide to manipulate the underlying XML directly.
  • Does not provide application behavior such as layout functionality in Word or recalculation, data refresh, or adjustment functionalities in Excel.

So lets have a look at the solution. I will try to build the solution from the scratch so that you can learn how you can use Open XML tools and leverage this information in other exercise as well.

So lets start!!

Step 1: Download the Open XML SDK and the tool from http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en. Please note that there are 2 links, one is for the tool and the second one is the actual library.

Step 2: So the objective is to insert a link into a cell. For the simplicity, we will assume that we want to insert the link into cell A1 of Sheet1. Lets create an Excel 2010 workbook and place a hyperlink in cell A1 manually. Once done, Excel file will look like this

clip_image001

Save this file and close it.

Step 3: If you haven’t changed the default installation location of the tool, they will appear here: C:\Program Files (x86)\Open XML SDK\V2.0\tool. Go ahead and run OpenXmlSdkTool.exe from here.

Step 4: You can simply open Office file in this tool and look at the different XML parts. (To understand different XML parts, have a look:https://ankushbhatia.wordpress.com/2010/03/04/basics-of-spreadsheet/). So go ahead and open the file in this tool. Once done, it will look like this:

clip_image002

Step 5: We know that we inserted the hyperlink in cell A1 of Sheet1 so go ahead and browse the Sheet1.xml file. Once you select the Sheet1, it gives you different child elements of it. Please select hyperlinks and click on “reflect Code” to view the XML. Make sure to follow the correct tree structure to get to Sheet1.xml and hyperlink object. After this, it will appear as:

clip_image003

Pay attention to the right side. There are 2 windows. Upper window shows XML of the section you have selected in the “Document Explorer” and the bottom window shows the C# code to generate the XML..Kind of cool….isn’t?? So now what we have..? We have XML which is required to generate a hyperlink and the equivalent C# code. Lets have a closure look at the XML

<x:hyperlinks xmlns:x=”http://schemas.openxmlformats.org/spreadsheetml/2006/main”&gt;

<x:hyperlink ref=”A1″ r:id=”rId1″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships&#8221; />

</x:hyperlinks>

There is no information about the hyperlink text. If you look at the relationship ID “A1″, it appears as

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”true”?>

<Relationships xmlns=”http://schemas.openxmlformats.org/package/2006/relationships“><Relationship TargetMode=”External” Target=”http://www.microsoft.com/” Type=”http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink” Id=”rId1″/></Relationships>

So where is the actual text (remember I entered Microsoft)?

As you know that Excel keeps all the text strings in a separate XML file, SharedSTring.xml and refer it back based on the index. So lets see how the data appear in cell A1

Have a look at the SheetData [where it keeps all the data . It is specific to a sheet] in the tool

clip_image004

If you look at the XML, it contains the information about the row which contains the data.

<x:sheetData xmlns:x=”http://schemas.openxmlformats.org/spreadsheetml/2006/main”&gt;

<x:row r=”1″ spans=”1:1″ x14ac:dyDescent=”0.25″ xmlns:x14ac=”http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac”&gt;

<x:c r=”A1″ s=”1″ t=”s”>

<x:v>0</x:v>

</x:c>

</x:row>

</x:sheetData>

Lets try to decode it.

<x:row r=”1″ spans=”1:1″ x14ac:dyDescent=”0.25″ xmlns:x14ac=”http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac”&gt; :

r=1 means there is one row.

There is one child element <x:c r=”A1″ s=”1″ t=”s”>.

X:c -> Column
r=A1 -> Referenced cell is “A1″

S=1 and t=”S” it’s a string value and value is referenced from Shared String table. And S=1 means that a style is applied and the defination of the style is taken from index 1 which can be found from Style.xml

Now analyze the SharedSTring.XML using the same tool

clip_image005

Here you will see the Microsoft string. It is referred back in SheetData using x:v node. The starting index is 0.

So to summarize, we need to do:

  1. Create a hyperlink object and insert it before the PageMargin node. Please note that Excel is enforcing a strict ordering of the elements. So make sure to add it before PageMargines node.
  2. Create an entry in the SharedString Table
  3. Create an entry in the SheetData section

So why we did this exercise. Every now and then we face situation where we want to these kind of things in Office using Open XML. So easy thing is, do the stuff in UI and analyze the XML and C# code and then write your own.

Lets move on and utilize this information.

Step 6: Create a new Excel file and save it. We will insert a hyperlink in this file. Create a new VS 2010 project and open the new blank file.

Step 7: Add a reference to DocumentFormat.OpenXML and WindowsBase.dll from .NET tab

Step 8: Add a namespace using XL = DocumentFormat.OpenXml.Spreadsheet;

Step 9: So basically you need to

a. Open the workbook
b. Get to the sheet where you want to add the hyperlink
c. Add the hyperlink
d. Add an entry in SheetData
e. Add an entry in SharedString.xml

The below code does exactly that.

using (SpreadsheetDocument document = SpreadsheetDocument.Open(@"C:\Users\abhatia\Desktop\Sample1.xlsx", true))

           {

               IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().Where(s => s.Name == "Sheet1");

               if (sheets.Count() == 0)

               {

                   // The specified worksheet does not exist.

                   return;

               }

               string relationshipId = sheets.First().Id.Value;

               WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(relationshipId);


               Hyperlinks hyperlinks1 = new Hyperlinks();

               Hyperlink hyperlink1 = new Hyperlink() { Reference = "A1", Id = "UNIQUE" };

               hyperlinks1.Append(hyperlink1);


               PageMargins pageMargins = worksheetPart.Worksheet.Descendants<PageMargins>().First();

               worksheetPart.Worksheet.InsertBefore<Hyperlinks>(hyperlinks1, pageMargins);

               worksheetPart.Worksheet.Save();

               worksheetPart.AddHyperlinkRelationship(new System.Uri("http://www.google.com/", System.UriKind.Absolute), true, "UNIQUE");


               // Create an element in SheetData


               // Get the SharedStringTablePart. If it does not exist, create a new one.

               SharedStringTablePart shareStringPart;

               if (document.WorkbookPart.GetPartsOfType<SharedStringTablePart>().Count() > 0)

               {

                   shareStringPart = document.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First();

               }

               else

               {

                   shareStringPart = document.WorkbookPart.AddNewPart<SharedStringTablePart>();

               }



               // Insert the text into the SharedStringTablePart.

               int index = InsertSharedStringItem("www.google.com", shareStringPart);


               // Insert cell A1 into the new worksheet.

               Cell cell = InsertCellInWorksheet("A", 1, worksheetPart);


               // Set the value of cell A1.

               cell.CellValue = new CellValue(index.ToString());

               cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);


               // Save the new worksheet.

               worksheetPart.Worksheet.Save();



           }

 

Here are the helper functions (taken from MS site):

// Given text and a SharedStringTablePart, creates a SharedStringItem with the specified text 

// and inserts it into the SharedStringTablePart. If the item already exists, returns its index.

private static int InsertSharedStringItem(string text, SharedStringTablePart shareStringPart)

{

    // If the part does not contain a SharedStringTable, create one.

    if (shareStringPart.SharedStringTable == null)

    {

        shareStringPart.SharedStringTable = new SharedStringTable();

    }


    int i = 0;


    // Iterate through all the items in the SharedStringTable. If the text already exists, return its index.

    foreach (SharedStringItem item in shareStringPart.SharedStringTable.Elements<SharedStringItem>())

    {

        if (item.InnerText == text)

        {

            return i;

        }


        i++;

    }


    // The text does not exist in the part. Create the SharedStringItem and return its index.

    shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(text)));

    shareStringPart.SharedStringTable.Save();


    return i;

}

 

// Given a column name, a row index, and a WorksheetPart, inserts a cell into the worksheet. 

       // If the cell already exists, returns it. 

       private static Cell InsertCellInWorksheet(string columnName, uint rowIndex, WorksheetPart worksheetPart)

       {

           Worksheet worksheet = worksheetPart.Worksheet;

           SheetData sheetData = worksheet.GetFirstChild<SheetData>();

           string cellReference = columnName + rowIndex;


           // If the worksheet does not contain a row with the specified row index, insert one.

           Row row;

           if (sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).Count() != 0)

           {

               row = sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).First();

           }

           else

           {

               row = new Row() { RowIndex = rowIndex };

               sheetData.Append(row);

           }


           // If there is not a cell with the specified column name, insert one.  

           if (row.Elements<Cell>().Where(c => c.CellReference.Value == columnName + rowIndex).Count() > 0)

           {

               return row.Elements<Cell>().Where(c => c.CellReference.Value == cellReference).First();

           }

           else

           {

               // Cells must be in sequential order according to CellReference. Determine where to insert the new cell.

               Cell refCell = null;

               foreach (Cell cell in row.Elements<Cell>())

               {

                   if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)

                   {

                       refCell = cell;

                       break;

                   }

               }


               Cell newCell = new Cell() { CellReference = cellReference };

               row.InsertBefore(newCell, refCell);


               worksheet.Save();

               return newCell;

           }

       }

 

Assumptions:

I have made several assumptions while writing code for this.

  1. I have assumed that Excel file is a new blank file i.e. there is no hyperlink present.
  2. Sheet1 name is hardcoded.
  3. File Name is Hardcoded.
  4. Can you think of anything by looking at the code? 🙂

Run this code and everything will work. When you will open the Excel sheet and click on the link, it will be treated as hyperlink.

But still one thing is missing. It is not underlined and appear in the blue color. Because you need to apply a style to do that. I leave this exercise to my readers to check how the styles are applied and how they can use this information. In case of anything, let me know 🙂

Please try this approch in every situation where you use Open XML and let me know in case of any questions.

Posted in Open XML SDK, Spreadsheet | Tagged: , , , | 9 Comments »

Question 8 # How to get the Return Values from Each Delegate in a Multicast Delegate

Posted by Ankush on March 3, 2011

Lets say you have created a multicast delegate.  You need to be able to access the return value of each delegate that is invoked in the multicast delegate.

How will you do that?

Posted in Questions | Tagged: , , | Leave a Comment »

Clear Office Clipboard Programmatically

Posted by Ankush on March 1, 2011

Lets say you are automating Word and looking for a way to clear an Office Clipboard.

image

Have a look in the left of the screen shot and it will show you the Office Clipboard. So you look into the Office Object Modal but there is no method/property to clear the clipboard.

Any solutions? Our old friend, win32 API come for the rescue.

Here is the solution:

Step 1: Declare the namespaces

   1: Imports Word = Microsoft.Office.Interop.Word

   2: Imports System.Runtime.InteropServices

 

Step 2:

Declare the local variables and APIs

   1: Private Const WM_LBUTTONDOWN As Long = &H201&

   2:    Private Const WM_LBUTTONUP As Long = &H202&

   3:

   4:    ' Variables to hold Word Objects

   5:    WithEvents oAppWD As Word.Application

   6:    Public oDoc As Word.Document

   7:

   8:    ' API to be used

   9:    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Int32)

  10:    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32

  11:    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32

  12:    Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32

  13:    Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Int32) As Int32

Step 3: Actual code

   1: Private Function MakeLong(ByVal nLoWord As Integer, ByVal nHiWord As Integer) As Int32

   2:        MakeLong = nHiWord * 65536 + nLoWord

   3:    End Function

   4:

   5:

   6:    Private Sub btnClearWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearWord.Click

   7:        Dim hMain As Int32, hWord As Int32, hClip As Int32, hWindow As Int32, hParent As Int32

   8:        Dim lParameter As Int32

   9:        Dim sTask As String

  10:        Dim HWND As Int32

  11:

  12:        'Open the selected File

  13:        oAppWD = DirectCast(System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"), Word.Application)

  14:        oAppWD.Visible = True

  15:        oDoc = oAppWD.ActiveDocument

  16:

  17:        oAppWD.Activate()

  18:        oDoc.Activate()

  19:        oDoc.ActiveWindow.SetFocus()

  20:        oDoc.ActiveWindow.Activate()

  21:

  22:        Sleep(2000)

  23:        MessageBox.Show("Doing it.....")

  24:

  25:        HWND = FindWindow("OpusApp", vbNullString)

  26:

  27:        ' Make Office Clipboard Visible

  28:        oAppWD.CommandBars("Office Clipboard").Visible = True

  29:

  30:        BringWindowToTop(HWND)

  31:

  32:        ' Get the handles of the respective Windows Of the Office 

  33:        sTask = "Office Clipboard"

  34:        hMain = HWND

  35:        hWord = FindWindowEx(hMain, 0, "MsoCommandBarDock", vbNullString)

  36:

  37:        hParent = hWord : hWindow = 0

  38:        hWindow = FindWindowEx(hParent, 0, "MsoCommandBar", sTask)

  39:        If hWindow Then

  40:            hParent = hWindow : hWindow = 0

  41:            hWindow = FindWindowEx(hParent, 0, "MsoWorkPane", vbNullString)

  42:            If hWindow Then

  43:                hParent = hWindow : hWindow = 0

  44:                '   hClip = FindWindowEx(hParent, 0, "bosa_sdm_Microsoft Office Word 12.0", vbNullString)

  45:                hClip = FindWindowEx(hParent, 0, "bosa_sdm_msword", vbNullString)

  46:

  47:

  48:            End If

  49:        End If

  50:

  51:

  52:        If hClip = 0 Then

  53:            MsgBox("Cant find Clipboard window")

  54:            Exit Sub

  55:        End If

  56:        ' Pass the message 120,18 are the respective co-ordinates of the Clear all button.

  57:        lParameter = MakeLong(120, 18)

  58:        ' Send the Message

  59:        Call PostMessage(hClip, WM_LBUTTONDOWN, 0&, lParameter)

  60:        Call PostMessage(hClip, WM_LBUTTONUP, 0&, lParameter)

  61:        Sleep(100)

  62:

  63:    End Sub

Try this and let me know how it goes for you Smile

Posted in Office 2007, Word | Tagged: , , , | 2 Comments »

Open XML SDK Learning Resources

Posted by Ankush on February 24, 2011

Open XML SDK 2.0 FAQ
http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/19032efe-80af-4a16-b954-1f5a6d2f2236

Building Office Open XML Files
http://msdn.microsoft.com/en-us/magazine/cc163478.aspx

Introducing the Office (2007) Open XML File Formats
http://msdn2.microsoft.com/en-us/library/ms406049.aspx

How to: Manipulate Office Open XML Formats Documents
http://msdn2.microsoft.com/en-us/library/aa982683.aspx#Office2007ManipulatingXMLDocs_creating

Building Server-Side Document Generation Solutions Using the Open XML Object Model
http://msdn.microsoft.com/en-us/library/bb735940.aspx (Part 1 of 2)
http://msdn.microsoft.com/en-us/library/bb735939.aspx (Part 2 of 2)

How to use the Office XML file format and the packaging components from the .NET Framework 3.0 to create a simple Excel 2007 workbook or a simple Word 2007 document
http://support.microsoft.com/?id=931866

How Do I…Open XML SDK v2.0
http://msdn.microsoft.com/en-us/library/bb491088(office.14).aspx

Nanipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Object Model (Part 1 of 2)
http://msdn.microsoft.com/en-us/library/bb739834.aspx

Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Object Model (Part 2 of 2)
http://msdn.microsoft.com/en-us/library/bb727373.aspx

Reading Data from SpreadsheetML
http://blogs.msdn.com/brian_jones/archive/2008/11/10/reading-data-from-spreadsheetml.aspx

How to use components of the .NET Framework 3.0 to create and then to stream an Office Word 2007 document and an Office Excel 2007 workbook to a client computer
http://support.microsoft.com/kb/932921

Welcome to the Open XML Developer Workshop
http://msdn.microsoft.com/en-us/office/bb738430.aspx

Open XML Explained e-book
http://openxmldeveloper.org/articles/1970.aspx

Good Site to Search ECMA standard online :
http://www.documentinteropinitiative.org/default.aspx

Open XML SDK Documentation
http://msdn.microsoft.com/en-us/office/ee441239.aspx

Open XML Format SDK 2.0: Getting Started Best Practices
http://blogs.msdn.com/erikaehrli/archive/2009/05/14/open-xml-format-sdk-2-0-getting-started-best-practices.aspx

Office Open XML Formats: Retrieving Lists of Excel 2007 Worksheets
http://msdn.microsoft.com/en-us/library/bb332456.aspx

Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 1 of 2)
http://msdn.microsoft.com/en-us/library/bb739834.aspx

Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 2 of 2)
http://msdn.microsoft.com/en-us/library/bb727373.aspx

2007 Office System Sample: Open XML Format SDK 2.0 Code Snippets for Visual Studio 2008
http://www.microsoft.com/downloads/details.aspx?FamilyID=78bea298-a3f9-44cf-bde0-b4f30dc986df&displaylang=en

Writing Large Excel Files with the Open XML SDK
http://blogs.msdn.com/b/brian_jones/archive/2010/06/22/writing-large-excel-files-with-the-open-xml-sdk.aspx

Parsing and Reading Large Excel Files with the Open XML SDK
http://blogs.msdn.com/b/brian_jones/archive/2010/05/27/parsing-and-reading-large-excel-files-with-the-open-xml-sdk.aspx

How to efficiently generate OpenXML Workbook from Excel files containing very large amount of data
http://blogs.msdn.com/b/vsod/archive/2010/05/31/how-to-efficiently-generate-openxml-workbook-from-excel-files-containing-very-large-amount-of-data.aspx

Very very very good blogs to through..Its must if you would like to know more about formats:

Where is the documentation for Office’s docx/xlsx/pptx formats? Part 1: Office 2007
http://blogs.msdn.com/b/chrisrae/archive/2010/09/25/where-is-the-documentation-for-office-2010-s-docx-xlsx-pptx-formats.aspx

Where is the documentation for Office’s docx/xlsx/pptx formats? Part 2: Office 2010
http://blogs.msdn.com/b/chrisrae/archive/2010/10/06/where-is-the-documentation-for-office-s-docx-xlsx-pptx-formats-part-2-office-2010.aspx

I’ll keep on updating this list and will try to categorize it as it becomes bigger 🙂

Posted in Open XML SDK | Tagged: , , , , | 4 Comments »

Question 7: How to find whether a DLL or EXE is managed or unmanaged

Posted by Ankush on February 24, 2011

What is best way to check if an assembly is managed or not?

Cheers!

 

Posted in Questions | Tagged: , | 2 Comments »

Custom UI part In Word and Open XML SDK 2.0

Posted by Ankush on February 24, 2011

Consider a scienrio you have a Word 2010 document in which you aretrying to custmization by adding custom UI part and you want to open this document in Open XML SDK, it WILL NOT WORK.

Why….?

Lets try this:

Create a new Word 2010 document and add a custom UI part [ You can use custom UI editor tool to do this]. Use the following XML to do the ribbon custmization.

<?xml version=”1.0″ encoding=”UTF-8″?>
<customUI xmlns=”http://schemas.microsoft.com/office/2009/07/customui“>
<ribbon>
<tabs>
<tab idMso=”TabDeveloper” visible=”false” />
<tab idMso=”TabReferences” visible=”false” />
</tabs>
</ribbon>
</customUI>

Now if you open this document using Open XML SDK 2.0, you will get an error message.

WordprocessingDocument doc = WordprocessingDocument.Open(“<Path of the document>”, false);

Exception Message : “Specified argument was out of the range of valid values.Parameter name: relationshipType”

Call Stack:

DocumentFormat.OpenXml.Packaging.WordprocessingDocument.CreatePartCore(String relationshipType)
DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.CreateOpenXmlPart(String relationshipType)DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships(OpenXmlPackage openXmlPackage, OpenXmlPart sourcePart, ackageRelationshipCollection
relationshipCollection, Dictionary`2 loadedParts)
DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load()
DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(Stream stream, Boolean readWriteMode)
DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(Stream stream, Boolean isEditable, OpenSettings openSettings)DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(Stream stream, Boolean isEditable)

Lets get into more detail.

If you look into the callstack, it is failing in CreatePartCore function. So I used .net reflector tool and anlyzed the Open XML SDK assembly i.e. defination of CreatePartCore. This is what I see:

The relationship namespace for Office 2010 is “http://schemas.microsoft.com/office/2007/relationships/ui/extensibility” and if you look at the image, it is not included. In result, you get an exception.

This is all about the problem.

Solution: The only solution which will work her to create an addin and then do the ribbon customization.

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

Question 6: Controlling Delegates and Multicast Delegate

Posted by Ankush on February 23, 2011

You have created a multicast delegate. When you invoke it, each delegate gets fired. You need want more control on this. Basically you want a fine control over:

a. order in which each delegate is invoked

b. firing only a subset of delegates

c. firing each delegate based on the success or failure of previous delegates

How will you achieve this?

Hint:
A delegate, when called, will invoke all delegatess to read within its invocation list. These delegates are usually invoked sequentially from the first to the last one added.With the use of the GetInvocationList method of the MulticastDelegate class, you can obtain each delegate in the invocation list of a multicast delegate. This method accepts no parameters and returns an array of Delegate objects that corresponds to the invocation list of the delegate on which this method was called.

Now can anybody offer the code solution:::)

Posted in Questions | Tagged: , , | 2 Comments »

.NET Reflector is not free anymore

Posted by Ankush on February 21, 2011

It is really sad when I heard that .NET reflector tool is not free anymore. RedGate company has announced that they will charge 35$ for a “perpetual license”. So, it’s not free. Anyway it’s worth to purchase a license of this beautiful software which has really helped but in case if you are looking for some free “Open Source”, then have a look:

  1. ILSpy , an open-source .NET Assembly browser and decompiler.
  2. Common Compiler Infrastructure (CCI)
  3. Mono Cecil
  4. Kaliro
  5. Dotnet IL Editor (DILE)
  6. Monoflector
  7. http://www.jetbrains.com/resharper/download/index.html
  8. http://blogs.jetbrains.com/dotnet/2011/02/resharper-6-bundles-decompiler-free-standalone-tool-to-follow/

Let us know if you have seen/used any tool instead of .net reflector and It is as good as .NET reflector is.

Posted in Troubleshooting Basics | Tagged: , , , , , | 1 Comment »

 
%d bloggers like this: