在C#中打开Word文档时显示修订气球

3

我写了一个小函数,可以打开指定文件位置的Word文档。当文档显示出来时,我想启用气球批注。

目前的代码如下:

    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;
    }

输入图像描述

转换为

输入图像描述


1
我并不是这方面的专家,不过你是否已经看到了这个:View.RevisionsMode - Joao
谢谢您的评论,它是View类中的一个属性而不是RevisionMode。我明天会写答案。 - Jean-Philippe Leclerc
1个回答

5
 using Microsoft.Office.Interop.Word;

启用气球提示框的主要属性为:
//enable tracking change
wordDocument.TrackRevisions = true;
wordDocument.ActiveWindow.View.MarkupMode = WdRevisionsMode.wdBalloonRevisions;

您可以添加以下设置。
//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;

请确保您拥有Microsoft Word 2010或2007以及最新的Microsoft.Office.Interop.Word.dll。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接