8 Replies Latest reply on Apr 10, 2012 2:41 AM by கற்பனை (Imagine)

    expanding table columns?

    கற்பனை (Imagine) Level 3

      Hi All,

       

      Is there any formula for calculating the table columns cells size using the character count.  Each cells has the different chars count,  which are fetched from the lines of the table column cells. the maximum characters i got from the columns.  but How to assaign the width based on the columns chars values.

       

      Thanks in advance for any solution.

       

      Regards,

      Imagine.

        • 1. Re: expanding table columns?
          tiger886

          @ imagine ,hi i think u can used width and height  properties for different column.

          • 2. Re: expanding table columns?
            [Jongware] Most Valuable Participant

            A "formula", purely based on the count? No way, unless you happen to use a nonproportional font.

             

            Look:

            iiiiii is way less wide than

            mmmmmmm

             

            Theoretically you could calculate an "average character width" per font, but not my dividing the width of "abcdefghijklmnopqrstuvwxyz" by 26 -- that's way too naive. Each character width is influenced by its statistical occurrence in the language of your text (and then some more, by the subject -- in a book on accounting, there are way more digits than in, say, a ficiton novel (then again unless that's Real Hardcore Science Fiction, of course)).

            • 3. Re: expanding table columns?
              Jump_Over Level 5

              Assuming you are looking for one line proper cell width.

              If you will find the way to set column width bigger than content, you can fix the proper column width comparing .horizontalOffset property.

              If you will compare

              myTable[x].myCell[x].insertionPoints[0].horizontalOffset with myTable[x].myCell[x].insertionPoints[-1].horizontalOffset -

              - you will find the cell contents width.

              After this find Max of them in the same column looping row by row.

               

              If cell is overset - .horizontalOffset gives an error.

              • 4. Re: expanding table columns?
                கற்பனை (Imagine) Level 3

                Thanks to all for the replys...

                 

                 

                 

                Jump_Over wrote:

                 

                Assuming you are looking for one line proper cell width.

                If you will find the way to set column width bigger than content, you can fix the proper column width comparing .horizontalOffset property.

                If you will compare

                myTable[x].myCell[x].insertionPoints[0].horizontalOffset with myTable[x].myCell[x].insertionPoints[-1].horizontalOffset -

                - you will find the cell contents width.

                After this find Max of them in the same column looping row by row.

                 

                If cell is overset - .horizontalOffset gives an error.

                 

                I got the width of the line of cells using the codes.

                 

                var endPosition = myTable.cells[x].characters.lastItem().endHorizontalOffset;

                var startPosition = myTable.cells[x].characters.firstItem().horizontalOffset;

                 

                var mywidth = endPosition-startPosition;

                 

                If the problem is expanding the cells width (because suppose if the cells has the two lines of text,  but its possible to fix in the single line, so that i want to expanding the cell width) then recalculating the Highest cell lines width and find out the maximum of the width.

                 

                Is there any short methods or tricky way to achieve this task?

                 

                Thanks Jongware for the great explanation,  is there any alternative solution or tricks?

                • 5. Re: expanding table columns?
                  Jump_Over Level 5

                  You can set .noBreak = true to all cell contents so all cells will be one line or overflow. Looping for .overflows cells in a columns will lead you to resize them to proper width.

                  1 person found this helpful
                  • 6. Re: expanding table columns?
                    [Jongware] Most Valuable Participant

                    கற்பனை (Imagine) wrote:

                     

                    Thanks Jongware for the great explanation,  is there any alternative solution or tricks?

                     

                    There are no tricks, you have to set the width and then see if it got better or worse.

                     

                    One of these approaches might work for you:

                    (1) set the column width to some small number, then while the number of lines does not equal the number of paragraphs, increase width

                    (2) set the column width to some big number, then decrease width until the number of lines does not equal the number of paragraphs.

                     

                    This works on single cells that don't already start overflown (place your text cursor inside any cell):

                     

                    stepsize = 1; // 1 unit size adjustments
                    cell = app.selection[0];
                    if (!(cell instanceof Cell))
                    cell = cell.parent;
                    if (cell instanceof Cell)
                    {
                    n_paragraphs = cell.paragraphs.length;
                    while (cell.width > 2*stepsize && !cell.overflows)
                      cell.width -= stepsize;
                    // revert one step (cell overflowed last time)
                    cell.width += stepsize;
                    while (cell.lines.length > n_paragraphs)
                      cell.width += stepsize;
                    }
                    

                     

                    Adjust per your requirements.

                    • 7. Re: expanding table columns?
                      கற்பனை (Imagine) Level 3

                      fantastic.  Thanks both.

                      • 8. Re: expanding table columns?
                        கற்பனை (Imagine) Level 3

                        Hi,

                         

                        This algorithm fails in certain cases, number of paragraphs and lines are equal means it doesn't reduce the unwanted white spaces in the table columns.  Is there any possiblity to do this.

                         

                        Error.jpg

                        Any suggestion for doing this kind of jobs.