RAS Playground 日本語 GitHub

Workbook tools

Editing workbooks

You can edit workbook files without using Excel. In the VS Code sheet preview ("RAS: Show workbook in sheet preview", "RAS: Show sheet preview") and the playground's "Workbook" tab, you edit with the same operations as Excel; on the command line, you edit with ras book edit. Both use the same mechanism and write back only what changed to the workbook file (How writing works and its limits).

The commands that view, compare and display the contents of a workbook are in Viewing and comparing workbooks.

Operations in the grid

In the VS Code sheet preview ("RAS: Show workbook in sheet preview", "RAS: Show sheet preview"), you can edit a workbook file with the same operations as Excel. The operations are laid out like Excel's ribbon (the Home, Insert, Formulas, Data, View and Developer tabs), and double-clicking a tab collapses the ribbon. As in Excel, volatile functions such as RAND and NOW are recalculated when a cell is edited, and are not recalculated when moving or resizing shapes, changing text or formatting, or switching the display (the editing view shows the values saved in the file. The read-only ras book view recalculates, as when you open the workbook in Excel).

Operation Keys and mouse
Selection Click, Shift+click, drag; row numbers and column headings (whole rows and columns); arrow keys, Tab, Enter, Home, Ctrl+Home, Ctrl+arrow, PageUp / PageDown, Ctrl+A. Ctrl+click and Ctrl+drag add separate ranges (formatting, clearing and Ctrl+Enter entry are applied range by range)
Entering in cells Type (overwrite), F2, double-click, or the formula bar (edit the current content). Enter / Tab to commit, Ctrl+Enter to enter in all cells of the selection, Alt+Enter for a line break in the cell, Esc to cancel
Formula references While entering a formula, click a cell, row number or column heading (drag or Shift+click for a range), or use the arrow keys (with Shift for a range) to insert a reference. F4 toggles $
Function suggestions While entering a formula, a list of functions and names starting with the typed characters (choose with ↑↓ and enter with Tab), and hints for the function's arguments
Today's date, current time Ctrl+; / Ctrl+:
Data validation lists Choose from the button at the right of the cell (Alt+↓). Values not in a "Stop" list cannot be entered
Navigating, finding, replacing Name Box (cell address, range, defined name), F5 / Ctrl+G (Go To), Ctrl+F (find), Ctrl+H (replace. "Replace All" can be undone in one step)
Defining names Formulas > Defined Names: "Name Manager" (Ctrl+F3. The same dialog as Excel: a list of name, value, refers-to, scope and comment; New, Edit (also by double-click) and Delete; changing the refers-to range of the selected name. OK writes everything at once) and "Define Name" (new name: name, scope (workbook / sheet), comment, refers-to (default: the selection)). When a name is renamed, formulas that use it are rewritten with the new name (an edit of name)
Clearing Delete / Backspace (formulas and values. Formatting remains)
Copy, cut, paste Ctrl+C / Ctrl+X / Ctrl+V (formula references shift as in Excel, and formatting is pasted too. Tab-separated text from other applications can also be pasted). Drag the border of the selection to move (Ctrl to copy)
Paste Special The ▾ of Home > Paste, right-click "Paste Values" and "Paste Special…", Ctrl+Alt+V (values, formulas, formats, column widths and so on; operations; skip blanks; transpose)
Fill down / right Home > Fill, Ctrl+D / Ctrl+R
Inserting and deleting rows, columns and cells Home > Insert and Delete, the right-click menu of row numbers, column headings and cells, Ctrl++ / Ctrl+- (with cells selected, a dialog asks which way to shift)
Formatting Home > Font, Alignment and Number (font name (from the system fonts. In the playground, the browser asks for permission to access fonts when you first open the list), size, increase and decrease size, bold, italic, underline, borders, fill color, font color, alignment, wrap text, number format, currency, percent, thousands separator, decimal places) and "Clear", Ctrl+B / Ctrl+I / Ctrl+U / Ctrl+5 (strikethrough). "Format Cells" (Ctrl+1, right-click, the button at the bottom right of the Font, Alignment and Number groups, "More Number Formats…" in the number format list), like the shape format pane, opens in the right pane (the width can be changed by dragging its left edge) and shows the same items as Excel's dialog in icon tabs, writing each changed item immediately: Number (number, currency, date, time, percentage, custom and so on, with a sample. Dates support Japanese eras too. Can also be set on empty cells), Text (Font: font name, style, size, underline, color, normal font; Effects: strikethrough, superscript, subscript; a preview that also reflects the fill; Alignment: horizontal, indent, vertical, wrap, shrink to fit, merge cells, vertical text and angle, text direction), Fill and Border (background color, pattern color and type; for borders, the line style and color, none / outline / inside, and each side and diagonal lines by buttons or by clicking the preview), and Properties (protection (locked, hidden), the conditional formatting rules applied to the selection (click to open Manage Rules), the defined names that refer to the selection (click to select that range)). The order of the tabs (Text → Fill → Properties) and the item names match the shape and control panes. Japanese-era dates can be displayed (ggge, the gannen "元年" in [$-ja-JP-x-gannen], the built-in Japanese-era formats) and entered (R1/5/1, 令和元年5月1日), and in a Japanese-era cell the formula bar also shows R1/5/1
Merging Home > Merge & Center (from the ▾: Merge Across, Merge Cells, Unmerge Cells)
Column width, row height Drag the border between column headings or row numbers (double-click to fit the content). Home > Format and the right-click menu of the headings: enter a value, AutoFit, hide, unhide
Sorting, filtering Home > Sort & Filter; Data > Sort A to Z / Z to A, Sort (by multiple columns), Filter (Ctrl+Shift+L), Clear; from the ▾ on a heading: sort, filter by choosing values, Number Filters and Text Filters (up to two conditions), Top 10
Sheets Right-click a tab (Insert…, Delete, Rename, Move or Copy, Tab Color…), double-click a tab to rename in place, + at the right end to insert (sheet name, code name and tab color in one dialog)
Data validation Data > Data Validation (Settings: Any value, Whole number, Decimal, List, Date, Time, Text length, Custom, with conditions such as between, Ignore blank, In-cell dropdown; Input Message; Error Alert (Stop, Warning, Information); IME mode (Japanese input). Clear All; apply to all cells with the same validation). Entered cells are checked as in Excel, and a value that does not match a rule is handled with "Retry / Cancel" or "Continue?" (conditions written as formulas, custom rules and formula entry are checked when written, and only the Stop style is rejected). From the ▾: "Circle Invalid Data" (red circles) and "Clear Validation Circles"
Freeze panes View > Freeze Panes (above and left of the active cell, top row, first column, unfreeze)
Tables Insert > Table, Ctrl+T / Ctrl+L (choose the range and whether the first row is the header. If there is no header, a row of "Column1"… is inserted)
Hyperlinks Insert > Link, Ctrl+K, right-click "Link" (a web page, file or e-mail, or a cell or name in the workbook. Display text and tip). Right-click "Edit Hyperlink" and "Remove Hyperlink"
Notes Insert > Note, Shift+F2, right-click "New Note", "Edit Note" and "Delete Note" (Ctrl+Enter to commit)
Symbols and special characters Insert > Symbols and Special Characters (inserted at the cursor in a cell being edited, or, if not editing, after the content of the active cell, starting editing)
Shapes, text boxes Choose Insert > Shapes (lines, rectangles, basic shapes, block arrows, stars, callouts) or Text Box, then drag on the sheet to draw (click for the default size. Shift to keep width and height equal. Esc to cancel). For a text box, type the text after drawing
Pictures Insert > Pictures (PNG, JPEG, GIF, BMP. Inserted at the position of the active cell), and pasting an image from the clipboard (such as a screenshot) with Ctrl+V
Moving and deleting shapes, pictures and charts Click to select, drag to move, the surrounding handles to resize (the corners of a picture keep the aspect ratio), the yellow adjustment handle to change the shape's form (corner radius, arrow thickness, callout tip and so on), arrow keys to move by 1 pixel (Ctrl for 10), Delete to delete. For a shape's text: F2, Enter, double-click, or right-click "Edit Text…"
Form controls With Insert > Controls, choose a button, check box, option button, label, group box, list box, combo box, spin button or scroll bar, then drag on the sheet to draw (click for the default size). Form controls and ActiveX controls are created, as in the form designer, in the system UI font (Yu Gothic UI on Japanese Windows 10 or later) at 10pt. As with shapes, select and drag to move, handles to resize, Delete to delete. Right-click "Format Control" opens the right pane (not a dialog; the same form as the form designer's properties) for text, on / off, input range, linked cell, selected item, current value and range, and F2 for text. ActiveX controls can also be drawn with the same "Controls", in 10 kinds including command buttons and text boxes (named CommandButton1 and so on; events are received with @on("CommandButton1.Click") in the sheet's file); they can be moved, resized and deleted, and the right-click "Properties" pane offers Caption, Value, LinkedCell, ListFillRange, Min, Max, SmallChange, LargeChange and so on (inserted ones have been verified in Excel 2021 for display and clicking)
Shape format, rotation, stacking order The "Shape Format" tab that appears while a shape is selected (shape fill, shape outline and weight; Bring Forward, Bring to Front, Send Backward, Send to Back; Selection Pane; Align (Align Left, Align Center, Align Right, Align Top, Align Middle, Align Bottom, Distribute Horizontally, Distribute Vertically, Snap to Grid (also by dragging with Alt held)); Rotate: right / left 90 degrees, Flip Vertical, Flip Horizontal; Size: height and width (cm); View Code). The format also appears in the right pane (tabs: Text, Fill & Line, Effects, Size & Properties, Code. Text has font, alignment and margins; Size & Properties has size, rotation, positioning and print / protection, and control settings; Code has events). You can also rotate by dragging the round handle at the top (Shift for 15° steps) or with Alt+← / Alt+→. The right-click menu also has the stacking order and "Rotate". Ctrl / Shift+click (also in the Selection Pane list) selects several, and you can move (drag, arrow keys), delete, format, rotate, reorder and resize them together
Series (fill handle) Drag the ■ at the bottom right of the selection (numbers, dates and numbered text such as "No. 1" continue the series; formulas are entered with their references shifted). Double-click to fill down to the end of the adjacent column
Undo, redo Home > Undo and Redo, Ctrl+Z / Ctrl+Y (in VS Code, 50 steps per workbook. When Excel or a sync changes the file, the history is cleared)
Shape and control events Right-click a shape or control, "View Code" in the shape format tab, the events in the right pane, or double-click (the default event). Events are written in the sheet's file (objects/<code name>.ras). In VS Code this works only for the project's workbook (VS Code extension)

