Andornot Consulting
Wednesday, February 24, 2010 3:18 PM

Replace MS Word special characters in javascript and C#

by Peter Tyrrell

MS Word uses characters from the Windows-1252 character encoding set which are not represented in ASCII or ISO-8859-1. This is often a pain in the butt. Special characters include:

  • the… ellipsis
  • ‘smart’ “quotes”
  • en – dash and em — dash
  • dagger † and double dagger ‡
  • and more, but these are most common.

If you want to replace them with ASCII cognates, here's a function to do that. (Daggers don't have cognates as far as I know.)

Javascript

/// Replaces commonly-used Windows 1252 encoded chars that do not exist in ASCII or ISO-8859-1 with ISO-8859-1 cognates.
var replaceWordChars = function(text) {
    var s = text;
    // smart single quotes and apostrophe
    s = s.replace(/[\u2018|\u2019|\u201A]/g, "\'");
    // smart double quotes
    s = s.replace(/[\u201C|\u201D|\u201E]/g, "\"");
    // ellipsis
    s = s.replace(/\u2026/g, "...");
    // dashes
    s = s.replace(/[\u2013|\u2014]/g, "-");
    // circumflex
    s = s.replace(/\u02C6/g, "^");
    // open angle bracket
    s = s.replace(/\u2039/g, "<");
    // close angle bracket
    s = s.replace(/\u203A/g, ">");
    // spaces
    s = s.replace(/[\u02DC|\u00A0]/g, " ");
    
    return s;
}

C# extension method

public static string ReplaceWordChars(this string text)
        {
            var s = text;
            // smart single quotes and apostrophe
            s = Regex.Replace(s, "[\u2018|\u2019|\u201A]", "'");
            // smart double quotes
            s = Regex.Replace(s, "[\u201C|\u201D|\u201E]", "\"");
            // ellipsis
            s = Regex.Replace(s, "\u2026", "...");
            // dashes
            s = Regex.Replace(s, "[\u2013|\u2014]", "-");
            // circumflex
            s = Regex.Replace(s, "\u02C6", "^");
            // open angle bracket
            s = Regex.Replace(s, "\u2039", "<");
            // close angle bracket
            s = Regex.Replace(s, "\u203A", ">");
            // spaces
            s = Regex.Replace(s, "[\u02DC|\u00A0]", " ");
            
            return s;
        }
Monday, November 16, 2009 9:34 AM

Top Ten Word 2007 Features

by Jonathan Jacobsen

Up until a couple years ago, I was a fan of OpenOffice, the open-source office suite, and in particular Writer and Calc, the word processor and spreadsheet applications. I found they had all the same features as Microsoft Word and Excel, and the price ($0) was great. Sure, the interface was a bit dated and you had to hunt through endless menus to find features, but that had been my experience with all the versions of MS Office up to that point.

Then two events conspired to change my view: Microsoft released Office 2007, with a greatly revised user interface, and I took a job teaching other people how to use it! It's a bit of a challenge to teach something you don't use, so I dived in to Office 2007, and in particular Word, poking into all the nooks and crannies to master every last feature... or at least to keep one step ahead of my students. It was painful at first, abandoning the familiar menus for the new Ribbon Bar, but I must say, within a couple of months I was a convert. I truly enjoy using Office 2007 every day now. And to celebrate that, I put together a top ten list of my favourite Word 2007 features. Many have been around for a while, but are even more usable in this version, while others are new.

1. Push Pins

As you work on documents, they appear in the Recent Documents list under the Office button in the top left corner. A single click on one re-opens it for editing, until it's pushed off the bottom of the list by new arrivals. Clicking the push pin sticks the document to the list for as long as you need to work on it.

2. Table Styles

Tables are a great way to present information, and now, it's easy to make them pretty with the built-in table styles.

3. Smart Art

Attractive, easy to use, pre-created charts and diagrams come in handy and save time when I want to add some visual interest to a document, as an alternative to a table.

4. Cropping Images

I am often pasting screenshots of websites into documents, and I think they are tidier without the browser window around them. I want the viewer to focus just on the web page content. The image cropping tool is invaluable for quickly trimming an image down, without need for external image software.

5. Visual Previews

