// Get insteresting code snippets (in this case text runs with
// style "tw4winMark")
Document sourceDocument = new Document(fileName);
var runs = sourceDocument.GetChildNodes(NodeType.Run, true)
.Select(r => r.Font.StyleName == "tw4winMark").ToList();
// Store snippets into temporary document
// Read Aspose documentation for details
Document document = new Document();
if (runs.Count > 0) {
NodeImporter nodeImporter = new NodeImporter(
runs[0].Document,
document,
ImportFormatMode.KeepSourceFormatting
);
foreach (Run run in runs) {
Run importedRun = nodeImporter.ImportNode(run, true) as Run;
importedRun.Font.Hidden = false;
document.Sections[0].Body.Paragraphs[0].AppendChild(importedRun);
}
}
// save temporary document in MemoryStream as RTF
RtfSaveOptions saveOptions = new RtfSaveOptions();
MemoryStream ms = new MemoryStream();
document.Save(ms, saveOptions);
// retrieve RTF from MemoryStream
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
string rtf = sr.ReadToEnd();
2 回答
最后我使用Aspose.Words for .NET从我感兴趣的Word文件中提取代码片段并将它们存储为RTF:
然后,可以像往常一样将rtf存储到数据库的文本字段中,并在RTF文本控件中对其进行编辑 .
Document.load,然后通过RANGE对象选择范围,然后使用range对象的XML属性获取该范围的XML并存储它 .
您可以稍后使用相反的过程将XML插入到另一个文档中 .
编辑片段可能会很有趣,因为我不知道任何基于Web的WORD兼容编辑器 .