Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Nano-Sheets: A Small But Mighty Spreadsheet Engine in REBOL  : Page 2

Even in today's big-computing environment, not everything useful has to be big. This article shows you how to build a tiny and basic—but powerful—GUI spreadsheet engine in REBOL, using fewer than 1500 bytes of code.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Nano-Sheets—the Complete Code
Pinch yourself. Here it is—a fully functional, cross-platform GUI spreadsheet in one page of code.

REBOL [Title: "Nano-Sheets"] csize: 100x20 size: 8x16 col-lbl: func [col] [form to char! 64 + col] cell-name: func [x y] [join col-lbl x y] mk-var: func [x y] [to lit-word! cell-name x y] sheet: copy [ space 1x1 across style cell field csize edge none with [formula: none] [enter face compute face/para/scroll: 0x0] style label text csize white black bold center ] repeat y 1 + size/y [ repend sheet ['label (csize / 2x1) either 1 = y [""] [form y - 1]] repeat x size/x [ append sheet compose/deep either 1 = y [ [label (col-lbl x)] ][ [cell with [var: (mk-var x y - 1)]] ] ] append sheet 'return ] enter: func [face /local data] [ if empty? face/text [exit] set face/var face/text data: either #"=" = face/text/1 [ next face/text ][ face/text ] if error? try [data: load data] [exit] if find [integer! decimal! money! time! date! tuple! pair!] type?/word :data [ set face/var data exit ] if face/text/1 = #"=" [face/formula: :data] ] compute: does [ unfocus foreach cell cells [ if cell/formula [ if error? cell/text: try [do cell/formula] [cell/text: "ERROR!"] set cell/var cell/text show cell ] ] ] lay: layout sheet cells: copy [] foreach face lay/pane [ if 'cell = face/style [ append cells face] ] focus first cells view lay

The preceding code is the complete Nano-Sheets engine, in fewer than 1,500 bytes. If you ".rap" Nano-Sheets, it shrinks even further—down to 1,051 bytes. The ".rap" process compresses and protects code for professional projects.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date