When you insert or delete rows, columns or cells, as in Excel, formulas on all sheets, defined names, merged cells, conditional formatting, data validation, filters, notes, the positions of shapes and charts, and chart references all follow along, and formulas that depend on the edited cells are recalculated. Operations Excel refuses, such as an insertion that moves only part of a merged cell, show the reason and change nothing.

Operations specific to VS Code (checking events in run mode, the shortcuts the sheet preview receives, how to write shape and control events) are in the VS Code extension.

Editing from the command line (ras book edit)

The same editing can be done from the command line (it can also be used when an AI agent fixes workbook data).

Entering, clearing, inserting and deleting cells

ras book edit Book.xlsm --sheet Sheet1 --set B2=100 --set "C2==B2*2"   # enter in cells (formulas and dates are read the same as when typed in Excel)
ras book edit Book.xlsm --sheet Sheet1 --clear A1:C3                    # clear formulas and values
ras book edit Book.xlsm --sheet Sheet1 --insert 3:4                     # insert rows (B:C is columns, B2:C3 is cells. --shift right shifts to the right)
ras book edit Book.xlsm --sheet Sheet1 --delete B:B                     # delete a column
ras book edit Book.xlsm --set A1=x -o build/edited.xlsm                 # write to another file (the original workbook is unchanged)

