Browse DevX
Sign up for e-mail newsletters from DevX


Nano-Sheets: A Small but Mighty Spreadsheet Engine in REBOL, Part 2 : Page 4

Building on Part 1 of this article, not only can you create a working spreadsheet in just a few bytes using REBOL, but you can extend it to support printing, standard keyboard navigation, macros containing code, and even make it shareable and dynamically updatable—while still using only a few bytes of code.




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

Multi-user Collaboration and Interacting with Other Programs
Adding multi-user collaboration capability to Nano-Sheets is easy in a secure X-Internet environment such as REBOL/IOS. With just a little code, you publish spreadsheets to an IOS server, which then syncs it to all the other clients that have access to the file (folders can be private, for example). IOS also maintains a historical list of published versions, so you can roll back to an earlier one if you want.

Nano-sheets files are small, thanks to their dialect-based format, and sharing published files works well in most cases, but you can reduce the network traffic required for collaboration even further. Rather than publishing an entire file, you can send messages to IOS that contain just part of a spreadsheet—for example, a single cell, or range of cells—in other words, just the changes made to that spreadsheet. IOS syncs those messages and the listening Nano-Sheet—if it had the same file open—can easily read that message and apply the changes to the live spreadsheet. This works because (remember the file format) cells are named; you just send the name of the cells that have changed and their new contents. That gives you interactive spreadsheet collaboration

In the next sections you'll see how to extend Nano-Sheets to publish spreadsheets in REBOL/IOS, and display the data to other users. To do that, you make to create a fileset in IOS and make two distinct changes to Nano-Sheets.

Creating the Fileset
Before extending Nano-Sheets so it can publish spreadsheets and display changed data to other users, a user with administrative rights must create a fileset named "nano-sheets" for the above example.

You can find more detailed information about filesets including both an overview and detailed programming information.

The administrator can create the fileset using the App-Admin tool provided with REBOL/IOS, or programmatically using the following line of code:

send-server new-app compose/deep [nano-sheets [] [] ]

The flexibilities of filesets allow you to automate nearly any workflow process. This example was designed to show a simple, fundamental application of distributed messaging. Note that when the file is "saved" via the X-Internet, the local copy is saved only after the distribution sync is complete. Also note that both "save" and "save-as" use the save-sheet function.

With the fileset created, you can continue with the Nano-Sheet collaboration extensions.

Publishing Spreadsheet Data with Send-server
To publish spreadsheet data collaboratively, you first modify the save-sheet function by adding the REBOL/IOS send-server function when the IOS Serve dialect is present by modifying these original two lines at the end of the save-sheet function:

save file buffer current-file: file

Here's a simple modified version that uses absolute file paths so you can see the structure clearly:

; For collaboration, see if IOS is connected through ; the X-Internet either all [link? connected?] [ send-server add-file reduce [ 'nano-sheets file compress mold/only buffer ] ][ save file buffer ;otherwise, store locally ] current-file: file

Here's a more advanced modified version that uses flexible cross-platform-capable relative file paths:

; For collaboration, see if IOS is connected ; through the X-Internet either all [link? connected?] [ base-dir: any [ ( find/match what-dir link-root ) what-dir] pub-file: second split-path file send-server add-file reduce [ 'nano-sheets base-dir/:pub-file compress mold/only buffer ] ][ save file buffer ;otherwise, store locally ] current-file: file

How does the code above publish a spreadsheet? First, you check to be sure it's using REBOL/IOS with the link? test and then determine whether it's connected to the X-Internet with the connected? test. Next it determines the relative base-dir. pub-file contains the filename only—without the path. These are joined by the base-dir/:pub-file line that determines where the file will be synced. The send-server dialect tells REBOL/IOS to add the file to the nano-sheets fileset, and the file contents will be whatever buffer holds.

Using relative file paths you can install Nano-Sheets anywhere on the REBOL/IOS desktop without needing to modify the Nano-Sheets program.

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