Object Reference : Object View and Procedure Reference : Table
Save table to disk as an Excel 2007 XLSX, CSV, tab-delimited ASCII text, RTF, HTML, Enhanced Metafile, LaTeX, PDF, or Markdown file.
table_name.save(options) [path\]file_name
Follow the keyword with a name for the file. file_name may include the file type extension, or the file type may be specified using the “t=” option.
If an explicit path is not specified, the file will be stored in the default directory, as set in the File Locations global options.
The base syntax for writing Excel files is:
table_name.save(options) [path\]file_name [table_description]
where the following table_description elements may be employed:
“range = arg”, where arg is top left cell of the destination Excel workbook, following the standard Excel format [worksheet!][topleft_cell[:bottomright_cell]].
If the worksheet name contains spaces, it should be placed in single quotes. If the worksheet name is omitted, the cell range is assumed to refer to the currently active sheet. If only a top left cell is provided, a bottom right cell will be chosen automatically to cover the range of non-empty cells adjacent to the specified top left cell. If only a sheet name is provided, the first set of non-empty cells in the top left corner of the chosen worksheet will be selected automatically. As an alternative to specifying an explicit range, a name which has been defined inside the excel workbook to refer to a range or cell may be used to specify the cells to read.
t=file_type (default=“csv”)
Specifies the file type, where file_type may be one of: “excelxml” (Excel 2007 (xml)),“csv” (CSV - comma-separated), “rtf” (Rich-text format), “txt” (tab-delimited text), “html” (HTML - Hypertext Markup Language), “emf” (Enhanced Metafile), “pdf” (PDF - Portable Document Format), “tex” (LaTeX), or “md” (Markdown).
Files will be saved with the “.xlsx”, “.csv”, “.rtf”, “.txt”, “.htm”, “.emf”, “.pdf”, “.tex”, or “.md” extensions, respectively.
Scale size, where arg is from 5 to 200, representing the percentage of the original table size (only valid for HTML or RTF files).
Range of table cells to be saved. See Table::setfillcolor for the cell_range syntax. If a range is not provided, the entire table will be saved.
Replace all cells that contain NA values with the specified string. “NA” is the default.
f / -f
[Use full precision values/ Do not use full precision] when saving values to the table (only applicable to numeric cells). By default, the values will be saved as they appear in the currently formatted table.
Force the dialog to appear from within a program.
PDF Options
Save in landscape mode (the default is to save in portrait mode).
size=arg (default=“letter”)
Page size: “letter”, “legal”, “a4”, and “custom”.
width=number (default=8.5)
Page width in inches if “size=custom”.
height=number (default=11)
Page height in inches if “size=custom”.
leftmargin=number (default=0.5)
Left margin width in inches.
rightmargin=number (default = 0.5)
Right margin width in inches.
topmargin=number (default=1)
Top margin width in inches.
bottommargin= number (default = 1)
Bottom margin width in inches.
LaTeX Options
texspec / -texspec
[Include / Do not include] the full LaTeX documentation specification in the LaTeX output. The default behavior is taken from the global default settings.
Excel Options
Specify whether to create a new file, overwrite an existing file, or update an existing file. arg may be “create” (create new file only; error on attempt to overwrite) or “update” (update an existing file, only overwriting the area specified by the range= table_description).
If the “mode=” option is not used, EViews will create a new file, unless the file already exists in which case it will overwrite it.
Note that the “mode=update” option is only available for Excel in 1) Excel versions through 2003, if Excel is installed, and 2) Excel 2007 (xml). Note: Excel does not need to be installed for Excel 2007 writing.
Excel 2007 Options
Specify whether to use EViews, pre-existing, or remove cell formatting (colors, font, number formatting when possible, column widths and row heights) for the written range.
arg may be “eviews” (replace current formatting in the file with the same cell formatting in EViews), “preserve” (leave current cell formatting already in the Excel file), or “clear” (remove current formatting and do not replace).
(default = 256)
Specify the maximum the number of characters written for cells containing text. Strings in cells which are longer the max, will be truncated.
The command:
tab1.save mytable
saves TAB1 to a CSV file named “mytable.CSV” in the default directory.
tab1.save(t=csv, n="NaN") mytable
saves TAB1 to a CSV (comma separated value) file named “mytable.csv” and writes all NA values as “NaN”.
tab1.save(r=B2:C10, t=html, s=50) mytable
saves from data from the second row, second column, to the tenth row, third column of TAB1 to a HTML file named “mytable.HTM” at half of the original size.
tab1.save(f, n=".", r=B) mytable
saves the contents of the second column of the table in full precision to a CSV file named “mytable.CSV”, and writes all NA values as “.”.
tab1.save(t=excelxml, cellfmt=eviews, mode=update) mytable range=Country!b5
adds TAB1 to the preexisting “mytable.XLSX” Excel file to the “Country” sheet at cell B5, where the cell colors and fonts in TAB1 will also be copied.
For additional discussion of table commands see “Working with Tables and Spreadsheets”.
See “Table and Text Objects” for a discussion of tables.