Results 1 to 16 of 16

Thread: text with layout

  1. #1

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    text with layout

    I have posted under traditional VB since that is what I am using but it seems this could be viewed as an office problem
    http://www.vbforums.com/showthread.p...49#post2526649

    Word 2003 removed the save as "text with layout"
    option which is what I used.
    I am looking to take an RTF file from word and make a text file that has only spaces and CR/LF
    BUT
    I need to save the layout so an indented paragraph should have spaces added to the line so that it lines up like it used to.
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: text with layout

    do you want to write code to do this or just a simple solution, which could be put into code anyway?

    find all tabs and replace with spaces (however many spaces to make it look right). if you have tabs in other parts of your document it may give a problem, but that could filtered by sections

    pete

  3. #3

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    I guess I am open to anything right now.
    Replacing the tabs is the simple part.
    the thing I can't get my head around is the indented paragraphs.
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  4. #4

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    help, I am trying to work with paraformat2 and I am having a hard time.

    here is the code I am dealing with.
    Command1_Click() gets me the text just fine but it looses the indenting.
    it looked like paraformat2 could query the line and tell me its indent.
    with the text, and the indent I would be able to pad the front of the text with spaces.

    can someone help me with the paraformat2 type declaration and how to use the EM_GETPARAFORMAT sendmessage?

    thanks

    VB Code:
    1. Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2. Private Declare Function SendMessageAsString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    4. Const WM_USER = &H400
    5. Const EM_GETPARAFORMAT = (WM_USER + 61)
    6. Const EM_SETPARAFORMAT = (WM_USER + 71)
    7. Const MAX_TAB_STOPS = 32&
    8. Const PFM_LINESPACING = &H100&
    9. Const EM_GETLINE = &HC4
    10. Const EM_GETLINECOUNT = 186&
    11. Const EM_GETWORDBREAKPROC = &HD1
    12. Const EM_LIMITTEXT = &HC5
    13. Private Type PARAFORMAT2
    14.     cbSize As Integer
    15.     wPad1 As Integer
    16.     dwMask As Long
    17.     wNumbering As Integer
    18.     wReserved As Integer
    19.     dxStartIndent As Long
    20.     dxRightIndent As Long
    21.     dxOffset As Long
    22.     wAlignment As Integer
    23.     cTabCount As Integer
    24.     lTabStops(0 To MAX_TAB_STOPS - 1) As Long
    25.     dySpaceBefore As Long          ' Vertical spacing before para
    26.     dySpaceAfter As Long           ' Vertical spacing after para
    27.     dyLineSpacing As Long          ' Line spacing depending on Rule
    28.     sStyle As Integer              ' Style handle
    29.     bLineSpacingRule As Byte       ' Rule for line spacing
    30.     bCRC As Byte                   ' Reserved for CRC for rapid searching
    31.     wShadingWeight As Integer      ' Shading in hundredths of a per cent
    32.     wShadingStyle As Integer       ' Nibble 0: style, 1: cfpat, 2: cbpat
    33.     wNumberingStart As Integer     ' Starting value for numbering
    34.     wNumberingStyle As Integer     ' Alignment, roman/arabic, (), ), .,     etc.
    35.     wNumberingTab As Integer       ' Space between 1st indent and 1st-line text
    36.     wBorderSpace As Integer        ' Space between border and text(twips)
    37.     wBorderWidth As Integer        ' Border pen width (twips)
    38.     wBorders As Integer            ' Byte 0: bits specify which borders; Nibble 2: border style; 3: color                                     index*/
    39. End Type
    40. Private Sub Command2_Click()
    41. Dim parastruct As PARAFORMAT2
    42. With parastruct
    43.     .cbSize = Len(para)
    44.     .dwMask = PFM_LEFTINDENT
    45. End With
    46. SendMessage RichTextBox1.hwnd, EM_GETPARAFORMAT, ByVal 0&, parastruct
    47. MsgBox "what"
    48. End Sub
    49.  
    50.  
    51. Private Sub Command1_Click()
    52.     Dim iFileNummer                     As Integer
    53.     Dim lCount                          As Long
    54.     Dim lLineCounter                    As Long
    55.     Dim x                               As Long
    56.     Dim Buffer                          As String
    57.    
    58.     iFileNummer = FreeFile
    59.     Open "c:\temp\export.txt" For Output As #iFileNummer
    60.     lCount = SendMessageAsLong(RichTextBox1.hwnd, EM_GETLINECOUNT, 0&, 0&)
    61.     For lLineCounter = 0 To lCount
    62.         j
    63.         Buffer = Space$(255)
    64.         x = SendMessageAsString(RichTextBox1.hwnd, EM_GETLINE, lLineCounter, Buffer)
    65.         Print #iFileNummer, Left$(Buffer, x)
    66.     Next lLineCounter
    67.     Close #iFileNummer
    68. End Sub
    Last edited by badgers; Jun 29th, 2006 at 03:58 PM.
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  5. #5

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    hello, any ideas?
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: text with layout

    send me a sample document and i will look at it

    pete

  7. #7

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    take a look at the attached.
    Attached Files Attached Files
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  8. #8

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    taking a look at the api call, I would need to index the call so that I get the format of the current line I am dealing with.

    any idea on how to get that set or setup?
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  9. #9

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    maybe this api is not the way to go.
    My real intent is to find out how a paragraph is indented so that I can add spaces to the text.

    For those who PM me,
    I can get the TEXT. My goal is getting it formatted with spaces and hard returns so it looks close to the original.

    being one space off won't kill me, so if something is indented .2" and 4 spaces is a little short, that is OK, but I want to know if it is .2" or .4" of indent.. that is the real trick..

    thanks
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: text with layout

    VB Code:
    1. For Each p In ActiveDocument.Paragraphs
    2. n = ActiveDocument.Name
    3.     ind = p.LeftIndent
    4.     hang = p.CharacterUnitLeftIndent
    5. '    for each
    6. Next

    left indent returned 18 on the first paragraphs of the sample file, i believe that is 18 points, ¼".

    i was looking at that, but hadn't decided yet what could be done with it as the paragraph is a single line in the RTF file, before word wrapping

    the line indent in the RTF code (/li360) varied a lot, but shows as 360 in many instances, which also converts to ¼"

    you can read the RTF code for each paragraph, then apply that as you get each paragraph of text.

    pete

    edit: in vb you can use textwidth to make the number of spaces very accurate for the length of the gap you want to insert
    VB Code:
    1. strl = (leftindent) / TextWidth(" ")
    2. mystr = Space(strl)

    remember that the font face and size will change the textwidth, so set the font of the form or a picture box to the required font if it is not a same font, unless you are printing it direct, then use the printers textwidth
    Last edited by westconn1; Jul 8th, 2006 at 03:01 AM.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: text with layout

    here is code that reads your sample file and saves it as text file with spaces to format the document with indents.

    so far i have not done anything to word wrap the longer lines of text, but that will not be too hard to do, just not tonight, try the code on seversl files, see how many bugs in it.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Integer, pos As Integer, mytest, pos1 As Integer
    3.  
    4. Dim li As Integer, strfi As String, f1 As Integer, arrfi() As String, pard As Boolean
    5. Dim tlen As Integer, myind As String
    6.  
    7.  
    8. f1 = FreeFile
    9. Open "spec.rtf" For Input As f1
    10.     strfi = Input(LOF(f1), #f1)
    11. Close f1
    12. pard = False
    13. arrfi = Split(strfi, vbNewLine)
    14.  
    15. Open "spec.txt" For Output As f1
    16. For i = 0 To UBound(arrfi)
    17.     If pard = False Then
    18.         If InStr(1, arrfi(i), "\pard") = 0 Then
    19.             GoTo notyet
    20.             Else: pard = True
    21.         End If
    22.     End If
    23.     pos = InStr(1, arrfi(i), "\li")
    24.         If Not pos = 0 Then
    25.             pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
    26.             mytest = Mid(arrfi(i), pos + 3, pos1)
    27.             If Left(mytest, 1) = "n" Then
    28.                 pos = InStr(pos + 1, arrfi(i), "\li")
    29.                 If Not pos = 0 Then
    30.                     pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
    31.                     mytest = Mid(arrfi(i), pos + 3, pos1)
    32.                 End If
    33.             End If
    34.             li = Val(mytest)
    35. '            Debug.Print li, i
    36.         End If
    37.     mytest = ""
    38.     tlen = li / 4 / TextWidth(" ")
    39.     myind = Space(tlen)
    40.     pos = InStrRev(arrfi(i), "\")
    41.     If pos = 0 Then
    42.         mytest = arrfi(i)
    43.         Else
    44.         pos = InStr(pos + 1, arrfi(i), " ")
    45.         If pos = 0 Then Stop
    46.         pos1 = Len(arrfi(i))
    47.         If Not Len(arrfi(i)) = pos Then mytest = Right(arrfi(i), Len(arrfi(i)) - pos)
    48.     End If
    49.     If mytest = "" Or mytest = "}}" Then mytest = " "
    50.     If Left(mytest, 1) = "{" Then mytest = Right(mytest, Len(mytest) - 1)
    51. notyet:
    52.     If Not mytest = "" Then Print #f1, myind & mytest 'mytest = "not yet"
    53.    
    54. Next
    55. Close f1
    56.  
    57. Exit Sub

    pete

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: text with layout

    here is some updated code to word wrap the lines, it is not perfect, but yopushould be able to play around with it to make any improvements needed

    pete

    VB Code:
    1. Private Function wordwrap(mystring As String, indent As String)
    2. Dim arrwords() As String, i As Integer, newstr As String, longstr As String
    3. arrwords = Split(mystring)
    4. newstr = indent
    5. For i = 0 To UBound(arrwords)
    6.     If Not TextWidth(newstr & arrwords(i)) > 6300 Then
    7.         newstr = newstr & arrwords(i) & Space(1)
    8.     Else
    9.     If longstr = "" Then
    10.         longstr = newstr
    11.             Else
    12.             longstr = longstr & vbNewLine & indent & newstr
    13.             End If
    14.             newstr = indent & arrwords(i) & Space(1)
    15.            
    16.     End If
    17. Next
    18. If longstr = "" Then
    19.     wordwrap = newstr
    20.     Else: wordwrap = longstr & vbNewLine & indent & indent & newstr
    21. End If
    22. End Function
    23. Private Sub Command1_Click()
    24. Dim i As Integer, pos As Integer, mytest As String, pos1 As Integer
    25.  
    26. Dim li As Integer, strfi As String, f1 As Integer, arrfi() As String, pard As Boolean
    27. Dim tlen As Integer, myind As String
    28.  
    29.  
    30. f1 = FreeFile
    31. Open "spec.rtf" For Input As f1
    32.     strfi = Input(LOF(f1), #f1)
    33. Close f1
    34. pard = False
    35. arrfi = Split(strfi, vbNewLine)
    36.  
    37. Open "spec.txt" For Output As f1
    38. For i = 0 To UBound(arrfi)
    39.     If pard = False Then
    40.         If InStr(1, arrfi(i), "\pard") = 0 Then
    41.             GoTo notyet
    42.             Else: pard = True
    43.         End If
    44.     End If
    45.     If Not i = UBound(arrfi) Then
    46.         If Not Left(arrfi(i + 1), 1) = "\" Then
    47.             arrfi(i) = arrfi(i) & arrfi(i + 1)
    48.             arrfi(i + 1) = ""
    49.         End If
    50.     End If
    51.     pos = InStr(1, arrfi(i), "\li")
    52.         If Not pos = 0 Then
    53.             pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
    54.             mytest = Mid(arrfi(i), pos + 3, pos1)
    55.             If Left(mytest, 1) = "n" Then
    56.                 pos = InStr(pos + 1, arrfi(i), "\li")
    57.                 If Not pos = 0 Then
    58.                     pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
    59.                     mytest = Mid(arrfi(i), pos + 3, pos1)
    60.                 End If
    61.             End If
    62.             li = Val(mytest)
    63. '            Debug.Print li, i
    64.         End If
    65.     mytest = ""
    66.     tlen = li / 4 / TextWidth(" ")
    67.     myind = Space(tlen)
    68.     pos = InStrRev(arrfi(i), "\")
    69.     If pos = 0 Then
    70.         mytest = arrfi(i)
    71.         Else
    72.         pos = InStr(pos + 1, arrfi(i), " ")
    73.         If pos = 0 Then Stop
    74.         pos1 = Len(arrfi(i))
    75.         If Not Len(arrfi(i)) = pos Then mytest = Right(arrfi(i), Len(arrfi(i)) - pos)
    76.     End If
    77.     If mytest = "" Or mytest = "}}" Then mytest = " "
    78.     If Left(mytest, 1) = "{" Then mytest = Right(mytest, Len(mytest) - 1)
    79. '    If i = 37 Then Stop
    80.         mytest = wordwrap(mytest, myind)
    81. notyet:
    82.     If Not mytest = "" Then Print #f1, mytest  'mytest = "not yet"
    83.    
    84. Next
    85. Close f1
    86. Shell "notepad.exe spec.txt"
    87. Stop
    88. Exit Sub

  13. #13

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    Thanks for all that you have done.
    I will have to wait until I get back in the office to test it.

    again, I apprecite your help
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  14. #14

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    I have run the code and this is what I am getting
    Code:
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    Fire Alarm Equipment Specifications 
    >080< 
    Manual Pull Station 
        
      box cover at 44" AFF. 
      
      
    >090< 
    15 Candela Fire Alarm Horn/Strobe 
        
      Simplex #4903-9428 Audible/Visible unit (15 Candela, 1 Hz flash rate, off-white w/Red 
          "FIRE").  Mount on recessed 4" square box with bottom of unit at 80" AFF. 
      
      
    >093< 
    110 Candela Fire Alarm Horn/Strobe 
        
      Simplex #4903-9430 Audible/Visible unit (110 Candela, 1 Hz flash rate, off-white w/Red 
          "FIRE").  Mount on recessed 4" square box with bottom of unit at 80" AFF. 
      
      
    >095< 
    Fire Alarm Horn only 
        
      Simplex #4901-9820 Horn with 4905-9989 cover (White). 
      
    Mount on recessed 4" square box with bottom of unit at 80" AFF. 
      
    >100< 
    15 Candela Fire Alarm Strobe only 
        
      Simplex #4904-9342 Visible Only Unit (15 Candela, 1 Hz flash rate, off-white w/Red 
        "FIRE").  Mount on recessed 4" square box with single gang plaster ring with bottom of 
          the unit at 80" AFF. 
      
      
    >105< 
    110 Candela Fire Alarm Strobe only 
        
      Simplex #4904-9344 Visible Only Unit (110 Candela, 1 Hz flash rate, off-white w/Red 
        "FIRE").  Mount on recessed 4" square box with single gang plaster ring with bottom of 
          the unit at 80" AFF. 
      
      
    >110< 
    Photoelectric Smoke Detector 
        
      Simplex #4098-9601 detector w/ #4098-9788 base, surface mount on suspended 
          ceiling on 4" octagonal box. 
      
      
    >120< 
    Photoelectric Duct Smoke Detector 
        
      Simplex #4098-9686 smoke/housing & appropriate sampling tube, mount w/ sampling 
          tube in air stream or air duct. 
      
      
    >130< 
    Photoelectric Smoke Detector w/ Aux. DPDT Relay Contacts 
        
      Simplex #4098-9601 detector w/ #4098-9682 base with relay, surface mount on 
          suspended ceiling on 4" octagonal box. 
      
      
    >140< 
    Heat Detector 
        
      Simplex #4098-9613 detector w/ #4098-9682 base rate of rise (15 degree F/min) and 
        fixed temperature (136 degree F) heat detector. Mount on recessed 4" octagonal box in 
          ceiling. 
      
    >150< 
    Fixed Temperature Heat Detector 
        
      Simplex #4098-9612 detector w/ #4098-9682 base 135 degree  F fixed point detector 
          w/2 normally open contacts. Mount on 4" octagonal box. 
      
    >160< 
    Remote Test / Alarm Indicator Station 
        
      box cover at 54" AFF. 
      
    >170< 
    Smoke Damper 
        
      damper motor.  Wired by EC. 
      
    >180< 
    Sprinkler Flow Switch 
        
      SPDT contacts provided by Sprinkler Contractor, wired by EC. 
      
    >190< 
    Sprinkler Tamper Switch 
        
      Switch w/normally closed contacts provided by Sprinkler Contractor, wired by EC. 
      
    >200< 
    Fire/Smoke Door 
        
      link (re-usable), wired by EC. 
      
    >210< 
    Fire Alarm Control & Annunciator Panel Specifications 
    >220< 
    Simplex #4004 series, 24V DC Fire Alarm with: 
    >230< 
    Simplex #4005 series, 24V DC Fire Alarm with: 
    >260< 
    4 hour battery 
    >270< 
    24 hour battery monitoring plus 5 minute alarm 
    >280< 
    Provision for 24VDC reverse polarity city fire dept. signal module 
    >285< 
    LED annunciator panel. 
    >290< 
    status command unit (SCU) remote annunciator panel. 
    >300< 
    Fire Alarm Zones 
    >310< 
      
    1st Floor 
    2nd Floor 
    3rd Floor 
    Sprinkler Flow Switches 
    Spare 
    Spare 
    Spare 
    Spare 
      
    >320< 
      
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
      
    >330< 
      
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
      
    >340< 
      
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
    Spare 
      
    >350< 
    See Details on Sheet E7 
    >000<
    Attached Files Attached Files
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  15. #15

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Re: text with layout

    what I see is the first line of indented text gets whacked and the second line of indented text gets double indent.


    thanks for all you have done.
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: text with layout

    i wrote this code in word, with your file already open, gave great result

    VB Code:
    1. Sub formatrtf()
    2.  
    3. Dim p As Paragraph
    4.  
    5. For Each p In ActiveDocument.Paragraphs
    6.     If p.LeftIndent > 0 Or p.FirstLineIndent > 0 Then
    7.     mystring = mystring & Space(3)
    8.    
    9.     End If
    10.     If Len(p.Range.Text) > 65 Then
    11.     thisp = wordwrap(p.Range.Text, 65)
    12.     Else: thisp = p.Range.Text
    13.     End If
    14.     mystring = mystring & thisp & vbNewLine
    15.  
    16. Next
    17.  
    18. Open "spec.txt" For Output As 1
    19.     Print #1, mystring
    20. Close 1
    21.  
    22. End Sub
    23. Private Function wordwrap(mystring As String, chars As Long)
    24. Dim arrwords() As String, i As Integer, newstr As String, longstr As String
    25. arrwords = Split(mystring)
    26. 'newstr = indent
    27.  
    28. For i = 0 To UBound(arrwords)
    29.     If Not Len(newstr & arrwords(i)) > chars Then
    30.         newstr = newstr & arrwords(i) & Space(1)
    31.     Else
    32.     If longstr = "" Then
    33.         longstr = newstr
    34.             Else
    35.             longstr = longstr & vbNewLine & Space(3) & newstr
    36.             End If
    37.             newstr = arrwords(i) & Space(1)
    38.            
    39.     End If
    40. Next
    41.     wordwrap = longstr & vbNewLine & Space(3) & newstr
    42. End Function
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width