2003-02-06 15:28:55 +00:00
|
|
|
import com.sun.star.uno.UnoRuntime;
|
|
|
|
import com.sun.star.uno.AnyConverter;
|
|
|
|
import com.sun.star.uno.Type;
|
|
|
|
import com.sun.star.lang.XComponent;
|
|
|
|
import com.sun.star.container.XIndexAccess;
|
|
|
|
import com.sun.star.sheet.XSpreadsheetDocument;
|
|
|
|
import com.sun.star.sheet.XSpreadsheet;
|
2004-10-22 12:50:00 +00:00
|
|
|
import com.sun.star.script.provider.XScriptContext;
|
2003-02-06 15:28:55 +00:00
|
|
|
|
|
|
|
addEntry(date, total, free) {
|
|
|
|
|
2004-10-22 12:50:00 +00:00
|
|
|
// The XSCRIPTCONTEXT variable is of type XScriptContext and is available to
|
2003-02-06 15:28:55 +00:00
|
|
|
// all BeanShell scripts executed by the Script Framework
|
2004-10-22 12:50:00 +00:00
|
|
|
comp = XSCRIPTCONTEXT.getDocument();
|
2003-02-06 15:28:55 +00:00
|
|
|
|
2004-10-22 12:50:00 +00:00
|
|
|
// get the XSpreadsheetDocument interface which allows us to work on the
|
|
|
|
// document
|
2003-02-06 15:28:55 +00:00
|
|
|
doc = (XSpreadsheetDocument)
|
|
|
|
UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
|
|
|
|
|
2004-10-22 12:50:00 +00:00
|
|
|
// get the XIndexAccess interface from the document, so that we can
|
|
|
|
// get the first sheet
|
2003-02-06 15:28:55 +00:00
|
|
|
index = (XIndexAccess)
|
|
|
|
UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
|
|
|
|
|
2004-10-22 12:50:00 +00:00
|
|
|
// get the XSpreadsheet interface corresponding to the first (zero-th)
|
|
|
|
// sheet in the document
|
2003-02-06 15:28:55 +00:00
|
|
|
sheet = (XSpreadsheet) AnyConverter.toObject(
|
|
|
|
new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
|
|
|
|
|
2004-10-22 12:50:00 +00:00
|
|
|
// set the value in the cells
|
2003-02-06 15:28:55 +00:00
|
|
|
sheet.getCellByPosition(0, 1).setValue(total - free);
|
|
|
|
sheet.getCellByPosition(1, 1).setValue(free);
|
|
|
|
sheet.getCellByPosition(2, 1).setValue(total);
|
|
|
|
sheet.getCellByPosition(0, 2).setFormula(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
runtime = Runtime.getRuntime();
|
|
|
|
generator = new Random();
|
|
|
|
date = new Date();
|
|
|
|
|
2004-10-22 12:50:00 +00:00
|
|
|
// allocate a random number of bytes so that the data changes
|
2003-02-06 15:28:55 +00:00
|
|
|
len = (int)(generator.nextFloat() * runtime.freeMemory() / 5);
|
|
|
|
bytes = new byte[len];
|
2004-10-22 12:50:00 +00:00
|
|
|
//update the entry in the spreadsheet
|
2003-02-06 15:28:55 +00:00
|
|
|
addEntry(date.toString(), runtime.totalMemory(), runtime.freeMemory());
|
2003-03-07 13:13:57 +00:00
|
|
|
|
|
|
|
return 0;
|