Loading ...
Sorry, an error occurred while loading the content.
 

Sorting HTML tables solved (this time working, hopefully ;)

Expand Messages
  • Ville Saalo
    ... D oh, someone could have told me that... Here we go again. Copy everything after this line. Watch out for the long lines. = V5 MultiLine NoSorting
    Message 1 of 1 , Sep 29, 2002
      >>> I'll put the library here as an attachment, TableStuff.clb. I
      >>> don't think it should be published yet
      >>The text of your message reads like you thought you'd attached
      >>the clip within. You didn't! ... but I'd like to see it ;-)
      >You cannot send attachments to the lists.

      D'oh, someone could have told me that... Here we go again.
      Copy everything after this line. Watch out for the long lines.

      = V5 MultiLine NoSorting TabWidth=30

      H=";Table Stuff"
      This library is used to collapse, expand and/or resort HTML table columns. Try these with your own
      responsibility, it is suggested to first test these with a backup copy of your original file.

      All clips but the 'Resort table' are made by Ville Saalo, 'Resort table' is made by Hugo Paulissen
      (pretty damn smart coding of him, got to admit (and admire). :) 'Resort table' is then boosted just
      a little bit by me, see the comments in that clip. It doesn't work if the table is not collapsed and
      I thought I'd make the collapsing clip a separate one because it might be handy in other cases also.
      Expand table is just a cosmethic thing. :)

      The clips assume that your code is well-formed.

      'Select table' clip selects the table you are in (without the starting or ending tags).
      'Collapse table' puts all the <TD's to the same line with the <TR if they were in different lines.
      'Resort table' asks the target order of the columns and resorts them.
      'Expand table' is a reverse action of the Collapse table clip, it puts each <TD on its own line.

      "Run 'em All!" runs all the clips above, in that order.

      September 29, 2002 (about two hours past midnight)
      -Ville Saalo, villes@...

      H=" "


      H="Run 'em All!"
      ^!SetScreenUpdate OFF
      ^!Clip "Select table"
      ^!Clip "Collapse table"
      ^!Clip "Resort table"
      ^!Clip "Expand table"
      ^!Select 0
      ^!Prompt All done.

      H=" "


      H="Select table"
      ^!SetScreenUpdate OFF
      ^!Find "</TABLE>" IS
      ^!Jump SELECT_START
      ^!Set %r%=^$GetRow$
      ^!Set %c%=^$GetCol$
      ^!Find "<TABLE" BIS
      ^!Select HTMLTAG
      ^!Jump SELECT_END
      ^!SelectTo ^%r%:^%c%

      H="Collapse table"
      ^!SetScreenUpdate OFF
      ^!StatusShow Collapsing your table...
      ^!Replace "<TR{[^>]*}>\b*" >> "<TR\1>" RATHIS
      ^!StatusShow ...some half of the table collapsing done...
      ^!Replace "</T{D|H}>\b*" >> "</T\1>" RATHIS
      ^!StatusShow ...table collapsing almost done...
      ^!Replace "\b*</TR>" >> "</TR>" RATHIS

      H="Resort table"
      ;Created by Hugo Paulissen
      ;#########################
      ;The next line is commented by Ville Saalo:
      ;^!Continue This clip will only work if you have selected a table...
      ^!Set %tds%=^$StrCount("<td";"^$GetSelection$";0;0)$
      ^!Set %trs%=^$StrCount("<tr";"^$GetSelection$";0;0)$
      ;VS, added 3
      ^!IfFalse ^%tds% NEXT ELSE SKIP_2
      ^!Prompt You don't have a proper HTML table selected. Aborting clip.
      ^!Goto END
      ^!Set %columns%=^?{How many columns do you have in your table?=^$Calc(^%tds%/^%trs%)$}
      ^!Set %order%=^?{(M="^$StrFill( 0;^%columns%)$")Now enter the new order (eg. 1 2 4
      3 )...=^%columns%}
      ;VS, added 1:
      ^!StatusShow Working...
      ^!Set %order%=^$strReplace(" ";"\";^%order%;0;0)$
      ;VS, replaced 1 line:
      ;^!Replace "^$StrFill({<td>.*</td>}\s*;^%columns%)$" >> "^%order%" HIRAS
      ^!Replace "^$StrFill({<td.*</td>}\s*;^%columns%)$" >> "^%order%" HIRAS

      H="Expand table"
      ^!SetScreenUpdate OFF
      ; The %empty% variable is for indentation: by default it contains two blank spaces
      ^!Set %empty%=
      ^!StatusShow Expanding your table...
      ^!Replace "<T{D|H}" >> "\n^%empty%^%empty%<T\1" HISRAT
      ^!StatusShow ..table almost expanded...
      ^!Replace "</TR>" >> "\n^%empty%</TR>" HISRAT



      ;End of message, this line doesn't need to be copied :)
    Your message has been successfully submitted and would be delivered to recipients shortly.