开发者

Show revision balloons when opening a Word document in C#

开发者 https://www.devze.com 2023-03-10 05:18 出处:网络
I made a little function that opens a WordDocument at a given file location. I\'d like to enable the balloons when the document shows up.

I made a little function that opens a WordDocument at a given file location. I'd like to enable the balloons when the document shows up.

Here's the code so far:

    public static Document OpenWordDocument(object fileName)
    {
        ApplicationClass application = new ApplicationClass();
        object readOnly = false;
        object isVisible = true;
        object missing = Missing.Value;

        application.Visible = true;
        Document wordDocument = application.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);

 开发者_开发知识库       wordDocument.TrackRevisions = true;
        //Do something here the enable balloons
        wordDocument.Activate();

        return wordDocument;
    }

Show revision balloons when opening a Word document in C#

TO

Show revision balloons when opening a Word document in C#


 using Microsoft.Office.Interop.Word;

The main properties for enable the balloon is :

//enable tracking change
wordDocument.TrackRevisions = true;
wordDocument.ActiveWindow.View.MarkupMode = WdRevisionsMode.wdBalloonRevisions;

you can also add these setting

//the balloon will be on the right side
wordDocument.ActiveWindow.View.RevisionsBalloonSide = WdRevisionsBalloonMargin.wdRightMargin;

// the ballon section width will been calculate in percent
wordDocument.ActiveWindow.View.RevisionsBalloonWidthType = WdRevisionsBalloonWidthType.wdBalloonWidthPercent;

//make sure the balloon will not been cut, the balloons section is egal to the doc with(100%)
wordDocument.ActiveWindow.View.RevisionsBalloonWidth = 100.0f;

//make sur Word show  the final version with the revisions
wordDocument.ActiveWindow.View.RevisionsView = WdRevisionsView.wdRevisionsViewFinal;

//True for Microsoft Word to display revisions and comments that were made to a document with Track Changes enabled
wordDocument.ActiveWindow.View.ShowRevisionsAndComments = true;

//True for Microsoft Word to display insertions and deletions that were made to a document
wordDocument.ActiveWindow.View.ShowInsertionsAndDeletions = true;

Be sure to have Microsoft Word 2010 or 2007 and the latest Microsoft.Office.Interop.Word.dll

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号