#1
|
|||
|
|||
formatting from word in xml
Hello i have written a code that creates a xml file from a word document. sometimes a paragraph from the word document hase different formattings for example the first two words are written strong. at this point i copied the hole range into a string that gets printed into a xml file. the problem is that in the xml file i loose all the formattings like bold italic or underlined. can you help me with this problem? |
#2
|
||||
|
||||
The problem is "i copied the whole range into a string". By definition, strings don't contain any formatting information.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
but any idea how i can go around this problem. is it possible to search for formatted words only in my range that i am working with. i need to put "<strong>" infront of the bold words and "</strong>" after them. |
#4
|
||||
|
||||
You really haven't provided anywhere near enough information for anyone to work with. You've supplied no code, no source material or an example of what it's supposed to look like at the destination. I can't even tell from what you've posted whether strong should end up in the output looking like strong or <b>strong</b>, for example.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
alright.
so the code is not really necessary. i go from heading to heading and look what is unter the heading. if there is a table i go from wdCell to next wdCell and work with the cells. Code:
For Each wdCell In ActiveDocument.Tables(ThisTableNumber).Range.Cells Set Rng1 = wdCell.Range Rng1.End = Rng1.End - 1 If Rng1.Font.Bold = True Then Set Rng2 = wdCell.Next.Range Rng2.End = Rng2.End - 1 Select Case Rng1.Text Case "Name": TestcaseString = TestcaseString & "<name>" & Rng2 & "</name>" & vbCrLf if the Rng2 looks like: "Hello, This is Tom. Im 21 yrs old." the whole formatting gets lost. my xml file needs this formatting. a bold word needs to look like "<strong>word</strong>" in the xml file. and this is where i need some help or ideas. |
#6
|
||||
|
||||
There are some serious issues with your code snippet:
1. unless the whole cell range is bold, your code won't recognise it; 2. it unnecessarily processes every cell; 3. by referencing wdCell.Next.Range you're liable to produce an error when wdCell inevitably ends up as the last cell in the table; and 4. there is no indication of any xml file existing for the output. Without knowing more about the table structure, there's not much more help I can give on that front. That said, applying the tags really doesn't require testing the contents of each & every cell. It can be done far more efficiently via Find/Replace. For example: Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Replacement.Text = "" .Format = True .Font.Bold = True .Forward = True .Wrap = wdFindStop .Execute End With Do While .Find.Found .Text = "<strong>" & .Text & "</strong>" .Font.Bold = False .Collapse wdCollapseEnd .Find.Execute Loop End With With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Replacement.Text = "" .Format = True .Font.Italic = True .Forward = True .Wrap = wdFindStop .Execute End With Do While .Find.Found .Text = "<emphasis>" & .Text & "</emphasis>" .Font.Italic = False .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
thank you for your code.
the code i posted is just a part of my whole code. my code is as almost finished and works fine for the tables. its just the problem with formatting. your code works fine until this point: Code:
Do While .Find.Found .Text = "<strong>" & .Text & "</strong>" .Font.Bold = False .Collapse wdCollapseEnd .Find.Execute Loop at one point i set a range with this code Code:
Do Until Selection.Style Like "Überschrift*" = True Selection.MoveDown Unit:=wdParagraph, count:=1 Loop ende = Selection.End Set bereich = ActiveDocument.Range(anfang, ende) Code:
For Each wdCell In ActiveDocument.Tables(ThisTableNumber + 1).Range.Cells Set Rng1 = wdCell.Range Rng1.End = Rng1.End - 1 If Rng1.ListFormat.ListType = 3 Then If Steps = False Then TestcaseString = TestcaseString & "<steps>" & vbCrLf Steps = True End If Set Rng2 = wdCell.Next.Range |
#8
|
||||
|
||||
Quote:
Code:
Do While .Find.Found If .InRange(some predefined range) Then ' do stuff here Else: Exit Do End If .Collapse wdCollapseEnd .Find.Execute Loop
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Formatting contents after Tab of continuous lines or formatting specific area of word | pawii | Word | 1 | 05-12-2014 05:24 AM |
Formatting is restricted in Word 2007 but not in Word 2010 | Word2007User | Word | 2 | 01-11-2014 06:33 PM |
Word 2013 vs Word 2010 formatting issue? | rhoyt | Word | 1 | 12-07-2013 09:40 AM |
Formatting from PDF to WORD | goldfish | Word | 8 | 04-25-2011 04:50 PM |
Word Formatting | Peter B. | Word | 5 | 05-10-2006 08:13 AM |