<< Click to Display Table of Contents >> Excel printing |
![]() ![]() ![]() |
You may use the SHEET statement to "print" directly to an Microsoft Excel worksheet. (For non-Excel users, you may try CLIP instead of SHEET (to copy-paste via the clipboard)).
As mentioned in the section on plotting, the statements PRT, PLOT and SHEET (and CLIP) are close cousins. This means that any expression, with any operator, used in one of the statements, can be used in the same way in one of the other statements. For instance, you may take a PRT statement and just replace PRT with SHEET, and the timeseries will be transferred to Excel instead.
A simple example could be the following:
reset; |
The following Excel worksheet is shown:
As with PRT or PLOT, you can use operators and mathematical expressions. The third argument x1<d> shows absolute time-difference in x1, because of the operator <d>.
Transforming the worksheet into an Excel graph is quite easy. Just click on the A1 cell, and then choose "Insert" and choose the chart type that you prefer (here: line with markers):
Excel graph
The SHEET statement needs Excel installed to work (else use CLIP, mentioned below). Per default, SHEET shows timeseries row-wise (use sheet<cols> to "print" in columns). In this worksheet, a missing value is shown as #I/T (because row 4 shows absolute time-change in x1), So operators like absolute or percentage time-change are easy to use with Excel, and expressions, too. This may in some cases be more convenient than using Excel formulas to do the same.
All in all, the SHEET statement is practical for showing things in Excel, rather than in the Gekko output window (with PRT). There are, however, other ways of interacting with Excel:
•Gekcel. This is an add-in for Excel that makes it possible to issue Gekko statements from within Excel (without starting up the Gekko graphical user interface).
•CLIP. This statement produces a semicolon-separated string that can be pasted to Excel (or other spreadsheets). Compared to SHEET, if using CLIP to paste into Excel, some precision and formatting is lost.
•IMPORT<xlsx> and EXPORT<xlsx>. These statements operate on Excel sheets formatted with variables as rows and dates as columns. Similar to csv import/export, just for .xlsx.
•SHEET<import>. This is a special kind of SHEET statement, where data is imported from Excel. In contrast to IMPORT<xlsx>, SHEET<import> is more flexible and can operate more freely on individual cells. SHEET<import> can also import a Gekko matrix from Excel cells.