RAS Playground 日本語 GitHub

Workbook tools

Viewing and comparing workbooks

The ras book commands read workbook files without using Excel. They work on Mac, Linux and CI, and also let an AI agent learn what is in a workbook instead of guessing. The command that edits cells (ras book edit) is described in Editing workbooks.

Command Description
ras book dump Prints sheets, used ranges, formulas, names, tables, data validation, conditional formatting and cell values as text, JSON, CSV or Markdown
ras book diff Prints the differences in cells and structure between two workbooks
ras book view Makes an HTML that shows sheets as a grid that looks close to Excel
ras book edit Edits cells as Excel does and writes them to the file (Editing workbooks)

Viewing contents (ras book dump)

ras book dump Book.xlsm                                   # list of sheets, used ranges, formulas, names, tables, data validation, conditional formatting
ras book dump Book.xlsm --sheet Sheet1 --range A1:F20     # cell values and formulas (--formats adds number formats and displayed cell text)
ras book dump Book.xlsm --sheet Sheet1 --format csv       # text (default) / json / csv / markdown
ras book dump Book.xlsm --sheet Sheet1 --styles           # also the formats (font, fill, borders)
Book.xlsx
Sheets:
  1. Sheet1 (code name Sheet1)  used range A1:C5, 13 cells with values (4 of them formulas)
     Formula: C2:C4 =B2*100 (3 formulas of the same shape)
     Formula: C5 =SUM(C2:C4)
Names:
  Total = Sheet1!$C$5

Formulas of the same shape that were copied down or to the right are combined into one line. A large sheet is printed by default up to 200 rows × 50 columns, and the range where it was cut off is shown (--max-rows / --max-cols / --all).

With --styles, the cells whose format (font, fill, borders) differs from the workbook's default are printed after the cell values, cells with the same format together. Only what differs from the default is printed, so even a heavily formatted sheet stays short.

Formats (what differs from the default font 游ゴシック 11):
  A1:C1	bold, fill #FFFF00, border-bottom thin
  C5	color #FF0000
  E2:F4	border thin

json gives them as styles (range and style), markdown as a "Formats" section (spec §14.14).

Comparing (ras book diff)

ras book diff Book.xlsm build/debug/workbooks/Book.xlsm   # differences in cells (values, formulas, number formats) and structure
ras book diff before.xlsx after.xlsx --styles             # also the differences in formats (font, fill, borders)

It also prints the addition, deletion and renaming of sheets, and the insertion and deletion of rows and columns (at several places too; inferred). The exit code is 0 if there is no difference and 1 if there is (spec §14.14).

With --styles, cells whose format changed are printed too (cells that have only a format and no value are compared as well).

Sheet1:
  A1	"Product"	format fill #FFFF00 → #00B0F0
  C5	=SUM(C2:C4) (1000)	format color none → #FF0000

Seeing it (ras book view)

ras book view Book.xlsx --open                                 # makes an HTML grid view (build/view/Book.html) and opens it in the browser
ras book view build/debug/workbooks/Book.xlsx --diff Book.xlsx # highlights changed cells
ras run Report.rebuildReport --view                            # runs, then shows the resulting workbook with the changes

It shows values, formulas, the main formatting (font, fill, borders, alignment, number format), column widths and row heights, merged cells and filters as a grid that looks close to Excel. Gridlines are drawn even in ranges with no data, and the grid continues as you scroll. Shapes, text boxes, WordArt, SmartArt, images (EMF too), charts, embedded objects, and form controls and ActiveX controls (buttons, check boxes and so on) are also drawn over the cells (clicking one shows its name and registered macro). Chart values are read from the current values of the cells they refer to, so values changed by a run also show up in the charts. Selecting a formula cell outlines its referenced cells with colored frames, and "Show formulas" (Ctrl+) displays formulas in the cells. With --diff`, changed cells are marked and you can jump to each from the list of changes. It also draws conditional formatting (rules on cell value, formula, top/bottom, duplicates, text, dates and so on; color scales, data bars and icon sets; as in Excel, color scales, data bars and icons on the same cell are layered) and table styles (header row, banded rows, total row).

As in Excel, it shows frozen panes (frozen rows and columns stay put when you scroll), notes (a red triangle; the text appears on hover), and the drop-down buttons and input messages of data validation lists. Typing a cell address, range or defined name in the Name Box jumps there (Ctrl+G, and F5 too in an editable grid, give "Go To"), and Ctrl+F searches (sheet or workbook; formulas, values or notes; wildcards). Selecting two or more cells shows in the status bar the count of data and the average and sum of the numbers. Clicking a hyperlink cell goes to its target (a place in the workbook, http, https, mailto), and you can zoom at the right of the status bar (or with Ctrl+wheel).

In VS Code, "RAS: Show workbook in sheet preview" (also in the right-click menu of a workbook in the Explorer) shows the same view in a panel. For a sheet file (objects/Sheet1.ras), the button in the editor's title bar or "RAS: Show sheet preview" in the Explorer's right-click menu opens the project's workbook at that sheet (the same as ras book view --sheet Sheet1). In debug runs without Excel, each time execution stops at a breakpoint or step, the sheet at that moment is shown in a panel, with the cells that changed since last time highlighted. When a run or debug run ends, the workbook the program changed (build/debug/workbooks/) is shown, with the cells changed from the original workbook highlighted (setting ras.debug.sheetView). The workbook of a failed test opens the same way from the Test Explorer (Testing).

For editing in the grid (the sheet preview in VS Code and the playground) and ras book edit, see Editing workbooks.

Making a workbook from CSV and JSON (ras book new)

Makes a workbook for the input of tests from CSV and JSON files. The sheet names and code names follow the project's workbook, so useWorkbook takes it as it is.

ras book new test/fixtures/sales.xlsx --sheet Sheet1=data/sales.csv --sheet Master=data/master.json

Making inputs for tests (ras book samples)

Makes samples by editing a real workbook (with mistakes put in, with sheets missing, and so on) from a recipe (JSON), all at once. Excel is not needed.

ras book samples test/fixtures/samples.json           # make them
ras book samples test/fixtures/samples.json --check   # check that the files are as the recipe makes them
{
  "source": "real-report.xlsx",
  "samples": [
    { "output": "wrong.xlsx", "edits": [
      { "sheet": "Ledger", "set": { "S14": "X", "N29": "20200" } },
      { "sheet": "Ledger", "clear": ["A80:AG80"] },
      { "op": "sheet", "action": "remove", "sheet": "Basics" }
    ] }
  ]
}

edits can also hold the edits of ras book edit --op. Formulas are calculated again.