Programmatic Spreadsheet Access
Important: The Spread package has been deprecated.
This worksheet demonstrates some of the features of the Spread package. This package is intended to provide support for accessing Maple spreadsheets programmatically. As you read this worksheet, you should execute the commands in sequence as you come to them.
restart
Accessing the Spread Package
To use the Spread package, you must first issue the following call to the procedure with, which provides interactive access to procedures organized into packages.
withSpread
CopySelection,CreateSpreadsheet,EvaluateCurrentSelection,EvaluateSpreadsheet,GetCellFormula,GetCellValue,GetFormulaeMatrix,GetMaxCols,GetMaxRows,GetSelection,GetValuesMatrix,InsertMatrixIntoSelection,IsStale,SetCellFormula,SetMatrix,SetSelection
The routines exported by the Spread package are now available for interactive use. The procedures available in the package are displayed as the result of the with command.
Creating Spreadsheets
The first task with which you must become acquainted is the programmatic creation of spreadsheets. When a spreadsheet is created, it is given a name. The procedure CreateSpreadsheet is provided for programmatic control of spreadsheet creation. The name of the spreadsheet is returned. You must use this name to refer to the spreadsheet in subsequent calls to Spread package procedures.
ssid:=CreateSpreadsheet⁡:
Now, the variable ssid is assigned the name of the spreadsheet that was created by executing the preceding command.
ssid
Spreadsheet(1)
When no arguments are provided, CreateSpreadsheet returns a system-generated name for the spreadsheet. You can also specify your own name for the spreadsheet by providing that name as an argument to the call to CreateSpreadsheet. You can find the name of a spreadsheet by opening the Properties dialog box that is accessible from the context-sensitive menu for the spreadsheet.
ssid:=CreateSpreadsheet⁡MySpreadSheet:
MySpreadSheet
Selecting Cells
Every spreadsheet has, at all times, a "current selection". This refers to the box-shaped region of cells that are visually distinguished from those that do not belong to the selection. Many of the Spread package procedures operate on and allow you to manipulate the current spreadsheet selection.
SetSelection⁡ssid,1,1,4,2
1,1,1,1
Try changing the selected region before executing the following command. You can re-execute this command after selecting different cells with the mouse.
GetSelection⁡ssid
1,1,4,2
This command will copy the selection from the spreadsheet above to the spreadsheet MySpreadsheet that was created earlier.
CopySelection⁡MySpreadSheet,ssid
Evaluating Cells and Manipulating Cell Data
You can evaluate either an entire spreadsheet, or just the current selection (which you can set using the procedure SetSelection), by using the commands EvaluateSpreadsheet and EvaluateCurrentSelection, respectively.
The command GetCellValue will retrieve the (displayed) value from a specified cell. The formula stored in a given cell can be queried by using the command GetCellFormula. By using SetCellFormula, you can set the formula of a cell (but not the cell value).
N:=3:
for i from 1 to N do for j from 1 to N do SetCellFormulassid,i,j,diffBesselJi,x,x$j end do end do:
SetSelection⁡ssid,1,1,1,2
EvaluateCurrentSelection⁡ssid:
EvaluateSpreadsheet⁡ssid:
for i from 1 to N do for j from 1 to N do SetCellFormulassid,i+N,j,evalGetCellFormulassid,i,j,x=0 end do end do:
GetCellValue⁡ssid,B3
BesselJ⁡1,x−2⁢BesselJ⁡2,xx+3⁢BesselJ⁡3,xx2−3⁢BesselJ⁡2,x−9⁢BesselJ⁡3,xxx
Performing Block Operations with Matrix Data
Sometimes it is convenient to manipulate entire blocks of data within a spreadsheet. Such blocks can be represented in Maple using matrices. Certain commands in the Spread package allow you to manipulate spreadsheet data in a blockwise fashion, using matrices.
The Procedure SetMatrix inserts a matrix of values into a spreadsheet. Blocks of data can be extracted from a spreadsheet by using the commands GetValuesMatrix and GetFormulaeMatrix. You can import matrix data into a spreadsheet selection, with clipping, by using the command InsertMatrixIntoSelection.
m:=LinearAlgebra:-RandomMatrix⁡10,5
m2:=Matrix⁡2,2,a,b,c,d
SetMatrix⁡ssid,m:
EvaluateSpreadsheetssid:
SetSelection⁡ssid,2,3,4,5:
InsertMatrixIntoSelection⁡ssid,m2:
GetValuesMatrix⁡ssid
GetFormulaeMatrix⁡ssid
Return to Index for Example Worksheets
Download Help Document