OpenXML SDK 读取WORD文档中的内容控件
2017-03-22 15:28
633 查看
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!
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!
相关文章推荐
- OpenXml读取word内容的实例
- ASP.NET C#如何读取word,写入word,复制内容到另一个word文档,批量修改文件名
- C# 给Word文档添加内容控件
- Java程序员从笨鸟到菜鸟之(一百零三)java操作office和pdf文件(一)java读取word,excel和pdf文档内容
- java操作office和pdf文件:读取word,excel和pdf文档内容
- C#读取word文档中的内容
- java读取word,excel和pdf文档内容
- poi读取word文档中内容
- VC如何读取Word文档中的批注内容
- java poi组件 读取word文档 替换文档 内容 图片
- asp读取word 文档内容转换为二进制数据流
- java读取word,excel和pdf文档内容
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- C# 给Word文档添加内容控件
- C#向Word文档中添加内容控件的方法示例
- word文档内容读取检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问。
- C#读取Word文档内容代码
- OpenXml读取word内容注意事项
- 通过C#从数据库中读取内容生成WORD文档
- C#读取word文档内容并显示