Quantcast
Channel: html2openxml Discussions Rss Feed
Viewing all articles
Browse latest Browse all 228

New Post: Apply Word style based on p class

$
0
0
Thank you, onizet! You have made a great work.
I'm encountered this problem:
I have a .docx as template generated from Word2013.
In this template I have added 3 new style:
  • style_doc_1
  • style_doc_2
  • style_doc_3
This is the HTML I've tried to insert:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
</head>
<body>
    <p class="style_doc_2">Hello world!!!</p>
</body>
</html>
Then I've used this line of code:
var pars = converter.Parse(html)
with a delegate to HtmlStyles.StyleMissing.

Result: the style "style_doc_2" is missing!

I've discovered that the problem is in the TryGetValueIgnoreCase in the OpenXmlDocumentStyleCollection class at line:
int rc = String.Compare(name, keys[mid], StringComparison.OrdinalIgnoreCase);
Microsoft says at
https://msdn.microsoft.com/en-us/library/system.stringcomparison%28v=vs.110%29.aspx:
An operation that uses word sort rules performs a culture-sensitive comparison wherein certain nonalphanumeric Unicode characters might have special weights assigned to them. Using word sort rules and the conventions of a specific culture, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list.
So the special character "_" (underscore) in "style_doc_2" is not considered in the comparison.

I've modified that line in:
int rc = String.Compare(name, keys[mid],System.Globalization.CultureInfo.CurrentCulture, System.Globalization.CompareOptions.IgnoreCase);
and everithing is fine.

Viewing all articles
Browse latest Browse all 228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>