我们需要把word中的文字拆成句,目前只能得到每句话的纯文本,我需要保留每句话或每段话的富文本格式,翻译句子后需将带格式的句子导入到word中,目前aspose.words有方法可以吗?谢谢得到1.jpg (18.9 KB)
您可以使用以下代码将Word文档中的每个段落转换为RTF字符串:
Document doc = new Document(@"E:\Temp\input.docx");
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
Document tempDoc = (Document)doc.Clone(false);
tempDoc.EnsureMinimum();
tempDoc.FirstSection.Body.AppendChild(tempDoc.ImportNode(para, true));
using (MemoryStream ms = new MemoryStream())
{
tempDoc.Save(ms, SaveFormat.Rtf);
ms.Position = 0;
Console.WriteLine(Encoding.ASCII.GetString(ms.ToArray()));
}
}
非常感谢,那ppt和Excel能实现导出rtr格式的字符吗
我认为,您可以首先分别使用.NET API的Aspose.Slides和.NET API的Aspose.Cells将PPTX和XLSX文件转换为PDF格式。 之后,您可以直接在Aspose.Words中加载PDF文件,并使用我之前的代码转换为RTF。 希望这可以帮助。