Finishing up formatting

Prev Next

Introduction

After all the table style ... () functions have been applied on cells, rows, columns and/or the entire table, one additional step is necessary before saving the tables, namely translating the generic formatting applied to target-specific formatting, i.e. HTML markups for HTML files, and Excel formatting markups for the Excel (XML 2003) file format. The following functions are available:


Procedures and Functions Provided:


Translate applied style to target file format:
    translate style attributes for excel
    translate style attributes for excel xml 2003
    translate style attributes for html

Remove all style attributes from the table:
    table style reset

Note:: For Excel, the function translate style attributes for excel() will be called automatically when saving Excel files in case you have not called it explicitly, which allows you to skip this step done manually.
You can save multiple formatted tables in one file using the table save multiple() function. In this case, the translation functions need to be called for every table to be included as sheets in the file. For Excel files (.xlsx), use table save excel file() where you specify all tables and sheet names in parameter sets and then save the file.

Attention: The formatting is associated to the table names. If you make a copy of the table with a different name, then the new table has no formatting information.

If you want to apply different style and formatting on the same table, then use the function table style reset() and begin again with formatting.

The 'Cities' table in a nice and professional appearance
  table load( t, "Examples\Cities.csv" );

  // Freeze panes and apply an autofilter
  table style table( t, sheet, freeze rows, 1, freeze columns, 2, autofilter, 0 );    

  for all parameters( { 10, 20, 20, 14, 20, 10, 20, 20 }, width[], col[] )
  {
      table style columns( t, col[], sheet, column width, width[] );
  }   
  
  table style rows( t, 0, table, row height, 32, vertical align, center,
      fill color, gray 14, boldface, true, font size, 12, wrap text, true );

  table style columns( t, { City, Country }, body, text color, blue, boldface, true, italic, true );
  table process selected rows( t, [Inhabitants]>=1000000,
      table style cells( t, Inhabitants, row(), single,
      text color, royal purple, fill color, champagne, boldface, true ) );

  border[] = { medium, red };
  table process selected rows( t, ([Famous cultural place]=+'*theater*','*opera*'),
      table style cells( t, { City, Famous cultural place}, row(), matrix,
      text color, mandarin, fill color, lemon, boldface, true,
      left border, border[], right border, border[], top border, border[], bottom border, border[]  ) );

  // Number format is supported in Excel only
  table style columns( t, {Inhabitants,"Alt. (m)"},body,  horizontal align, right, number format, "#,##0" );

  table save( t, "Images/Style_Function_table_style_professionally.xls", EXCEL );
  table save excel file( t, Contents, "Images/Style_Function_table_style_professionally.xlsx"  );

  // How to apply number formats in HTML for browsers

  table process              ( t,                      [Inhabitants] = str([Inhabitants], '#,##0', local) );  
  table process selected rows( t, ['Alt. (m)'] != '',  ['Alt. (m)']  = str(['Alt. (m)'] , '#,##0', local) );
  table style columns( t, {Inhabitants,"Alt. (m)"},body,  type, string );

  table save( t, "Images/Style_Function_table_style_professionally.html", HTML );
  file copy overwrite( "Images/Style_Function_table_style_professionally.html", "Images/Style_Function_table_style_professionally_in_html.xls" );
  echo("Done.");
    Saved table(s) to EXCEL file 'Images/Style_Function_table_style_professionally.xlsx' containing 1 sheets.

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

Test Click on the file name view the result: Style_Function_table_style_professionally.html.
Test Click on the file name open the file with Excel: Style_Function_table_style_professionally.xls (Excel XML 2003 format - confirm the message box query).
Test Click on the file name open the HTML file with Excel: Style_Function_table_style_professionally_in_html.xls (Note: HTML file opened with Excel).
Test Click on the file name open the file with Excel (.xlsx) : Style_Function_table_style_professionally_in_html.xlsx (Excel .xlsx format).