table style auto width

Prev Next

Function Names

table style auto width

Library

Style Library

Description

This function will adjust the width the table columns automatically. If only one function parameter, namely the table name, is provided, then the column widths will be adjusted according to default settings and should be fine in most cases. However, you can add one or more pairs of two parameters which consist of attribute names and attribute values in order to refine the automatic width adjustment. The attributes are summarized in teh table below.

Attribute Name Attribute Value Description
min Numeral: 1..255 Defines the minimum column width. Non-integer values will be rounded up.
Default value: 4
max Numeral: 1..255 Defines the maximum column width. Longer contents may either not be fully visible or do wrap. Non-integer values will be rounded up.
Default value: 255
factor Numeral: 0.1 - 20 Scaling factor applied to estimate the width based on number of characters.
Default value: 1.2
With font size 10, one character typically takes a unit width of 1. See further info underneath the table.
quantile Numeral: 0..1 The quantile rules the percentage of rows ordered from shortest to longest to be included to estimate the width.
Example a: Quantile of 1.0 considers the widest contents checked.
Example b: Quantile of 0.5 considers the median width of all contents checked
Example c: Quantile of 0.9 considers 90% of the shorter contents and ignores the 10% longest contents in order to avoid providing too wide columns for a minority of long data.
Default value: 1
wrap text headers
table
body
none
Appliy text wrapping for headers, table (headers and and body), body (without headers) or none.
Default value: headers.
starting row Numeral: row number Starting row number to assess contents for row width (use 0 to include header row). Negative indexing is supported.
Default value: 0
stopping row Numeral: row number Stoping row number to assess contents for row width (use 0 for header row only). You may consider checking the whole table, but this may require significant amount of time for very large tables. Therefore, a representative check of a smaller number of rows makes sense. Negative indexing is supported.
Default value: 50
starting column Numeral: column number Column width adjustment begins with this column. Negative indexing is supported.
Default value: 0 (first column)
stopping column Numeral: column number Column width adjustment ends with this column. Negative indexing is supported.
Default value: -1 (last column acc. to maximum table width)

Info on the attribute name factor: The width characteristics of the chosen font name, font type (monospace or not), font size and actual contents (e.g. mainly upper case text, or words with more narrow typefaced letters(e.g. l) or wider typefaced letters (e.g. W) contribute to some inaccuracies. A scaling factor of 1.0 may work fine for font size 10, but consider a higher scaling factor to allow for more space for bigger text or generally more spece. You can still apply lower and upper boundaries for the columns.

Call as: procedure

Restrictions

Don't forget to include 'Style Library' at the top of your program

Parameter count

1, 3, 5, 7, etc.

Parameters

No.TypeDescription
1.
input
string Name fo existing table

Opt. 2, 4, ...
input
string Auto width attribute name

See table above for supported attribute names.

Opt. 3, 5, ...
input
string Auto width attribute value

See table above for supported attribute values.

Examples

  table load( t1, "Examples\Cities.csv" );
  table copy table( t1, t2 );

  // Simple example

  table style auto width ( t1 );

  // Example with customized paramters (narrowed intentionally).

  table style auto width ( t2, quantile, 0.9, wrap text, table, starting column, 0, stopping column, -3 );
  table style auto width ( t2, min, 20, max, 30, starting column, -2 );


  // Prepare and save the work

  table save excel file  ( { t1, t2 }, { Simple, Customized }, "Images/Style_Auto_Width.xlsx" );

  echo("Done.");

Output

    Saved table(s) to EXCEL file 'Images/Style_Auto_Width.xlsx' containing 2 sheets.

Done.
Try it yourself: Open LIB_Function_table_style_auto_width.b4p in B4P_Examples.zip. Decompress before use.

Viewing the Results:

Test Click on the file name open the file with Excel (.xlsx) : Style_Auto_Width.xlsx (Excel .xlsx formats).