Results 1 to 7 of 7

Thread: [RESOLVED] How to add HTML tag <br> automatically fit table column width

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [RESOLVED] How to add HTML tag <br> automatically fit table column width

    The sample text is:
    Code:
    lRow = 3
    lCol = 3
    .Cell(lRow,lCol).Text =  _
             "Clipboard Support : " & vbNewLine & _
              vbNewLine & _
              "   The grid content can be copied, cut and pasted freely." & vbNewLine & _
              "   The grid can interact with some other software such as Excel, it can copy & paste f/t Excel and smartly keep the cell attributes and styles. "
    The column (lCol = 3) width is 400 pixels.

    In Grid, the last long line can automatically break lines (Wrap text) by assign wFormat = DT_MODIFYSTRING Or DT_EDITCONTROL Or DT_NOPREFIX Or DT_WORDBREAK

    But after I parse Grid content to HTML, the width of column 3 get too long showing in browser. The last column (lCol=3) got resized, the first column (lcol=0) got shrink.

    If I delete the long line, the format are in good place. All column widths follow the assignment.

    Code:
    <body>
    <table border=0 cellspacing=0 cellpadding=2 width=608 style="border-collapse:collapse">
      <tr height=0>
        <td width=40></td>
        <td width=150></td>
        <td width=18></td>
        <td width=400></td>
      </tr>
    I already specify the table width but why browser parser differently?

    Sure I can use hardcode by calculate width of every word then add <br>. Any better way (add some tags in HTML) to fix the column's width and the long line automatically wrap?

    Code:
    </tr>
      <tr height=200>
    <td class="s3 f2">Clipboard&nbsp;Support&nbsp;:&nbsp;<br><br>&nbsp;&nbsp;&nbsp;The&nbsp;grid&nbsp;content&nbsp;can&nbsp;be&nbsp;copied,&nbsp;cut&nbsp;and&nbsp;pasted&nbsp;freely.<br>&nbsp;&nbsp;&nbsp;The&nbsp;grid&nbsp;can&nbsp;interact&nbsp;with&nbsp;some&nbsp;other&nbsp;software&nbsp;such&nbsp;as&nbsp;Excel,&nbsp;it&nbsp;can&nbsp;copy&nbsp;&amp;&nbsp;paste&nbsp;f/t&nbsp;Excel&nbsp;and&nbsp;smartly&nbsp;keep&nbsp;the&nbsp;cell&nbsp;attributes&nbsp;and&nbsp;styles.&nbsp;</td>
    </tr>
    Edited:
    Post edited.
    Attached Images Attached Images   
    Last edited by Jonney; Sep 20th, 2015 at 07:40 PM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to add HTML tag <br> automatically fit table column width

    attach the htm file

    Edited: delete the attached HTML zip file to save my space (71KB) in VBForums.

    If someone need it, please PS me.
    Last edited by Jonney; Sep 21st, 2015 at 07:19 AM.

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to add HTML tag <br> automatically fit table column width

    How are you using the HTML?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to add HTML tag <br> automatically fit table column width

    Quote Originally Posted by jmsrickland View Post
    How are you using the HTML?
    ExportToHTML is a parser, output Grid content to HTML.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to add HTML tag <br> automatically fit table column width

    Post edited.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to add HTML tag <br> automatically fit table column width

    OK. Create the table and td style to specify our desired style.
    Code:
    <style>
     table {border-collapse:collapse; table-layout:fixed; width:608px;}
     table td {word-wrap:break-word;}
    </style>
    Last edited by Jonney; Sep 20th, 2015 at 10:29 PM.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to add HTML tag <br> automatically fit table column width

    Quote Originally Posted by Jonney View Post
    OK. Create the table and td style to specify our desired style.
    Code:
    <style>
     table {border-collapse:collapse; table-layout:fixed; width:608px;}
     table td {word-wrap:break-word;}
    </style>
    improve further:
    Code:
    <style>
     table {border-collapse:collapse; table-layout:fixed; width:608px;}
     table td {white-space: -o-pre-wrap; word-wrap: break-word;white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; }
    </style>

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