I love seeing changes happen as I make them, such as when resizing an image or previewing different styles. Such a change from the earliest versions of Word, where you waited many minutes for a page to re-render after adding an image!

6. Track Changes

When collaborating on a document, it's critical to see the changes others make. Enabling this feature makes that such a breeze.

7. Compare Documents

However, if your collaborators forget to track their changes, this feature will find them, by comparing two different versions of the same document. You can easily accept, reject and merge changes into a final version.

8. Inspect Document

After a series of revisions, changes tracked and accepted or rejected, and comments added and removed, running the Document Inspector is wise. It will let you know about any last stray changes and comments, so that the version you release is truly the final one.

Read more about issues related to tracking changes in these two blog posts:

9. Save as PDF

Not everyone has Office 2007, but most people have or can install Adobe Reader or one of several other PDF readers. You can save your document as a PDF directly from Word with no additional software required.

10. The Ribbon Bar

Last but not least, I've found that the grouping of features on the Ribbon Bar really does make sense. A skeptic at heart, I've come to enjoy using this interface over the options buried many levels deep in menus.

Thursday, April 16, 2009 9:26 AM

MS Office Features for Tracking Revisions

by Administrator

Have you ever sent a Word document or Excel spreadsheet out for review and asked the recipient to please, please, please either turn on Track Changes or insert Comments, so you can see their revisions, only to have the document come back with neither? If so, here are two features available in Word and Excel that will help.

First, before sending a document out for review, you can turn on Track Changes in such a way that the recipient cannot turn it off without knowing a password. To do so in Word 2007:

  1. Select the Review tab on the Ribbon Bar, click the Protect Document button, and choose the Restrict Formatting and Editing option.
  2. In the panel that appears, ignore option 1, but tick option 2 and change the drop down selector to Tracked Changes (or Comments if you prefer to only allow comments to be made).
  3. Click the Yes, Start Enforcing Protection button and enter a password when prompted, to allow you to turn off Tracked Changes or Comments later.
  4. Save the document and send it out for review.

The procedure is similar in Excel.

In both applications, you can also be more fine-grained in what editing you allow, such as restricting editing to speciic cells in a spreadsheet or styles in a document (e.g. the user may edit body text but not headings).

The document may be opened by the recipient as usual, but Track Changes or Comments will be enabled and may only be disabled by following the same steps as above, but disabling protection with the password.

If you had forgotten to add Track Changes (with a password) to the document that you sent, you can use the Compare option. Open your original document and the one that was edited without changes being tracked. You can then compare the two and produce a version with changes tracked, which you can then proceed to accept or reject as appropriate.

Monday, March 03, 2008 5:27 PM

Oops: Tracking Changes in Microsoft Word

by Ted Jardine

Microsoft Word's "Track Changes" feature is extremely useful, but has the very real potential of embarrassing you and/or your company. I wrote an internal memo a couple months back because a client had sent a Word document that unknowingly had very private information visible with Track Changes enabled; this particular client had been tracking changes, but had not removed all traces of past edits before sending it off. Fortunately, I was as yet the only recipient, but that was something a little too close for comfort.

The Word 2007 help files include the following:

Life is full of embarrassing moments. Some merely cause temporary blushing while others can make you cringe for years to come. Of course, some of these episodes are preventable if you just take some appropriate action. For example:

  • That hiring manager you sent your souped up resume to opened it up in Word 2003 and saw all your creative editing right there, in the form of insertions, deletions, and comments. Your secret was out, and you now remain unemployed and living in your parents' rec room.
  • Before sending off your annual review form, where you let off some steam by inserting epithets and insults about your goody-goody coworkers, you hide the revision marks. Later that day, you're escorted out of the building.
  • You send off your contract bid with the proprietary notes (i.e. profit margins) not-so-hidden.

Solution: Before you send those documents off, get rid of the revision marks — otherwise, they're on by default when someone opens them up in Word 2003.

There's only one way to get rid of all those potentially embarrassing/incriminating changes, and that's by accepting or rejecting all of them. Go to the online Microsoft help article to find out the steps for all versions of Word. Read it. Do it. And if you don't, pray you send that Word doc to somebody nice like me.