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

New Post: Styled spans turn the subsequent headings into normal text

$
0
0
After testing both cases, I obtain the same results on the 2nd hearing.
You specify both <h1> so you obtain Heading 1.

Yes, <span> handle also class attribute.

New Post: Styled spans turn the subsequent headings into normal text

$
0
0
Just imported this document:
<!doctype html>
<html><head><title>a</title></head><body>
<h1>Header 1</h1>
<p><span class="Normal">Par 1</span></p>
<p><span>Par 2</span></p>
<h1>Another Header 1</h1>
</body></html>
"Another Header 1" rendered in Normal text.

Then I imported this:
<!doctype html>
<html><head><title>a</title></head><body>
<h1>Header 1</h1>
<p><span>Par 1</span></p>
<p><span>Par 2</span></p>
<h1>Another Header 1</h1>
</body></html>
"Another Header 1" rendered as Heading 1 as it should.

New Post: Nested numbered lists

$
0
0
This is why i said, that MultilevelList is defined in the template that is used to base the new document on. My code loads the template, which already contains MultilevelList definition, converts the template into a document, and then adds all paragraphs imported from HTML.

I added the line in your reply before doing actual conversion, but nothing changed. Was that the right place?
HtmlConverter converter = new HtmlConverter(document.MainDocumentPart);
converter.HtmlStyles.StyleMissing += delegate(object sender1, StyleEventArgs e1)
{
    lblResult.Text += String.Concat("Missing style: ", e1.Name, "<br/>");
};

converter.HtmlStyles.DefaultStyle = converter.HtmlStyles.GetStyle("MultilevelList");

foreach (var p in converter.Parse(String.Concat("<html><head></head><body>", String.Join("\n\r", File.ReadAllLines(htmlPath)), "</body></html>")))
{
    body.Append(p);
}

New Post: Nested numbered lists

$
0
0
One thing to watch, make sure the Css name converts to the word name. camel case converts to include spaces.

converter.HtmlStyles.DefaultStyle = converter.HtmlStyles.GetStyle("Multilevel List");
<li class"MultilevelList">

New Post: Nested numbered lists

$
0
0
The style is actually called "MultilevelList" in the template. If I was using a wrong name, the missing style event should have fired, I guess.

New Post: Nested numbered lists

$
0
0
Yes I see. But I found some class & style names dont work..I could not explain it. but the only reliable way I found was:

class:"MbmBulletList" === style:"Mbm Bullet List"

and table styles needed to start with "table". class:"TableMyTable" = style:"Table My Table"

I dont understand why, I have not investigated it. but I discovered this by trial and error before I got the source.

New Post: Styled spans turn the subsequent headings into normal text

$
0
0
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.

New Post: Nested numbered lists

$
0
0
mart1c, you are perfectly right about predefining your styles first in Word, then importing them.
This is the correct way to do.


Beware that Style in OpenXml can be applied at 4 different scopes: Paragraph, Character (=Run), Numbering and Table.
So even if the naming is important (case insensitive but yes, beware of spaces), the scope is also important.
You can name 2 different scopes with the same name, thought.

Hope this help your understanding

New Post: Nested numbered lists

$
0
0
Wow, have folks at MS sunk so low?

Deleted the style, added it again under "List Multi Level" name, changed the code, and still no difference - Decimal numbers at all levels.

It still does not stick in Word either. Mind you - that is a List type style in Word, not Paragraph, so I am not sure it should be visible when a list item is selected. All I see is ListParagraph.

New Post: Nested numbered lists

$
0
0
I'm interested to see your template doc with the styles setup. Are you able to post somewhere?

New Post: Nested numbered lists

$
0
0
Let me describe this scenario and ask if you think this is an issue with the library, or I am doing something wrong.
When I tried using "list-style-type:lower-roman" in order to get the roman numbering for the 2nd level listings, they stopped restarting numbering after each new 1st level list.

So if I imported this, the numbers of the 2nd level list in the 1st and 2nd listings start from 1.
<!doctype html>
<html><head><title>a</title></head><body>

<ol>
    <li>List item
    <li>List item
        <ol>
            <li>Nested item</li>
            <li>Nested item</li>
        </ol>
    </li>
</ol>
<ol>
    <li>List item
    <li>List item
        <ol>
            <li>Nested item</li>
            <li>Nested item</li>
        </ol>
    </li>
</ol>

</body></html>
I see the following in the imported document:
1. List item
2. List item
  1. Nested item
  2. Nested item
1. List item
2. List item
  1. Nested item
  2. Nested item
But this HTML results in a different import:
<!doctype html>
<html><head><title>a</title></head><body>

<ol>
    <li>List item
    <li>List item
        <ol style="list-style-type:lower-roman">
            <li>Nested item</li>
            <li>Nested item</li>
        </ol>
    </li>
</ol>
<ol>
    <li>List item
    <li>List item
        <ol style="list-style-type:lower-roman">
            <li>Nested item</li>
            <li>Nested item</li>
        </ol>
    </li>
</ol>

</body></html>
This is what I see in the document:
1. List item
2. List item
  i. Nested item
  ii. Nested item
1. List item
2. List item
  iii. Nested item
  iv. Nested item
Should the last 2nd level list start from i, not from iii?

New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?

$
0
0
unluckily, when dealing with numbering, this is always a pain. It's terribly bad designed.

