Short Description
Toolbox to create and manipulate result tables with plug-ins and protocols, and export as text file or to your favorite spreadsheet software
Institution: Institut Pasteur
Website: https://icy.bioimageanalysis.org/
Documentation
General description
Workbooks is a library that allows users and developers to handle and manipulate results via workbooks (also known as spreadsheets). Workbooks uses the Apache POI library, and is therefore able to read/write common file formats including those used by Open Office’s ‘Calc’ and Microscoft’s ‘Excel’.
Workbooks comes with the following components:
- A Var structure for developers to store algorithm output from plug-ins and protocols
- Two blocks to import and export workbooks in Protocols
- A standalone interface to load and modify existing workbooks (still evolving to add more features!)
- A simple API to create workbooks programmatically in no time
For scripters
Here is a sample script showing you how to create (and show) a workbook (screenshot above) in just a few lines in the Script Editor:
importClass(Packages.plugins.adufour.workbooks.Workbooks) importClass(Packages.plugins.adufour.workbooks.IcySpreadSheet) importClass(Packages.java.awt.Color)
// Create an empty workbook wb = Workbooks.createEmptyWorkbook();
// Get a (possibly new) sheet sheet = Workbooks.getSheet(wb, "Test");
// Set the header row (all at once, easier to write!) sheet.setRow(0, "Col 0", "Col 1", "Some other column"); // etc.
// Assign a few cell values // NB: give any object (unknown types are converted to text) sheet.setValue(0, 0, "Name"); sheet.setValue(1, 0, 3);
// Need to insert a formula? // NB: this is the standard formula syntax. The first (corner) cell is called "A1" sheet.setFormula(1, 1, "A2 * A2");
// How about changing the background color? sheet.setFillColor(1, 0, Color.cyan);
// Finally, show the workbook on screen // with a nice window title and whether the table should be editable Workbooks.show(wb, "Workbook test", false);
For developers
Here is a sample code showing you how to create (and show) a workbook (screenshot above) in just a few lines in a Java plugin:
// Some import statements you might need (in case you hate auto-imports ;)) import org.apache.poi.ss.usermodel.Workbook; // NOTE: this comes from Apache POI import plugins.adufour.workbooks.Workbooks; import plugins.adufour.workbooks.IcySpreadSheet;
/** * A test to make sure the plug-in works as intended. Also useful as a sample code */ public static void test() { // Create an empty workbook Workbook wb = Workbooks.createEmptyWorkbook();
// Get a (possibly new) sheet
IcySpreadSheet sheet = Workbooks.getSheet(wb, “Test”);
// Set the header row (all at once, easier to write!)
sheet.setRow(0, “Col 0”, “Col 1”, “Some other column”); // etc.
// Assign a few cell values
// NB: give any object (unknown types are converted to text)
sheet.setValue(0, 0, “Name”);
sheet.setValue(1, 0, 3);
// Need to insert a formula?
// NB: this is the standard formula syntax. The first (corner) cell is called “A1”
sheet.setFormula(1, 1, “A2 * A2”);
// How about changing the background color?
sheet.setFillColor(1, 0, Color.cyan);
// Finally, show the workbook on screen
// with a nice window title and whether the table should be editable
Workbooks.show(wb, “Workbook test”, false);
}
Copyright note: the ‘Workbooks’ icon is a modified version of the K-spread icon available at http://openiconlibrary.sourceforge.net