--op operations

For --op, write the edit as JSON (one edit, or an array of them; --op can be given more than once. To read from a file, use --ops-file <file>, and - for standard input). The operations you can write in "op" are as follows.

Category Operations
Cells set (enter), values (paste values row by row), clear, insert / delete, copy, move, fill, autofill, pasteSpecial
Formatting format, clearFormats, merge / unmerge, conditional, conditionalRules
Rows and columns size, fit, hide, freeze
Data sort, filter, filterBy, table, validation, validate, name (define a name)
Links and notes link, note
Shapes, pictures, controls shape, picture, object, control, activeX
Sheets sheet (add / copy / remove / rename), tabColor, sheetVisible, moveSheet, protect, standardWidth

Examples:

ras book edit Book.xlsm --op '{"op":"copy","sheet":"Sheet1","from":"A1:B2","to":"D1"}'   # edits specified as JSON (copy / move / fill / values and so on)
ras book edit Book.xlsm --op '{"op":"format","sheet":"Sheet1","range":"A1:D1","set":{"bold":true,"fill":"#DDEEFF","border":"all"}}'   # formatting
ras book edit Book.xlsm --op '{"op":"sort","sheet":"Sheet1","range":"A1","by":"B","desc":true}'    # sort (filter / filterBy / size / hide / merge / autofill are similar)
ras book edit Book.xlsm --op '{"op":"freeze","sheet":"Sheet1","at":"B2"}'    # freeze panes (row 1 and column A. "off":true unfreezes)
ras book edit Book.xlsm --op '{"op":"table","sheet":"Sheet1","range":"A1:D20"}'    # make a table ("header":false inserts a header row, "name" gives the name)
ras book edit Book.xlsm --op '{"op":"link","sheet":"Sheet1","range":"B2","url":"https://example.com"}'   # hyperlink ("to":"Sheet2!A1" for a place in the workbook, "off":true removes it)
ras book edit Book.xlsm --op '{"op":"note","sheet":"Sheet1","at":"B2","text":"Checked"}'   # note ("off":true removes it)
ras book edit Book.xlsm --op '{"op":"conditional","sheet":"Sheet1","range":"D2:D20","type":"cellIs","operator":"greaterThan","values":["1000"],"format":{"color":"#9C0006","fill":"#FFC7CE"}}'   # conditional formatting (also dataBar, colorScale, iconSet, expression and so on. "clear":true clears the rules. conditionalRules reorders, deletes and edits)
ras book edit Book.xlsm --op '{"op":"validation","sheet":"Sheet1","range":"C2:C20","type":"whole","operator":"between","formula1":"1","formula2":"100","error":"Enter a number from 1 to 100"}'   # data validation (also list, date, custom and so on. "formula1":"\"red,blue\"" gives the values of a list, "clear":true clears. Putting {"op":"validate","range":"C2"} after an entry stops the edit on a value that does not match the rule)
ras book edit Book.xlsm --op '{"op":"shape","sheet":"Sheet1","shape":"roundRect","at":"B2","width":120,"height":40,"text":"Total"}'   # shape ("range":"B2:D4" lays it over a range. Also textBox, line, arrow and so on)
ras book edit Book.xlsm --op '{"op":"picture","sheet":"Sheet1","file":"logo.png","at":"F2","width":200}'   # picture (or base64 in "data". If the size is omitted, the picture's own size is used)
ras book edit Book.xlsm --op '{"op":"object","sheet":"Sheet1","name":"Picture 2","at":"H2"}'   # move a shape, picture or chart ("width" and "height" resize, "text" sets the shape's text, "delete":true deletes)
ras book edit Book.xlsm --op '{"op":"object","sheet":"Sheet1","name":"Oval 1","fill":"#FF0000","line":null,"rotation":30,"order":"front"}'   # fill, line ("lineWidth" for the weight), rotation ("flipH" and "flipV" flip), text alignment ("textAnchor": t / ctr / b, "textWrap", "inset": {"left": 0} and so on, in points), effects ("shadow": {"angle": 45, "distance": 3}, "glow": {"color": "#FFC000", "size": 8}, "reflection": {"size": 35}. null for none), properties ("placement": twoCell / oneCell / absolute, "print", "locked", "lockText"), adjustment values ("adjust": {"adj": 25000}), stacking order (front / forward / backward / back)
ras book edit Book.xlsm --op '{"op":"control","sheet":"Sheet1","control":"button","at":"B2","text":"Total","macro":"Module1.run"}'   # form control (checkBox, listBox and so on. "link" for the linked cell, "items" for the list range)
ras book edit Book.xlsm --op '{"op":"activeX","sheet":"Sheet1","control":"commandButton","at":"B4"}'   # ActiveX control (textBox, comboBox and so on. The name is CommandButton1 and so on; it can also be given with "name")
ras book edit Book.xlsm --op '{"op":"object","sheet":"Sheet1","shape":1025,"at":"D2"}'   # move a form control ("delete":true deletes. It can also be specified by name)
ras book edit Book.xlsm --op '{"op":"object","sheet":"Sheet1","name":"Check Box 2","text":"Checked","link":"$C$2","checked":true}'   # text, linked cell and state (also "items", "selected", "value", "min", "max", "step", "page". The linked cell is also filled in. The same for ActiveX controls)
ras book edit Book.xlsm --op '{"op":"object","sheet":"Sheet1","name":"CommandButton1","font":{"name":"Yu Gothic","size":11,"bold":true},"foreColor":"#C00000","backColor":"#FFF2CC"}'   # properties of an ActiveX control ("backStyle": opaque / transparent, "enabled", "wordWrap", "autoSize", also "placement", "print", "locked", "altText". A null color means the default color)
ras book edit Book.xlsm --op '{"op":"object","sheet":"Sheet1","name":"Button 1","font":{"size":12,"bold":true},"foreColor":"#0070C0","textAlign":"center","textVAlign":"center","inset":{"left":3.6}}'   # font, alignment and margins of a form control button ("insetAuto": true for automatic. "lockText", "placement", "print", "locked", "altText" work on all form controls)
ras book edit Book.xlsm --op '{"op":"sort","sheet":"Sheet1","range":"A1","keys":[{"by":"C"},{"by":"D","desc":true}]}'    # sort by multiple columns
ras book edit Book.xlsm --op '{"op":"filterBy","sheet":"Sheet1","column":"D","criteria":[[">=","100"],["<","500"]]}'   # number filter ("top":10 for Top 10)

How writing works and its limits