我可以创建word文件和转换aspose.words应用程序接口的超文本标记语言。如何使用API获取html中的正文内容(不包括HTML、head、BODY标签/仅包含正文内容)。我将使用它在WYSIWYG编辑器(summernote)应用程序中显示输出。
注意:我正在使用.net框架(C#)开发应用程序
发布于 2020-04-20 20:28:01
Document doc = new Document(MyDir + "inputdocx.docx");
var options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.Html)
{
ImageSavingCallback = new HandleImageSaving(),
};
String html = doc.FirstSection.Body.ToString(options);发布于 2020-04-20 16:47:44
默认情况下,Aspose.Words将html保存为Xhtml格式,因此您可以安全地将其加载到XmlDocument中并获取bydy标记的内容。例如,请参阅以下代码。
// Create a simple document for testing.
DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("Hello world!!!");
// For testing purposes insert an image.
builder.InsertImage(@"https://cms.admin.containerize.com/templates/aspose/App_Themes/V3/images/aspose-logo.png");
// Additional options can be specified in the corresponding save options.
HtmlSaveOptions opt = new HtmlSaveOptions(SaveFormat.Html);
// For example, output images in the HTML as base64 string (summernote supports base64)
opt.ExportImagesAsBase64 = true;
// Save the document to MemoryStream.
using (MemoryStream ms = new MemoryStream())
{
builder.Document.Save(ms, opt);
// Move the stream position ot the beginning and load the resulting HTML into Xml document.
ms.Position = 0;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(ms);
// Find body tag.
XmlNode body = xmlDoc.SelectSingleNode("//body");
// Get inner xml of the body.
Console.WriteLine(body.InnerXml);
}希望这能有所帮助。
披露:我在Aspose.Words团队工作。
https://stackoverflow.com/questions/61309501
复制相似问题