没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2019-06-26 10:44:06.227|阅读 1687 次
概述:Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
【下载Aspose.Words for .NET最新试用版】
如果希望从任何Word文档中提取内容表,可以使用以下代码示例。
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
string fileName = "TOC.doc";
Aspose.Words.Document doc = new Aspose.Words.Document(dataDir + fileName);
foreach (Field field in doc.Range.Fields)
{
if (field.Type.Equals(Aspose.Words.Fields.FieldType.FieldHyperlink))
{
FieldHyperlink hyperlink = (FieldHyperlink)field;
if (hyperlink.SubAddress != null && hyperlink.SubAddress.StartsWith("_Toc"))
{
Paragraph tocItem = (Paragraph)field.Start.GetAncestor(NodeType.Paragraph);
Console.WriteLine(tocItem.ToString(SaveFormat.Text).Trim());
Console.WriteLine("------------------");
if (tocItem != null)
{
Bookmark bm = doc.Range.Bookmarks[hyperlink.SubAddress];
// Get the location this TOC Item is pointing to
Paragraph pointer = (Paragraph)bm.BookmarkStart.GetAncestor(NodeType.Paragraph);
Console.WriteLine(pointer.ToString(SaveFormat.Text));
}
} // End If
}// End If
}// End Foreach如果您想为任何Word文档计算段落中的行数,可以使用下面的代码示例。
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
string fileName = "Properties.doc";
Document document = new Document(dataDir + fileName);
var collector = new LayoutCollector(document);
var it = new LayoutEnumerator(document);
foreach (Paragraph paragraph in document.GetChildNodes(NodeType.Paragraph, true))
{
var paraBreak = collector.GetEntity(paragraph);
object stop = null;
var prevItem = paragraph.PreviousSibling;
if (prevItem != null)
{
var prevBreak = collector.GetEntity(prevItem);
if (prevItem is Paragraph)
{
it.Current = collector.GetEntity(prevItem); // para break
it.MoveParent(); // last line
stop = it.Current;
}
else if (prevItem is Table)
{
var table = (Table)prevItem;
it.Current = collector.GetEntity(table.LastRow.LastCell.LastParagraph); // cell break
it.MoveParent(); // cell
it.MoveParent(); // row
stop = it.Current;
}
else
{
throw new Exception();
}
}
it.Current = paraBreak;
it.MoveParent();
// We move from line to line in a paragraph.
// When paragraph spans multiple pages the we will follow across them.
var count = 1;
while (it.Current != stop)
{
if (!it.MovePreviousLogical())
break;
count++;
}
const int MAX_CHARS = 16;
var paraText = paragraph.GetText();
if (paraText.Length > MAX_CHARS)
paraText = $"{paraText.Substring(0, MAX_CHARS)}...";
Console.WriteLine($"Paragraph '{paraText}' has {count} line(-s).");
}Aspose.Words For .Net提供ImportFormatOptions类,该类允许指定各种导入选项来格式化输出。
启用此选项后,如果使用KeepSourceFormatting导入模式,则源样式将扩展为目标文档中的直接属性。当禁用此选项时,只有在对源样式进行编号时才会展开它。不会覆盖现有的目标属性,包括列表。
目前,这个选项只能与DocumentBuilder类的新公共方法一起使用,如下面的示例所示:
Document srcDoc = new Document(dataDir + "source.docx"); Document dstDoc = new Document(dataDir + "destination.docx"); DocumentBuilder builder = new DocumentBuilder(dstDoc); builder.MoveToDocumentEnd(); builder.InsertBreak(BreakType.PageBreak); ImportFormatOptions options = new ImportFormatOptions(); options.SmartStyleBehavior = true; builder.InsertDocument(srcDoc, ImportFormatMode.UseDestinationStyles, options);
在不同文档之间导入节点时,可能会出现这样的情况:源文档具有与目标文档中已经使用的标识符相同的列表。在这种情况下,Word总是使用目标列表的格式。为了允许用户选择适当的行为,ImportFormatOptions类中引入了KeepSourceNumbering属性,该属性指定了当编号在源文档和目标文档中发生冲突时将如何导入编号。默认值为false。
为了使用这个priperty,引入了一个新的公共方法,它接受新的KeepSourceNumbering选项,如下面的示例所示。
Document srcDoc = new Document(dataDir + "source.docx");
Document dstDoc = new Document(dataDir + "destination.docx");
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
// Keep source list formatting when importing numbered paragraphs.
importFormatOptions.KeepSourceNumbering = true;
NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting, importFormatOptions);
ParagraphCollection srcParas = srcDoc.FirstSection.Body.Paragraphs;
foreach (Paragraph srcPara in srcParas)
{
Node importedNode = importer.ImportNode(srcPara, false);
dstDoc.FirstSection.Body.AppendChild(importedNode);
}
dstDoc.Save(dataDir + "output.docx");当在不同文档之间导入文本框时,将对其应用目标文档的格式。这与单词的行为相对应。为了允许用户选择适当的行为,ImportFormatOptions类中引入了IgnoreTextBoxes选项。此属性指示在导入期间是否忽略源目标文本框中的格式设置,默认值为true。
Document srcDoc = new Document(dataDir + "source.docx");
Document dstDoc = new Document(dataDir + "destination.docx");
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
// Keep the source text boxes formatting when importing.
importFormatOptions.IgnoreTextBoxes = false;
NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting, importFormatOptions);
ParagraphCollection srcParas = srcDoc.FirstSection.Body.Paragraphs;
foreach (Paragraph srcPara in srcParas)
{
Node importedNode = importer.ImportNode(srcPara, true);
dstDoc.FirstSection.Body.AppendChild(importedNode);
}
dstDoc.Save(dataDir + "output.docx");慧都20万+用户答谢惠倒计时,ASPOSE系列产品火热促销中,最高直降8万元!欲购从速哟~>>立即进入优惠专场
ASPOSE技术交流QQ群现已开通,各类资源及时分享,欢迎交流讨论!(扫描下方二维码加入群聊)

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn




BarTender 标签管理系统,正是帮助企业轻松实现 GS1 标准化标签设计、编码生成与信息联动的强大工具。
Parasoft C/C++test 是一款功能强大的 C/C++ 软件测试工具,集成了静态代码分析、单元测试、集成测试和覆盖率分析等功能,单元测试作为其关键功能之一,为了适配多样化的目标部署环境,C/C++test 设计了灵活的测试结果收集机制。通过Socket通讯方式来收集单元测试结果,从而扩展其测试覆盖范围与应用场景。
Parasoft C/C++test作为一款功能全面的自动化代码质量保障工具,为C/C++开发者提供了静态分析、单元测试和运行时错误检测等核心功能。通过将其与轻量级且广受欢迎的VScode编辑器集成,开发团队可以在熟悉的编码环境中实时获得代码质量反馈,有效提升开发效率与代码可靠性。
本文主要介绍如何在MVVM应用程序中使用虚拟源,欢迎下载最新版组件体验!
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营