HTML to Word DOCX | Visibility of Hidden Numbered and Bullet Lists | Java

@bekal94 Thank you for additional information. I have managed to reproduce the problem on my side. For a sake of correction it has been logged as WORDSNET-23466. We will keep you informed and let you know once it is resolved.

Thank you Alexey,

There is also another issue, if you input
a
b
c
as an ordered list, it will automatically change to
1
2
3
I am unable to reproduce in the local, but in our application it is reproducible

@bekal94 Unfortunately, it is difficult to say what might cause the problem without ability to reproduce it on our side. If possible, could you please create a simple document and code example that will allow us to reproduce the problem? We will investigate and provide you more information.

Hi Alexey,

I have used the latest jar to generate the word and the numbered list inside hidden content is still not visible. Is it possible to check and get back?

image.png (110.5 KB)

The highlighted part is missing the numbered list.
Thanks

@bekal94 Could you please attach your input, output and expected documents along with code that will allow us to reproduce the problem? We will check the issue and provide you more information. Unfortunately, it is not possible to detect what is going wrong using screenshot.

Hi Alexey,

You can use the same information provided in the above thread, there is an entry on 11 Feb, that I had reported where the content was coming outside the box,
Now the content is coming inside but the UL and OL is missing, I am attaching it here again, Information.zip (36.4 KB)

@bekal94 unfortunately, I cannot reproduce the problem on my side. I used the following code for testing:

HtmlLoadOptions opt = new HtmlLoadOptions();
opt.setBlockImportMode(BlockImportMode.PRESERVE);
Document doc = new Document("C:\\Temp\\in.html", opt);
doc.save("C:\\Temp\\out.docx");

Here is the output document produced on my side: out.docx (9.2 KB)

Could you please provide the code you are using to produce the document from screenshot and attach the generated document here for our reference.

Hi Alexey,

We are still getting the same error on the application,
could you please provide the source code, or explain why
“HtmlLoadOptions opt = new HtmlLoadOptions();
opt.setBlockImportMode(BlockImportMode.PRESERVE);”

is used?

Also please let me know the jar version you are using to generate the .doc file?

@bekal94 In MS Word documents there is no direct way to preserve borders applied to DIV elements. For this purpose OOXML has a special div tag in webSettings.xml, which are referred by paragraphs using divId tag. BlockImportMode.PRESERVE instructs Aspose.Words to import DIVS from HTML this way to preserve borders applied using DIV around several paragraphs.

Hi Alexey,

In our application we are using builder.insertHtml() for inserting our data and building the document, how can we incorporate this [BlockImportMode.PRESERVE] with builder.insertHtml(). It will throw an error as there is a mismatch.

Thanks

@bekal94 Unfortunately, there is no way to pass BlockImportMode.PRESERVE into DocumentBuilder.insertHtml method. This feature request has been logged as WORDSNET-24117. We will will be sure to notify you once it is implemented or we have more information for you.

@bekal94 Excuse me, I was wrong, in the latest 22.7 version of Aspose.Words you can use an appropriate HtmlInsertOptions to preserve blocks:

DocumentBuilder builder = new DocumentBuilder();
String html = new String(Files.readAllBytes(Paths.get("C:\\Temp\\in.html")));
builder.insertHtml(html, HtmlInsertOptions.PRESERVE_BLOCKS);
builder.getDocument().save("C:\\Temp\\out.docx");

Hi Alexey,

Thank you for the suggestion we have implemented it in our code and the blocks seems to be good.
There is one more issue we have noticed in the export, the numbered list input is given as a b c (alphabets) but the output in the word is coming as 1 2 3 (numbers).

Please advise if there is a way to define styles for numbered list, example Alphabets, roman numerals etc.Information.zip (20.5 KB)

The reproducible information is attached.
Thanks

@bekal94 As I can see type of ordered list is not specified in your HTML and both Aspose.Words and browser uses the default numbering style - 1,2,3… You can specify numbering style in your HTML using type attribute of <ol> tag. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("<ol type='a'><li>Coffee</li><li>Tea</li><li>Milk</li></ol>");
doc.save("C:\\Temp\\out.docx");

Yes from the type if it is defined it will give the desired result, but we are dynamically fetching it from the application.
So we cannot apply single style for all those objects, is there a way we can apply the styles dynamically?

@bekal94 You can try using INodeChangingCallback to change the inserted list type dynamically in the code. For example see the following code:

Document doc = new Document();
doc.setNodeChangingCallback(new NodeInsertion());
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("<ol><li>Coffee</li><li>Tea</li><li>Milk</li></ol>");
doc.save("C:\\Temp\\out.docx");
private static class NodeInsertion implements INodeChangingCallback
{
    @Override
    public void nodeInserting(NodeChangingArgs nodeChangingArgs) throws Exception {
        // Do nothing
    }

    @Override
    public void nodeInserted(NodeChangingArgs nodeChangingArgs) throws Exception {

        if(nodeChangingArgs.getNode().getNodeType() == NodeType.PARAGRAPH)
        {
            Paragraph para = (Paragraph)nodeChangingArgs.getNode();
            if(para.isListItem())
                para.getListFormat().getListLevel().setNumberStyle(NumberStyle.LOWERCASE_LETTER);
        }
    }

    @Override
    public void nodeRemoving(NodeChangingArgs nodeChangingArgs) throws Exception {
        // Do nothing
    }

    @Override
    public void nodeRemoved(NodeChangingArgs nodeChangingArgs) throws Exception {
        // Do nothing
    }
}

Hi Alexey,

This implementation is maybe not feasible for us as there is a lot of code changes we will need to implement,
It is already working for Roman Numerals as expected in our application, has it already been handled in the aspose.words jar itself?

@bekal94 Roman Numerals is the default numbering style for ordered list. Aspose.Words needs to know what numbering style should be used. So numbering style must be specified either in HTML using type attribute of <ol> tag or changed later in the DOM.