Calico Spreadsheet

From IPRE Wiki
Jump to: navigation, search

In Calico, you can open up a Comma-Separated-Value (CSV) file and manually enter and edit items in a two-dimensional grid, much like any spreadsheet program.

However, you can also programmatically edit/add data from any Calico program.


1. Open up an existing Spreadsheet, or make a new one, say, "Ages.csv"

calico.Open("Ages.csv")

2. You can then (in Python):

doc = calico.GetDocument("Ages.csv")

which will give you a reference to the Ages.csv document.

3. Then you can read/write to it:

Using the ["A"][1] based system (x, y of upper left hand corner)

python>>> doc["A"][1]
'Name'
Ok
python>>> print(doc["A"][2])
Sally
Ok
python>>> doc["A"][2] = "Billy"
Ok
python>>> print(doc["A"][2])
Billy

and you can see the data change live.

You can also use a [0][0] (x, y of upper left hand corner) based indexing:

python>>> doc[0][0] = "XXX"
Ok

NOTE: it is currently limited to 26 cols x 100 rows. Also everything you get out of the spreadsheet is a string, no matter what you put in.

Here is a program you can run and watch the data go into the spreadsheet dynamically:

import Myro
doc = calico.GetDocument("Ages.csv")
for col in range(26):
    for row in range(100):
        doc[col][row] = Myro.randomNumber()
        Myro.wait(.01)

NOTE: if you run it from the shell, and want to cancel it, reselect the shell, then press the Stop button.

Calico2-Spreadsheet.jpg

calico.Open("spreadsheet.csv")
document = calico.GetDocument("spreadsheet.csv")
row = 0; col = 0 ## row is zero-based because row is int
document[col][row] = 23
print(document['A'][1]) ## row is one-based because row is string