aspose word同类标题之间的文本转换成html

举报
Amrf 发表于 2019/09/19 18:49:50 2019/09/19
【摘要】 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写了一遍;

image.png

参考:

https://docs.aspose.com/display/wordsnet/How%2Bto%2BExtract%2BSelected%2BContent%2BBetween%2BNodes%2Bin%2Ba%2BDocument+&cd=2&hl=zh-CN&ct=clnk&gl=sg

https://github.com/aspose-words/Aspose.Words-for-Java/blob/master/Examples/src/main/java/com/aspose/words/examples/programming_documents/document/ExtractContentBetweenBookmarks.java

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");
    }
}

https://forum.aspose.com/t/convert-doc-file-to-html-having-large-header-section/179379+&cd=1&hl=zh-CN&ct=clnk&gl=sg

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.

https://forum.aspose.com/t/convert-word-document-to-html-with-images/163689+&cd=3&hl=zh-CN&ct=clnk&gl=sg

....
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


【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。