Friday, June 18, 2010

Not all Structured Document Tags are created equal! (Continued)

Every Sdt must contain SdtProperties.  So the solution was to get the OpenXmlElement of DocumentMainPart.Document then get the Descendants that are SdtProperties. For example:

Code Snippet
  1. Dim opnXMLElement As OpenXmlElement = newDocMainPart.Document
  2.             For Each sdtProperty As SdtProperties In opnXMLElement.Descendants(Of SdtProperties)()

Then the parent of sdtProperty (as shown above) MUST be one of the types we are looking for so I run this check:

Code Snippet
  1. Dim sdtContentCell As SdtContentCell = Nothing
  2.                 Dim sdtContentBlock As SdtContentBlock = Nothing
  3.                 Dim sdtContentRow As SdtContentRow = Nothing
  4.                 Dim sdtContentRun As SdtContentRun = Nothing
  5.                 Select Case True
  6.                     Case TypeOf sdtProperty.Parent Is SdtBlock
  7.                         sdtContentBlock = sdtProperty.Parent.GetFirstChild(Of SdtContentBlock)()
  8.                     Case TypeOf sdtProperty.Parent Is SdtCell
  9.                         sdtContentCell = sdtProperty.Parent.GetFirstChild(Of SdtContentCell)()
  10.                     Case TypeOf sdtProperty.Parent Is SdtRow
  11.                         sdtContentRow = sdtProperty.Parent.GetFirstChild(Of SdtContentRow)()
  12.                     Case TypeOf sdtProperty.Parent Is SdtRun
  13.                         sdtContentRun = sdtProperty.Parent.GetFirstChild(Of SdtContentRun)()
  14.                     Case Else
  15.                         'Nothing
  16.                 End Select

Now I have the actual Sdt Content I am looking for and I can do whatever replacement I need to do.

Thursday, June 10, 2010

Not all Structured Document Tags are created equal!

Depending on the location of the <w:sdt> tag, the actual type of the tag could be different.  For instance an sdt tag inside a table could be an SdtContentCell or SdtContentRow depending on its position.  I’m currently working on an idea to identify a structured document tag, stay tuned.

Monday, March 22, 2010

Why is it so hard for companies to standardize contracts and forms?

Currently I’m working on a project where we create components of contracts using a Word Add-In.  But for some reason this company’s principals cannot decide on a standardized contract.  I realize there may be differences in contracts based on something such as country, but really! Do you really need to have end users enter in custom fields with information specified by a particular client, really? Instead of looking up to something we can be proud of, we’re headed down a slippery slope of wasteful time and money.

Tuesday, December 15, 2009

Formatting International Date

A quick post to help establish the numerical designator for a day, and create a International date in the form (DD(designator) MMMM, yyyy).

Code Snippet
  1. Private Function FormatInternationalDate(ByVal DateToFormat As Date) As String
  2.     Dim NumericalDesignator As String = String.Empty
  3.     Select Case Day(DateToFormat)
  4.         Case Is = 1, 21, 31
  5.             NumericalDesignator = "st"
  6.         Case Is = 2, 22
  7.             NumericalDesignator = "nd"
  8.         Case Is = 3, 23
  9.             NumericalDesignator = "rd"
  10.         Case Else
  11.             NumericalDesignator = "th"
  12.     End Select
  13.     '// Return date as 24th June, 2009
  14.     Return DateToFormat.Day.ToString & NumericalDesignator & Space(1) & DateToFormat.ToString("MMMM, yyyy")
  15. End Function

Monday, December 14, 2009

Locating a file placed in the bin directory when Build Action is set to Content

Task: How could a get a content file from the bin directory without having to hard code the directories that are created under the bin when a project is built. Using reflection I get the Executing Assembly’s Codebase (Note: You could also use Assembly.GetExecutingAssembly().Location then there’s no need for the replace in line 3)

Code Snippet
  1. Dim pathToMyFile As String = String.Empty
  2. With Assembly.GetExecutingAssembly().CodeBase
  3.     Dim tmpPath As String = .Replace("file:///", String.Empty)
  4.     pathToMyFile = tmpPath.Substring(0, tmpPath.LastIndexOf("bin") + 4)
  5.     Dim directoryList() As String = Directory.GetFiles(pathToMyFile, "MyFileName.docx", SearchOption.AllDirectories)
  6.     For Each myFile In directoryList
  7.         pathToMyFile = myFile
  8.     Next
  9. End With

Thursday, November 19, 2009

Are all Dietitian’s naturally nut jobs?

You can’t eat anything. You have to eat less. You can’t drink milk. You have to eat every 2.5 hours.  You should only eat grilled chicken, salmon or tuna in very small portions. No fast food. No sugars. No soda pop. A gallon of water per day.  People will understand if you eat during meetings.  You should walk 2 miles during your lunch break.  Are these people serious? I think I’ve heard everything now.

Tuesday, November 3, 2009

H1N1 Scare, scared but no worries here!

I’m not opposed to getting the H1N1 flu vaccine. What really scares me is having to go to the clinic to get the shot.  There’s sick people there!! Touch anything, a door, chair, pen, paper, magazine or even breathe and you could become infected, right? My wife is going today to protect our future child due in February and I am terrified she will contract something simply by going to the clinic.  Now I’ve heard the news broadcasts and I’ve listened to the crazies out there claiming this is a hoax but I’m sure there were people saying the same thing during the Spanish Flu as well and that one killed big time! I’m not going to put my life or the life of my family in danger by not getting vaccinated!

Calling .NET From COM Originally posted by Mikec276 on C Sharp Friends It might be hard to convince your IT manager to let you build y...