Parameter "mso-style-name" does not work

Hi,

i have a problem with styles.

I have a word -template. The template has style “myStyle” and bookmark “myBookmark”. I try to write in bookmark a html. The html is:

title of test
p.CaptionTable {
mso-style-name: myStyle;
mso-style-next: Standard;
}

TEXT


my code:

public static void main(String[] args) {
try {
Document doc = new Document(“myTemplate.docx”);
DocumentBuilder builder = new DocumentBuilder(doc);
boolean bookmarkFounded = builder.moveToBookmark(“myBookmark”);
System.out.println("Bookmark founded: " + bookmarkFounded);
String html = getHtml();
builder.insertHtml(html);
doc.save(“result.docx”);
} catch (Exception e) {
e.printStackTrace();
}
}

public static String getHtml() {

try {
try (BufferedReader br = new BufferedReader(new FileReader(“myHtml.htm”))) {
StringBuilder sb = new StringBuilder();
String line = null;
try {
line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}


String everything = sb.toString();
return everything;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

In result word document has the “TEXT” style “p_CaptionTable” and not “myStyle”. Can you say me where is my mistake?

Тhanks in advance

Hi Alexey,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.8.0) from here and let us know how it goes on your side. If the problem still remains, please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

hello,
thank you for your reply
I apologize for the late reply, I was in vacation. I'm using the current version (aspose-words-14.8.0-jdk16.jar)

I have uploaded the files

Hi Alexey,

Thanks for sharing the detail. I suggest you please upgrade to the latest version of Aspose.Words for Java 14.8.0.

Please note that the content inserted by DocumentBuilder.insertHtml method does not inherit formatting specified in DocumentBuilder options. Whole formatting is taken from HTML snippet. If you insert HTML with no formatting specified, then default formatting is used for inserted content.

In your case, I suggest you please
use
overloaded DocumentBuilder.insertHtml method as shown in following code example
.

Document doc = new Document(MyDir + "myTemplate.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToBookmark("myBookmark");

builder.insertHtml(getHtml(), true);

doc.save(MyDir + "Out.docx");


When useBuilderFormatting is false, DocumentBuilder formating is ignored and formatting of inserted text is based on default HTML formatting. As a result, the text looks as it is rendered in browsers.

When useBuilderFormatting is true, formatting of inserted text is based on DocumentBuilder formatting, and the text looks as if it were inserted with Write.

I have attached the output document with this post for your kind reference. In this document, 'p_CaptionTable' is based on 'myStyle'. Note that an Embedded or Linked CSS style (through use of the class attribute) is imported as a Style and applied to the Paragraph node in the document.

hi,
thank you for your reply, your code works. But I have one example, where the code does not work. You find in attachment a word- template, which has a style "isrCaptionTable" and bookmark "S_CALIBRATION". In result docx-document you will see a new style "p_CaptionTable", which does not based on the style "isrCaptionTable", even though in html is

p.CaptionTable {
mso-style-name: isrCaptionTable;
mso-style-next: Standard;
}

Could you say me, what i do false?

Hi Alexey,

Thanks for your inquiry. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10835. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

hi,
where can I see in which version the bug is fixed, how long must I wait?

P. S. WORDSNET is correct? should not be WORDSJAVA?

Hi Alexey,

Thanks for your inquiry.

schroeder:

where can I see in which version the bug is fixed, how long must I wait?

Currently special Microsoft “mso” attributes are not imported or exported with the exception of “mso-break-type” which is supported both in import and export. These properties help with round-tripping HTML back to a document format but significantly bloat the HTML which is why most users want to avoid such extra markup. However since it is a useful tool to provide Word-HTML round-trip, we will support these attributes both import and export in a future version.

I am afraid this requested feature (WORDSNET-10835) has now been postponed till a later date due to some other important issues and new features. We will inform you as soon as there are any further developments. We apologize for your inconvenience.
schroeder:

P. S. WORDSNET is correct? should not be WORDSJAVA?

Please
note that the latest version of Aspose.Words for Java is completely
auto-ported from .NET, i.e. we do not write code for Aspose.Words for
Java; it is generated out automatically from C# code of Aspose.Words for
.NET. So there should not be any significant difference in
functionalities between Java and .NET versions because the code is
mostly the same.

The issues you have found earlier (filed as WORDSNET-10835) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(2)

The issues you have found earlier (filed as WORDSNET-10835) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.