I used this
<olstyle="list-style-type: upper-alpha"><li>This is H1
        <olstyle="list-style-type: decimal"><li>This is H2</li><li>Another H2</li></ol></li><li>This is another H1
        <olstyle="list-style-type: decimal"><li>This is H2</li><li>Another H2</li></ol></li><li>Last H1
        <olstyle="list-style-type: decimal"><li>This is H2</li><li>Another H2</li></ol></li></ol>
The 2nd underlying level doesn't work. Why? This is due to my laziness : to avoid creating a new NumberDefinition each time I encounter <ol>/<ul>, I try to reuse an existing one.
Instead, MS Word will create a whole new definition with MultiLevel ad-hoc. Your sample is "easy" but what when people want to mix different list:
1.
    i.
    ii.
2.
    a.
    b.
I think, I have to start a new whole definition too and don't care if there are many list definition in the documents.

New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?

$
0
0
onizet,

I absolutely bow before your patience in dealing with Open XML implementation, where discovering the things is such a pain.

Thanks a lot for looking into that - you are going to make so many users happy!

New Post: Nested numbered lists

$
0
0
I think if you use css styles you are bound to fail.
htm2openxml tries to create word styles on the fly: eg. (just some random lines of code)
                        StartNumberingValue = new StartNumberingValue() { Val = 1 },
                        NumberingFormat = new NumberingFormat() { Val = NumberFormatValues.LowerLetter },
                        LevelIndex = 0,
                        LevelText = new LevelText() { Val = "%1." },
                        PreviousParagraphProperties = new PreviousParagraphProperties {Indentation = new Indentation() { Left = "420", Hanging = "360" }
                    prop.SpacingBetweenLines = new SpacingBetweenLines() { After = "0" };
                    prop.Indentation = new Indentation() { Hanging = "357", Left = (level * 357).ToString(CultureInfo.InvariantCulture) };
therefor fighting with the predefined word styles and messing with number styles and indentation, which are complicated enough to define correctly in word.

In the same concept as any HTML document ditch the inline styles and use use a predefined class in your stylesheet.css
word documents are much cleaner if you stop using the font and paragraph buttons and only use the predefined styles.

To solve this, need to use a predefined word list style (css class) and only manipulate the level of the paragraphs numbering properties.
I think this should work, add the commented section to my code above.
        currentParagraph.InsertInProperties(prop => prop.ParagraphStyleId = new ParagraphStyleId() { Val = className });
        /// Handle Numbering Levels     
                currentParagraph.InsertInProperties(prop => 
                            prop.NumberingProperties = new NumberingProperties
                            {
                                NumberingLevelReference = new NumberingLevelReference() { Val = level - 1 },
                                NumberingId = new NumberingId() { Val = numberingId }
                            });
     ///
                        break;
I think this should work, but you will still need to use the class in your <li class="MultilevelList">
I made a regex function to replace all my <li> :
cvHtml = RegexReplace(@"((?:<li.*?>))", @"<li class=""MultilevelList"" >", cvHtml);

private static string RegexReplace(string strRegex, string strReplace, string withInString)
        {
            Regex myRegex = new Regex(strRegex, RegexOptions.None);
            string withLiClass = myRegex.Replace(withInString ?? "", strReplace);
            return withLiClass;
        }
Ive got to run now, but I think that will be enough to get around the levels and submit a useful patch.

New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?

$
0
0
Was just looking at the previous comment and noticed, that when using upper Alpha style, the top level list should have been A, B, C numbered.
But it appears as 1, 2, 3. Does that make sense?

onizet wrote:
unluckily, when dealing with numbering, this is always a pain. It's terribly bad designed.

I used this

<ol style="list-style-type: upper-alpha">

1.
i.
ii.
2.
a.
b.
```
and the 2nd level lists should be both same number format, but they are lower roman vs. lower alpha. That is exactly what I saw when I tried creating my own numberings.

New Post: Nested numbered lists

$
0
0
Totally agree - I want to do as little formatting in HTML as possible and rely completely on the template used to create the document.
Using roman style was just a dirty workaround that backfired of course.
I am still trying to find a place and time to upload the template to show to you, but I am not set up on any free file hosting and also getting pulled in all directions at work so it may take me some time.

New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?

$
0
0
Should this be used instead of trying to create the numberings manually?
http://officeopenxml.com/WPnumbering-restart.php

What I mean is that every numbering level in the document should have its restart attribute equal to the the previous level by default (keeping in mind that the "restart levels" are 1 based, while the actual levels are 0 based - Confucius would be proud).

I am not so sure that creating the new numberings for every list level will be a better approach, as right now the library seems to be doing fine, except that it is not changing the list numbering formats. But it seems to be incrementing the levels consistently with the nested lists.

Only in the case where incoming nested lists are styled by the user, something is not right and a level restart described above might help.

Am I making sense?

New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?

$
0
0
I don't know yet because I already use LevelOverride + StartOverrideNumberingValue.

I have to test again but for now, I have detected why my code doesn't work. I check with the previous list to know if I should nest <OL> but I don't check with the parent list.
So when I test "absNumId == prevAbsNumId", it failed.
But it doesn't restart the 2nd list and I don't succeed with LevelRestart yet...

New Post: Fork this project

$
0
0
Is it possible to fork this project?

I would like to make some changes to enable custom tag processing.

New Post: Fork this project

$
0
0
hello,

Thanks for your interest but unluckily, I'm not very enthusiast for a fork.
The code is open source so if you need it for your own job, you can duplicate for yourself.
But if you want to publish your modifications, make it on this project so everyone will benefit
Viewing all 228 articles
Browse latest View live


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