OpenXML SDK 读取WORD文档中的内容控件

OpenXML SDK 是不是已经开源了?原先实在微软的网站上下载最新版是2.5

BING查询他的网址https://github.com/OfficeDev/Open-Xml-Sdk

最新版是2.7.1,由于他采用了最新的.net core使用vs2015打不开,因此忽略他的最新版。

使用2.6版,在NuGet上发现有2.6.1版,但是在他的网站上没看到,只有2.7.1 2.7 2.6 2.5.1 2.5。

using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Office2010.Word;


namespace TestPaper
{
    sealed class DocxPaper : IPaper
    {
        public bool Checking(string sFileName)
        {
            string tempstr;


            using (WordprocessingDocument doc = WordprocessingDocument.Open(sFileName, false))
            {
                MainDocumentPart mpart = doc.MainDocumentPart;


                foreach(SdtContentCheckBox chk in mpart.Document.Descendants<SdtContentCheckBox>().ToList())
                {
                    var tagProperty = chk.Parent.Descendants<Tag>().FirstOrDefault(); //这是CheckBox内容控件的标记,VBA中的tag属性


                    if(tagProperty != null)
                    {
                        tempstr = tagProperty.Val;
                    }


                    tempstr = chk.Checked.Val;


                    if(chk.Checked.Val == OnOffValues.True) //此时checkbox选中状态
                    {
                        tempstr = "1"; //这是测试代码无用,为了断点能调试
                    }
                }
            }


            return true;
        }
    }
}

忽略接口IPaper,这是项目中使用的。只定义了方法!

这应该是比较快的了,除非使用C++了。我以前的文章有C++访问xlsx!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值