Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2023, 04:59 PM
Journeyman Journeyman is offline HTML To Word Styles Windows 10 HTML To Word Styles Office 2019
Novice
HTML To Word Styles
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default HTML To Word Styles

Hi All,



I'm xfering HTML to Word. The xterfer works fine. Except

I was provided advice to to have html style map to word:
https://www.msofficeforums.com/word-...rd-styles.html

That advice had me include the class inside the HTML tag:
Code:
<p Class=MsoBodyText>Body Text Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p>
<p Class=MsoList>List Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p>
<p Class=MsoListNumber>List Number Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p>
<p Class=MsoHeading1>Heading 1 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p>
<p Class=MsoTitle>Heading 2 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p>
The problem:
Using these style classes inside the P tag works fine. However, on my html form, I have Bullet points.

<Ul>
<Li> List 1</Li>
<Li> List 2</Li>
</Ul>
... etc

Where <p Class=MsoList> works to identify the correct word style <Li Class=MsoList> does not.

This means that a bulleted or numbered list in the HTMl document, with transpose to word as a normal class - no matter how I define the List class.

I've tried <P><Li>.... etc, but that doesn't work. I've tried <Li><P>... etc. but that doesn't work either.

Is there a solution to this issue?

I am simply wanteding my list styles to appears as list styles in word, and use the correct formatting.

Cheers
Reply With Quote
  #2  
Old 08-27-2023, 11:28 PM
Guessed's Avatar
Guessed Guessed is offline HTML To Word Styles Windows 10 HTML To Word Styles Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I don't have a solution for you while using the LI tags. I note that Word saving lists to html makes unnumbered lists more complex but it doesn't save to UL and LI. Instead it creates paragraph tags for
Code:
p class=MsoListParagraphCxSpFirst
p class=MsoListParagraphCxSpMiddle
p class=MsoListParagraphCxSpLast
If you have the ability to add the classes to the p tags, why is it hard to convert the UL/LI to the more simple P + class? Your CSS can apply the preferred bullets to a P tag
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-28-2023, 02:41 PM
Journeyman Journeyman is offline HTML To Word Styles Windows 10 HTML To Word Styles Office 2019
Novice
HTML To Word Styles
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default

Hi Andrew

Thanks again for your help on this.

I have the ability to change tags at runtime. No problem there. I have it running such that any class required convert to the word style (thanks to your previous inputs).

So I replaced MsoListBullet with MsoListParagraphCx5pFirst.

I tested this with an online HTML editor and my Web browser editor, neither of which produced the result I needed which was to display the bullets and numbers for the list in the editor, then reproduce those results in word.

i.e show bullets in htm -> show word style List bullet... etc

Now the word side works fine. I can output the class to word from the *.Htm doc, and get my classes working perfectly (from your previous solution). It's just that whenever I apply bullets into the htm document, the output result won't recognise the class.

<p Class=MsoListBullet>Test</p> 'Outputs to word style List Bullet But does not show a bullet in html document.
<Li Class=MsoListbullet>Test</Li> 'Output to word style as Normal, but shows bullet in document.

p class=MsoListParagraphCxSpFirst - outputs to word as new style MsoListParagraphCxSpFirst and does not include a bullet in the html editor.

I appreciate your responses, so thanks for efforts.

Cheers
Reply With Quote
  #4  
Old 08-30-2023, 05:50 PM
Journeyman Journeyman is offline HTML To Word Styles Windows 10 HTML To Word Styles Office 2019
Novice
HTML To Word Styles
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default

I have determined the following when converting html to Word...

Code:
<P Class=MsoBodyText>Body Text Test</P>
<P Class=MsoListNumber>Body Text Test</P>
<Ol>
<LI Class=MsoListNumber>Testing</LI>
<OL>
Word identifies the correct style to apply - provided the style is inside the P tag.
The LI tag is recognised by the HTML editor as a list item, but is not recognised by word as a style.

However...
Code:
<Ol>
<LI Class=MsoListNumber><P Class=MsoBodyText>Testing</P></LI>
<OL>
inserting the <P> tag inside the <LI> tag works and word picks up the style, while the HTML editor picks up the list.

The question then remains, how can I set the Paragraph inside the List?

This is a basic example of how I'm setting the class for the <LI> element

Code:
Dim rng as MSHTML.IHTMLTxtRange
Dim rngElement as MSHTML.HTMLDDElement
Set rng =WBControl.Object.Document.selection.CreateRange
Set rngElement = rng.ParentElement
rngelement.classname ="MsoListNumber"
So how might I be able to insert a P tag inside the LI tag, that contains the HTML text.

Or perhaps I'm going about this the wrong way.

To start with, I have text. How can I embed that text into both the LI tag and the P tag - such as above example?

Cheers
Reply With Quote
  #5  
Old 08-31-2023, 10:13 PM
Guessed's Avatar
Guessed Guessed is offline HTML To Word Styles Windows 10 HTML To Word Styles Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm not very elegant so I would be running a String Replace function on the entire html string
Code:
Find: <LI Class=MsoListNumber>
Replace with: <LI Class=MsoListNumber><P Class=MsoListNumber>

and 
Find: </LI>
Replace with: </p></LI>

Or if you didn't need the nested tags you could replace <LI and </LI> with <P and </P> respectively
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 09-04-2023, 02:33 PM
Journeyman Journeyman is offline HTML To Word Styles Windows 10 HTML To Word Styles Office 2019
Novice
HTML To Word Styles
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default

Hey Andrew and thanks for your input.

I ran with this and used

Code:
rngElement.innerHTML = "<P Class = MsoListNumber>Test</P>""
This inserts a <P> Tag into a <Li> tag. On the WebBrowser side this allows for the List Number, and in the word side, this allows for the Style to be picked up.

It's fine on the word side, since word picks up all the intended styles and applies them, however, on the webbrowser side, lists do not provide for sublists that include parent list numbers - unless you write the class into the /<head>.

In any case, it's workable and functions as required.

Thanks again for input.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML To Word Styles HTML Class to Word Styles Journeyman Word VBA 4 08-17-2023 09:03 PM
HTML To Word Styles Displaying in the Styles Pane Only the Styles You Actually Use -- Which Was a Snap in Word 2003 RobertB Word 4 08-09-2022 09:29 AM
Locking styles in Word using VBA to restrict new styles cadillac1206 Word VBA 1 04-21-2020 01:08 AM
HTML To Word Styles Self-created styles in Word to appear when converting to HTML anapat Word 2 05-11-2013 09:40 PM
Can you actually write HTML and CSS in a word document and send it as an html page jackaroo Word 0 07-12-2010 07:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft