Return an array with the width of each column

        If a specific width has been specified, exit. If the total of the
        columns width exceed the table desired width, another width will be
        computed to fit, and cells will be wrapped.
341356
def _compute_cols_width(self):
        

        if hasattr(self, "_width"):
            return
        maxi = []
        if self._header:
            maxi = [ self._len_cell(x) for x in self._header ]
        for row in self._rows:
            for cell,i in zip(row, range(len(row))):
                try:
                    maxi[i] = max(maxi[i], self._len_cell(cell))
                except (TypeError, IndexError):
                    maxi.append(self._len_cell(cell))
        items = len(maxi)
        length = reduce(lambda x,y: x+y, maxi)
        if self._max_width and length + items*3 + 1 > self._max_width:
            maxi = [(self._max_width - items*3 -1) / items \
                for n in range(items)]
        self._width = maxi
1113055
public void widthTable(XWPFTable table, float widthCM, int rows, int cols) {
        TableTools.widthTable(table, widthCM, cols);
        TableTools.borderTable(table, 4);
    }
930539
def convert_table(self, block):
        """""""
        lines_orig = block.split('\n')
        lines_orig.pop() # Remove extra newline at end of block
        widest_cell = [] # Will hold the width of the widest cell for each column
        widest_word = [] # Will hold the width of the widest word for each column
        widths = []      # Will hold the computed widths of grid table columns

        rows = []   # Will hold table cells during processing
        lines = []  # Will hold the finished table

        has_border = False  # Will be set to True if this is a bordered table

        width_unit = 0.0 # This number is used to divide up self.width according
                         # to the following formula:
                         #
                         # self.width = width_unit * maxwidth
                         #
                         # Where maxwidth is the sum over all elements of
                         # widest_cell.

        # Only process tables, leave everything else untouched

        if not self.test(None, block):
            return lines_orig

        if lines_orig[0].startswith('|'):
            has_border = True

        # Initialize width arrays

        for i in range(0, len(self._split_row(lines_orig[0], has_border))):
            widest_cell.append(0)
            widest_word.append(0)
            widths.append(0)

        # Parse lines into array of cells and record width of widest cell/word

        for line in lines_orig:
            row = self._split_row(line, has_border)
            # pad widest_cell to account for under length first row
            for i in range(0, len(row) - len(widest_cell)):
                widest_cell.append(0)
                widest_word.append(0)
                widths.append(0)
            for i in range(0, len(row)):
                # Record cell width
                if len(row[i]) > widest_cell[i]:
                    widest_cell[i] = len(row[i])
                # Record longest word
                words = row[i].split()
                for word in words:
                    # Keep URLs from throwing the word length count off too badly.
                    match = re.match(r'\[(.*?)\]\(.*?\)', word)
                    if match:
                       word = match.group(1)

                    if len(word) > widest_word[i]:
                        widest_word[i] = len(word)
            rows.append(row)

        # Remove table header divider line from rows
        rows.pop(1)

        # Compute first approximation of column widths based on maximum cell width

        for width in widest_cell:
            width_unit += float(width)

        width_unit = self.width / width_unit

        for i in range(0, len(widest_cell)):
            widths[i] = int(widest_cell[i] * width_unit)

        # Add rounding errors to narrowest column
        if sum(widths) < self.width:
            widths[widths.index(min(widths))] += self.width - sum(widths)

        # Attempt to correct first approximation of column widths based on
        # words that fail to fit their cell's width (if this fails textwrap
        # will break up long words but since it does not add hyphens this
        # should be avoided)

        for i in range(0, len(widths)):
            if widths[i] < widest_word[i]:
                offset = widest_word[i] - widths[i]
                for j in range(0, len(widths)):
                    if widths[j] - widest_word[j] >= offset:
                        widths[j] -= offset
                        widths[i] += offset
                        offset = 0

        lines.append(self.ruler_line(widths, linetype='-'))

        # Only add header row if it contains more than just whitespace
        if ''.join(rows[0]).strip() != '':
                lines.extend(self.wrap_row(widths, rows[0]))
                lines.append(self.ruler_line(widths, linetype='='))

        for row in rows[1:]:
            # Skip empty rows
            if ''.join(row).strip() == '':
                continue
            lines.extend(self.wrap_row(widths, row))
            lines.append(self.ruler_line(widths, linetype='-'))

        # Append empty line after table
        lines.append('')

        return lines
395376
function get_min_max_width() {

    if ( !is_null($this->_min_max_cache)  )
      return $this->_min_max_cache;

    $style = $this->_frame->get_style();

    $this->_frame->normalise();

    // Add the cells to the cellmap (this will calcluate column widths as
    // frames are added)
    $this->_frame->get_cellmap()->add_frame($this->_frame);

    // Find the min/max width of the table and sort the columns into
    // absolute/percent/auto arrays
    $this->_state = array();
    $this->_state["min_width"] = 0;
    $this->_state["max_width"] = 0;

    $this->_state["percent_used"] = 0;
    $this->_state["absolute_used"] = 0;
    $this->_state["auto_min"] = 0;

    $this->_state["absolute"] = array();
    $this->_state["percent"] = array();
    $this->_state["auto"] = array();

    $columns =& $this->_frame->get_cellmap()->get_columns();
    foreach (array_keys($columns) as $i) {
      $this->_state["min_width"] += $columns[$i]["min-width"];
      $this->_state["max_width"] += $columns[$i]["max-width"];

      if ( $columns[$i]["absolute"] > 0 ) {
        $this->_state["absolute"][] = $i;
        $this->_state["absolute_used"] += $columns[$i]["absolute"];

      } else if ( $columns[$i]["percent"] > 0 ) {
        $this->_state["percent"][] = $i;
        $this->_state["percent_used"] += $columns[$i]["percent"];

      } else {
        $this->_state["auto"][] = $i;
        $this->_state["auto_min"] += $columns[$i]["min-width"];
      }
    }

    // Account for margins & padding
    $dims = array($style->border_left_width,
                  $style->border_right_width,
                  $style->padding_left,
                  $style->padding_right,
                  $style->margin_left,
                  $style->margin_right);

    if ( $style->border_collapse !== "collapse" ) 
      list($dims[]) = $style->border_spacing;

    $delta = $style->length_in_pt($dims, $this->_frame->get_containing_block("w"));

    $this->_state["min_width"] += $delta;
    $this->_state["max_width"] += $delta;

    return $this->_min_max_cache = array(
      $this->_state["min_width"], 
      $this->_state["max_width"],
      "min" => $this->_state["min_width"], 
      "max" => $this->_state["max_width"],
    );
  }
833142
def table(*columns, &_block)
      rows = []
      yield(rows)

      # determine maximum cell widths
      max_cell_widths = rows.reduce(Array.new(columns.length, 0)) do |result, row|
        lengths = row.map { |column| column.to_s.length }
        result.each_with_index { |length, index| result[index] = ([length, lengths[index]].max rescue length) }
      end
      columns.each_with_index { |col, index| col[:actual_width] ||= max_cell_widths[index] }

      # determine actual column width
      column_widths = columns.map do |column|
        if column[:width] == :rest
          nil
        elsif column[:width]
          column[:width]
        elsif column[:min_width]
          [column[:min_width], column[:actual_width]].max
        elsif column[:max_width]
          [column[:max_width], column[:actual_width]].min
        else
          column[:actual_width]
        end
      end

      if column_widths.include?(nil)
        width_left = options[:width] - ((columns.length - 1) * (style[:cell_separator] ? 3 : 1)) - column_widths.compact.reduce(0) { |sum, col| sum + col }
        column_widths[column_widths.index(nil)] = width_left
      end

      line(:green) if @style[:top_line]

      # Print table header
      if table_has_header?(columns)
        column_titles = []
        columns.each_with_index do |column, index|
          width = column_widths[index]
          alignment = (column[:align] == :right ? '' : '-')
          column_titles.push(colorize("%#{alignment}#{width}s" % column[:title].to_s[0...width], :bold))
        end

        puts column_titles.join(style[:cell_separator] ? " #{characters[:vertical_line]} " : ' ')
        line(:green)
      end

      # Print the rows
      rows.each do |row|
        row_values = []
        columns.each_with_index do |column, index|
          width = column_widths[index]
          case column[:type]
          when :ratio
            if width > 4
              if column[:treshold] && column[:treshold] < row[index].to_f
                bar = ''
                bar << characters[:block] * (width.to_f * column[:treshold]).round
                bar << colorize(characters[:block] * (width.to_f * (row[index].to_f - column[:treshold])).round, :red)
                row_values.push(bar)
              else
                # Create a bar by combining block characters
                row_values.push(characters[:block] * (width.to_f * row[index].to_f).round)
              end
            else
              # Too few characters for a ratio bar. Display nothing
              row_values.push('')
            end
          else
            alignment = (columns[index][:align] == :right ? '' : '-')
            cell_value = "%#{alignment}#{width}s" % row[index].to_s[0...width]
            cell_value = colorize(cell_value, :bold, :brown) if columns[index][:highlight]
            row_values.push(cell_value)
          end
        end
        puts row_values.join(style[:cell_separator] ? " #{characters[:vertical_line]} " : ' ')
      end
    end
183522
function set_column_width($j, $width) {
    if ( $this->_columns_locked ) {
      return;
    }
    
    $col =& $this->get_column($j);
    $col["used-width"] = $width;
    $next_col =& $this->get_column($j+1);
    $next_col["x"] = $next_col["x"] + $width;
  }
844603
def get_column_width_raw(column_index = 0)
      validate_workbook
      validate_nonnegative(column_index)

      range = cols.locate_range(column_index)
      range && range.width
    end
237367
public function getWidths(): array
    {
        $columns = $this->getColumns();
        $values  = ['equal', 'variable', 'null'];
        $values  = array_merge($values, range(1, $columns));

        return array_combine($values, $values);
    }
124092
def dimensions
      rows = []
      cols = []
      @win.getmaxyx(rows, cols)
      rows = rows.first
      cols = cols.first
      [rows, cols]
    end
857218
def column_width colindex, width
      return if width < 0
      raise ArgumentError, "wrong width value sent: #{width} " if width.nil? || !width.is_a?(Fixnum) || width < 0
      @cw[colindex] = width # uncommented 2011-12-1 for expand on +
      @pw[colindex] = width # XXXXX
      get_column(colindex).width = width
      @repaint_required = true
      @recalc_required = true
    end
1078588
private static int[] getWidths(String[] headers, String[][] data) {
        final int[] widths = new int[headers.length];
        for (int j = 0; j < headers.length; j++) {
            final String header = headers[j];
            widths[j] = Math.max(widths[j], header != null ? header.length() : 0);
        }
        for (String[] rowValues : data) {
            for (int j = 0; j < rowValues.length; j++) {
                final String value = rowValues[j];
                widths[j] = Math.max(widths[j], value != null ? value.length() : 0);
            }
        }
        return widths;
    }
296388
def rst_table(self, array):
        """"""
        # Determine cell width for each column
        cell_dict = {}
        for i, row in enumerate(array):
            for j, val in enumerate(row):
                if j not in cell_dict:
                    cell_dict[j] = []
                cell_dict[j].append(val)
        for item in cell_dict:
            cell_dict[item] = max([len(x) for x in cell_dict[item]]) + 1  # Contains adapted width for each column

        # Format top line
        num_cols = len(array[0])
        form = '+'
        for col in range(num_cols):
            form += (cell_dict[col] + 1) * '-'
            form += '+'
        form += '\n'

        # Format values
        for i, row in enumerate(array):
            form += '| '
            for j, val in enumerate(row):
                cell_width = cell_dict[j]
                form += str(val) + (cell_width - len(val)) * ' ' + '| '
            form.rstrip()
            form += '\n'

            # Seperation lines
            form += '+'
            if i == 0:
                sign = '='
            else:
                sign = '-'
            for col in range(num_cols):
                form += (cell_dict[col] + 1) * sign
                form += '+'
            form += '\n'
        return form
870580
def _guess_col_widths  #:nodoc:
      return if @second_time
      @second_time = true if @list.size > 0
      @list.each_with_index { |r, i| 
        break if i > 10
        next if r == :separator
        r.each_with_index { |c, j|
          x = c.to_s.length
          if @cw[j].nil?
            @cw[j] = x
          else
            @cw[j] = x if x > @cw[j]
          end
        }
      }
      #sum = @cw.values.inject(0) { |mem, var| mem + var  }
      #$log.debug " SUM is #{sum} "
      total = 0
      @cw.each_pair { |name, val| total += val }
      @preferred_width = total + (@cw.size() *2)
      @preferred_width += 4 if @numbering # FIXME this 4 is rough
    end
1364683
private function calculateColumnWidths(array $rows) {
        $widths = [];

        foreach ($rows as $row) {
            if ($row['type'] !== '@row') {
                continue;
            }

            foreach ($row['cols'] as $colIndex => $col) {
                $currentWidth = array_get($widths, $colIndex, 0);
                $col = $this->output->format($col, OutputFormat::PLAIN);
                $width = strlen($col);

                if ($width > $currentWidth) {
                    $widths[$colIndex] = $width;
                }
            }
        }

        return $widths;
    }
585821
function getWidths(tableGrid, isPercentageBased, table) {

        var cols = getColumnBlocks(tableGrid);

        var backups = Tools.map(cols, function (col) {
          return getInnerEdge(col.colIndex, col.element).x;
        });

        var widths = [];

        for (var i = 0; i < cols.length; i++) {
          var span = cols[i].element.hasAttribute('colspan') ? parseInt(cols[i].element.getAttribute('colspan'), 10) : 1;
          // Deduce if the column has colspan of more than 1
          var width = span > 1 ? deduceSize(backups, i) : getWidth(cols[i].element, isPercentageBased, table);
          // If everything's failed and we still don't have a width
          width = width ? width : RESIZE_MINIMUM_WIDTH;
          widths.push(width);
        }

        return widths;
      }
277658
def format_table(table, column_names=None, column_specs=None, max_col_width=32, auto_col_width=False):
    
    orig_col_args = dict(column_names=column_names, column_specs=column_specs)
    if len(table) > 0:
        col_widths = [0] * len(table[0])
    elif column_specs is not None:
        col_widths = [0] * (len(column_specs) + 1)
    elif column_names is not None:
        col_widths = [0] * len(column_names)
    my_col_names, id_column = [], None
    if column_specs is not None:
        column_names = ["Row"]
        column_names.extend([col["name"] for col in column_specs])
        column_specs = [{"name": "Row", "type": "float"}] + column_specs
    if column_names is not None:
        for i in range(len(column_names)):
            if column_names[i].lower() == "id":
                id_column = i
            my_col = ansi_truncate(str(column_names[i]), max_col_width if i not in {0, id_column} else 99)
            my_col_names.append(my_col)
            col_widths[i] = max(col_widths[i], len(strip_ansi_codes(my_col)))
    trunc_table = []
    for row in table:
        my_row = []
        for i in range(len(row)):
            my_item = ansi_truncate(str(row[i]), max_col_width if i not in {0, id_column} else 99)
            my_row.append(my_item)
            col_widths[i] = max(col_widths[i], len(strip_ansi_codes(my_item)))
        trunc_table.append(my_row)

    type_colormap = {"boolean": BLUE(),
                     "integer": YELLOW(),
                     "float": WHITE(),
                     "string": GREEN()}
    for i in "uint8", "int16", "uint16", "int32", "uint32", "int64":
        type_colormap[i] = type_colormap["integer"]
    type_colormap["double"] = type_colormap["float"]

    def col_head(i):
        if column_specs is not None:
            return BOLD() + type_colormap[column_specs[i]["type"]] + column_names[i] + ENDC()
        else:
            return BOLD() + WHITE() + column_names[i] + ENDC()

    formatted_table = [border("┌") + border("┬").join(border("─") * i for i in col_widths) + border("┐")]
    if len(my_col_names) > 0:
        padded_column_names = [col_head(i) + " " * (col_widths[i] - len(my_col_names[i]))
                               for i in range(len(my_col_names))]
        formatted_table.append(border("│") + border("│").join(padded_column_names) + border("│"))
        formatted_table.append(border("├") + border("┼").join(border("─") * i for i in col_widths) + border("┤"))

    for row in trunc_table:
        padded_row = [row[i] + " " * (col_widths[i] - len(strip_ansi_codes(row[i]))) for i in range(len(row))]
        formatted_table.append(border("│") + border("│").join(padded_row) + border("│"))
    formatted_table.append(border("└") + border("┴").join(border("─") * i for i in col_widths) + border("┘"))

    if auto_col_width:
        if not sys.stdout.isatty():
            raise AegeaException("Cannot auto-format table, output is not a terminal")
        table_width = len(strip_ansi_codes(formatted_table[0]))
        tty_cols, tty_rows = get_terminal_size()
        if table_width > max(tty_cols, 80):
            return format_table(table, max_col_width=max_col_width - 1, auto_col_width=True, **orig_col_args)
    return "\n".join(formatted_table)
764567
def max_column_widths(columns, header, opts = {})
      row_column_widths = columns.map do |c| 
        c.reduce(0) { |m, v| [m, v.nil? ? 0 : v.length].max }
      end

      header_column_widths = header.map { |h| h.length }

      row_column_widths = header_column_widths if row_column_widths.empty?

      widths = row_column_widths.zip(header_column_widths).map do |column|
        column.reduce(0) { |m, v| [m, v].max }
      end

      widths.empty? ? [] : scale_widths(widths, opts)
    end