.. index:: single: G7 Reference Manual; X single: G7 Command; xl single: G7 Command; xl open single: G7 Command; xl create single: G7 Command; xl save single: G7 Command; xl write single: G7 Command; xl vecwrite single: G7 Command; xl formula single: G7 Command; xl font single: G7 Command; xl setfont single: G7 Command; xl read single: G7 Command; xl vecread single: G7 Command; xl mkseries single: G7 Command; xl matread single: G7 Command; xl missing single: G7 Command; xl print missing single: G7 Command; xl clear missing single: G7 Command; xl replace single: G7 Command; xl visible single: G7 Command; xl invisible single: G7 Command; xl name single: G7 Command; xl column single: G7 Command; xl row single: G7 Command; xl close single: G7 Command; xl exit single: G7 Command; xl graph single: G7 Command; xl merge single: G7 Command; xl subscript single: G7 Command; xl border single: G7 Command; xl gridlines single: G7 Command; xl printer single: G7 Command; xl cf single: G7 Command; xl setfrequency single: G7 Command; xl freeze single: G7 Command; xl background single: G7 Command; conditional formatting *G7* Commands: X ================ .. _G7RMxl: | **xl** | The *xl* command actually is a family of two or three word commands that enable the reading and writing of Excel worksheets from within *G7*. Actually, *G7* does not do the reading and writing itself, but communicates with the Excel program and provides instructions for Excel to execute. Therefore, Excel already must be installed on your machine before using these *xl* commands. Next, some examples will be provided that show how to read from and write to Excel files. For details on each member of this family of commands, see the corresponding entries in this Reference Manual. Example 1: In this example, the file "XLTEST.XLS" is created in the current directory. The time series are written to the spreadsheet by giving the starting cell, the direction to write the data (down or right), the name of the series, and the range of periods to write. :: fdate 1975 2010 # Create sample data. f Year = 1974 + @cum(t, 1.0, 0.0) f Data = 1975 / (t - 1975) xl create xltest.xls # Start Excel server, create xltest.xls workbook. xl open worksheet 1 # Open worksheet 1. xl write A 1 "Writing text to file:" xl write A 3 "Year" # Record label for the year xl write A 4 down Year 1976 2010 # Record the year xl write B 3 "Data" # Record series name xl write B 4 down Data 1976 2010 # Write series 'Data' xl close # Close the workbook. Example 2: In this example, we re-open the same file, and read one of the series back into *G7* with a different name. :: xl open xltest.xls # Open the workbook. xl open worksheet 1 # Open worksheet 3. xl read A 1 "" # Read the string in position A1; string # will be printed on screen. xl read B 4 right Year2 1976 2010 # Read data into workspace. xl exit # Close workbook, close connection to # Excel server. Example 3: In this example, we must be working with a Vam file, and it must be opened and declared to be the default. The data read from the spreadsheet are stored as vector elements in the Vam file. Writing to the Vam file, instead of to the *G7* workspace bank, is forced by providing a bank leter ('c') corresponding to the open Vam bank in front of the name of the vector. Note that columns may be specified either by the Excel column letters or by the column number. :: xl open C0301e.xls xl open worksheet 1 do{ xl read %1 27 down c.gdpN%2 1990 1990 }(3-4 6-7 9-10)(1-6)m xl exit Example 4: In this final example, we show the use of the "xl matread" command. The command must all be on one line, even though it seems to span two lines in this example. First the blocks of data in the Excel spreadsheet are specified by listing their rows and columns. Next, the name of the matrix is given in which the data should be sotred, along with the matrix rows and columns. Finally, the year is given for which the matrix should be stored. :: xl open C0319e.xls xl open worksheet 1 xl matread c(2-18) r(14-17, 19-20, 22-24,26-29,31-32, 34-35)... c.AM c(1-17) r(1-17) 2000 Related Topics: 123toG, :ref:`p123 ` .. _G7RMxlopen: | **xl open ** | This command opens an Excel file, either for writing or reading. | **xl open worksheet ** | **xl open chart ** | This command opens a worksheet or chart within the Excel file for reading or writing. The number to be used is the order of the worksheets within the file, where the first tab is '1'. The list of charts is handled separately, and the first chart also begins with '1'. Alternatively, the name of the worksheet or chart sheet may be specified. "worksheet" may be abbreviated "ws" and "chart" may be abbreviated "ch". .. _G7RMxlcreate: | **xl create** | **xl create workbook [ []]** | **xl create [before|after] worksheet []** | **xl create [before|after] chart []** | An *xl create* command with no arguments launches the Excel server and opens a new workbook with one worksheet. An *xl create workbook* command may provide the name for a new Excel filename. If no name is provided, then a new workbook will be created with the default name. The option "workbook" may be abbreviated "wb". The default filetype is XLS. Available file types include ===================== ===================== **File Types** --------------------- --------------------- AddIn (.xlam) WorkbookNormal (.xls) CSV (.csv) SYLK (.slk) CSVMac (.csv) Template (.xltx) CSVMSDOS (.csv) TextMac (.txt) CSVWindows (.csv) TextMSDOS (.txt) DBF2 (.dbf) TextPrinter (.txt) DBF3 (.dbf) TextWindows (.txt) DBF4 (.dbf) WK1 (.wk1) DIF (.dif) WK1ALL (.wk1) Excel2 (.xls) WK1FMT (.wk1) Excel2FarEast (.xls) WK3 (.wk3 ) Excel3 (.xls) WK4 (.wk4) Excel4 (.xls) WK3FM3 (.wk3) Excel5 (.xls) WKS (.wks) Excel7 (.xls) WQ1 (.wq1) Excel9795 (.xls) UnicodeText (.txt) Excel4Workbook (.xls) Html (.html) IntlAddIn (.xla) XLS (.xls) IntlMacro (.xlsm) ===================== ===================== If no extension is provided with the filename, then the appropriate extension will be determined according to the file type and will be appended to the file name. An *xl create worksheet* command may provide a name for a new worksheet to be added to the open workbook. The instruction "worksheet" may be replaced with "ws". An *xl create chart* command may provide a name for a new chart sheet to be added to the open workbook. The instruction "chart" may be replaced with "ch". If "before" or "after" is specified, then the new sheet will be inserted to the left or right of the currently-active sheet. See also the :ref:`xl name ` command. .. _G7RMxlbackgroundcolor: | **xl background ** | Set the background color. Available colors are listed in the `xl font ` section. .. _G7RMxlcellborder: | **xl border