COM 字 -->获取所有内容控件

发布于 2024-12-17 20:55:51 字数 939 浏览 0 评论 0原文

我想获取Word文档的所有ContentControl。目前我使用以下函数来执行此操作。

    private static List<ContentControl> GetAllContentControls(Document wordDocument)
    {
        if (null == wordDocument)
            throw new ArgumentNullException("wordDocument");

        List<ContentControl> ccList = new List<ContentControl>();

        Range rangeStory;
        foreach (Range range in wordDocument.StoryRanges)
        {
            rangeStory = range;
            do
            {
                try
                {
                    foreach (ContentControl cc in rangeStory.ContentControls)
                    {
                        ccList.Add(cc);
                    }
                }
                catch (COMException) { }
                rangeStory = rangeStory.NextStoryRange;

            }
            while (rangeStory != null);
        }
        return ccList;
    }

问题是在文本字段中也获取内容控件。

I want to get all ContentControls of a Word-Document. Currently I use following function to do this.

    private static List<ContentControl> GetAllContentControls(Document wordDocument)
    {
        if (null == wordDocument)
            throw new ArgumentNullException("wordDocument");

        List<ContentControl> ccList = new List<ContentControl>();

        Range rangeStory;
        foreach (Range range in wordDocument.StoryRanges)
        {
            rangeStory = range;
            do
            {
                try
                {
                    foreach (ContentControl cc in rangeStory.ContentControls)
                    {
                        ccList.Add(cc);
                    }
                }
                catch (COMException) { }
                rangeStory = rangeStory.NextStoryRange;

            }
            while (rangeStory != null);
        }
        return ccList;
    }

The Problem is to get Contentcontrols in text-fields, too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×纯※雪 2024-12-24 20:55:51

我得到了它

    private static List<ContentControl> GetAllContentControls(Document wordDocument)
    {
        if (null == wordDocument)
            throw new ArgumentNullException("wordDocument");

        List<ContentControl> ccList = new List<ContentControl>();

        Range rangeStory;
        foreach (Range range in wordDocument.StoryRanges)
        {
            rangeStory = range;
            do
            {
                try
                {
                    foreach (ContentControl cc in rangeStory.ContentControls)
                    {
                        ccList.Add(cc);
                    }

                    foreach (Shape shapeRange in rangeStory.ShapeRange)
                    {
                        foreach (ContentControl cc in shapeRange.TextFrame.TextRange.ContentControls)
                        {
                            ccList.Add(cc);
                        }
                    }
                }
                catch (COMException) { }
                rangeStory = rangeStory.NextStoryRange;

            }
            while (rangeStory != null);
        }
        return ccList;
    }

I got it

    private static List<ContentControl> GetAllContentControls(Document wordDocument)
    {
        if (null == wordDocument)
            throw new ArgumentNullException("wordDocument");

        List<ContentControl> ccList = new List<ContentControl>();

        Range rangeStory;
        foreach (Range range in wordDocument.StoryRanges)
        {
            rangeStory = range;
            do
            {
                try
                {
                    foreach (ContentControl cc in rangeStory.ContentControls)
                    {
                        ccList.Add(cc);
                    }

                    foreach (Shape shapeRange in rangeStory.ShapeRange)
                    {
                        foreach (ContentControl cc in shapeRange.TextFrame.TextRange.ContentControls)
                        {
                            ccList.Add(cc);
                        }
                    }
                }
                catch (COMException) { }
                rangeStory = rangeStory.NextStoryRange;

            }
            while (rangeStory != null);
        }
        return ccList;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文