aspose word同类标题之间的文本转换成html
【摘要】 word同类标题之间的正文段转换成html,基本是吧c#版的用java对应的api写了一遍;参考:https://docs.aspose.com/display/wordsnet/How%2Bto%2BExtract%2BSelected%2BContent%2BBetween%2BNodes%2Bin%2Ba%2BDocument+&cd=2&hl=zh-CN&ct=clnk&gl=sgh...
word同类标题之间的正文段转换成html,基本是吧c#版的用java对应的api写了一遍;
参考:
https://stackoverflow.com/questions/53802211/how-to-read-between-two-heading1-word-with-aspose
public static void ExtractHeadingContent() { Document doc = new Document(MyDir + "input.docx"); int i = 1; DocumentBuilder builder = new DocumentBuilder(doc); NodeCollection nodes = doc.GetChildNodes(NodeType.Paragraph, true); foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true)) { if (paragraph.ParagraphFormat.IsHeading == true && paragraph.ParagraphFormat.StyleName.Equals("Heading 1")) { Paragraph newPar = new Paragraph(doc); paragraph.ParentNode.InsertBefore(newPar, paragraph); builder.MoveTo(newPar); builder.StartBookmark("bm_extractcontents" + i); builder.EndBookmark("bm_extractcontents" + i); i++; } } builder.MoveToDocumentEnd(); builder.StartBookmark("bm_extractcontents" + i); builder.EndBookmark("bm_extractcontents" + i); for (int bm = 1; bm < i; bm++) { BookmarkStart bookmarkStart = doc.Range.Bookmarks["bm_extractcontents" + bm].BookmarkStart; BookmarkStart bookmarkEnd = doc.Range.Bookmarks["bm_extractcontents" + (bm + 1)].BookmarkStart; ArrayList extractedNodes = Common.ExtractContent(bookmarkStart, bookmarkEnd, false); Document dstDoc = Common.GenerateDocument(doc, extractedNodes); dstDoc.Save(MyDir + bm + "_out.docx"); } }
We are using htmlFixedSaveOptions while saving it to html: htmlFixedSaveOptions.setExportEmbeddedImages(true); htmlFixedSaveOptions.setExportEmbeddedCss(true); htmlFixedSaveOptions.setExportEmbeddedFonts(true);htmlFixedSaveOptions.setPrettyFormat(true); Any help is highly appreciated.
.... com.aspose.words.HtmlSaveOptions options= new com.aspose.words.HtmlSaveOptions(); options.setSaveFormat(com.aspose.words.SaveFormat.HTML); options.setExportImagesAsBase64(true); options.setExportFontsAsBase64(true); ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); doc.save(baos1,options); ....
https://blog.csdn.net/liweizhong193516/article/details/83548534
推荐
![](https://res.hc-cdn.com/ecology/9.3.130/v2_resources\images\global\blog-dialog.png)
华为开发者空间发布
让每位开发者拥有一台云主机
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)