Object Reference : Object View and Procedure Reference : Table
  
 
setformat
Set the display format for cells in a table view.
Syntax
table_name.setformat(cell_range) format_arg
where format_arg is a set of arguments used to specify format settings. If necessary, you should enclose the format_arg in double quotes.
The cell_range option is used to describe the cells to be modified. It may take one of the following forms:
 
@all
Apply to all cells in the table.
cell
Cell identifier. You can identify cells using either the column letter and row number (e.g., “A2”), or by using “R” followed by the row number followed by “C” and the column number (e.g., “R1C2”).You can optionally add an ‘if’ condition to the identifier. Without the ‘if’ condition, the formatting will be applied to all the identified cells. If an ‘if’ condition is supplied, the formatting will be applied to all the identified where the ‘if’ condition is true. The ‘if’ condition must be followed by a boolean expression.
row[,] col
Row number, followed by column letter or number (e.g., “2,C”, or “2,3”), separated by “,”. Apply to cell.
row
Row number (e.g., “2”). Apply to all cells in the row.
col
Column letter (e.g., “B”). Apply to all cells in the column.
first_cell[:]last_cell, first_cell[,]last_cell
Top left cell of the selection range (specified in “cell” format), followed by bottom right cell of the selection range (specified in “cell” format), separated by a “:” or “,” (e.g., “A2:C10”, “A2,C10”, or “R2C1:R10C3”, “R2C1,R10C3”). Apply to all cells in the rectangular region defined by the first cell and last cell.
first_cell_row[,] first_cell_col[,] last_cell_row[,] last_cell_col
Top left cell of the selection range (specified in “row[,] col” format), followed by bottom right cell of the selection range (specified in “row[,] col” format), separated by a “,” (e.g., “2,A,10,C” or “2,1,10,3”). Apply to all cells in the rectangular region defined by the first cell and last cell.
To format numeric values, you should use one of the following format specifications:
 
g[.precision]
significant digits
f[.precision]
fixed decimal places
c[.precision]
fixed characters
e[.precision]
scientific/float
p[.precision]
percentage
r[.precision]
fraction
To specify a format that groups digits into thousands using a comma separator, place a “t” after the format character. For example, to obtain a fixed number of decimal places with commas used to separate thousands, use “ft[.precision]”.
To use the period character to separate thousands and commas to denote decimal places, use “..” (two periods) when specifying the precision. For example, to obtain a fixed number of characters with a period used to separate thousands, use “ct[..precision]”.
If you wish to display negative numbers surrounded by parentheses (i.e., display the number -37.2 as “(37.2)”), you should enclose the format string in “()” (e.g., “f(.8)”).
To format numeric values using date and time formats, you may use a subset of the possible date format strings (see “Date Formats”). The possible format arguments, along with an example of the date number 730856.944793113 (January 7, 2002 10:40:30.125 p.m) formatted using the argument are given by:
 
WF
(uses current EViews workfile period display format)
YYYY
“2002”
YYYY-Mon
“2002-Jan”
YYYYMon
“2002 Jan”
YYYY[M]MM
“2002[M]01”
YYYY:MM
“2002:01”
YYYY[Q]Q
“2002[Q]1”
YYYY:Q
“2002:Q
YYYY[S]S
“2002[S]1” (semi-annual)
YYYY:S
“2002:1”
YYYY-MM-DD
“2002-01-07”
YYYY Mon dd
“2002 Jan 7”
YYYY Month dd
“2002 January 7”
YYYY-MM-DD HH:MI
“2002-01-07 22:40”
YYYY-MM-DD HH:MI:SS
“2002-01-07 22:40:30”
YYYY-MM-DD HH:MI:SS.SSS
“2002-01-07 22:40:30.125”
Mon-YYYY
“Jan-2002”
Mon dd YYYY
“Jan 7 2002”
Mon dd, YYYY
“Jan 7, 2002”
Month dd YYYY
“January 7 2002”
Month dd, YYYY
“January 7, 2002”
MM/DD/YYYY
“01/07/2002”
mm/DD/YYYY
“1/07/2002”
mm/DD/YYYY HH:MI
“1/07/2002 22:40”
mm/DD/YYYY HH:MI:SS
“1/07/2002 22:40:30”
mm/DD/YYYY HH:MI:SS.SSS
“1/07/2002 22:40:30.125”
mm/dd/YYYY
“1/7/2002”
mm/dd/YYYY HH:MI
“1/7/2002 22:40”
mm/dd/YYYY HH:MI:SS
“1/7/2002 22:40:30”
mm/dd/YYYY HH:MI:SS.SSS
“1/7/2002 22:40:30.125”
dd/MM/YYYY
“7/01/2002”
dd/mm/YYYY
“7/1/2002”
DD/MM/YYYY
“07/01/2002”
dd Mon YYYY
“7 Jan 2002”
dd Mon, YYYY
“7 Jan, 2002”
dd Month YYYY
“7 January 2002”
dd Month, YYYY
“7 January, 2002”
dd/MM/YYYY HH:MI
“7/01/2002 22:40”
dd/MM/YYYY HH:MI:SS
“7/01/2002 22:40:30”
dd/MM/YYYY HH:MI:SS.SSS
“7/01/2002 22:40:30.125”
dd/mm/YYYY hh:MI
“7/1/2002 22:40”
dd/mm/YYYY hh:MI:SS
“7/1/2002 22:40:30”
dd/mm/YYYY hh:MI:SS.SSS
“7/1/2002 22:40:30.125”
hm:MI am
“10:40 pm“
hm:MI:SS am
“10:40:30 pm”
hm:MI:SS.SSS am
“10:40:30.125 pm”
HH:MI
“22:40”
HH:MI:SS
“22:40:30”
HH:MI:SS.SSS
“22:40:30.125”
hh:MI
“22:40”
hh:MI:SS
“22:40:30”
hh:MI:SS.SSS
“22:40:30.125”
Note that the “hh” formats display 24-hour time without leading zeros. In our examples above, there is no difference between the “HH” and “hh” formats for 10 p.m.
Also note that all of the “YYYY” formats above may be displayed using two-digit year “YY” format.
Examples
To set the format of a cell to fixed 5-digit precision, provide the format specification and a valid cell specification:
tab1.setformat(A2) f.5
You may use any of the date formats given above:
tab1.setformat(A3) YYYYMon
tab1.setformat(B1) "YYYY-MM-DD HH:MI:SS.SSS"
The cell specification may be described in a variety of ways:
tab1.setformat(B2) hh:MI:SS.SSS
tab1.setformat(2,B,10,D) g(.3)
tab1.setformat(R2C2:R4C4) "dd/MM/YY HH:MI:SS.SSS"
You may conditionally set the format for a range of cells. For example, in the command below the cells from b20 to d25 will use format ‘e.5’ if the matching cells from the second range (b20 to d25) are greater than the cells from the third range (f10 to h15). Specifically, the format for cell b20 will be set to 'e.5' if cell b20 is greater than f10:
tab1.setformat(b20:d25 if [b20:d25] > [f10:h15]) e.5
Cross-references
See Table::settextcolor and Table::setfillcolor for details on changing text color, and Table::setlines for drawing lines between and through cells. To set other cell properties, see Table::setheight, Table::setindent, Table::setjust, and Table::setwidth.
For additional discussion of table commands see “Working with Tables and Spreadsheets”.
See also “Table and Text Objects” for a discussion and examples of table formatting in EViews.