Calc
Calc przedstawia program tabelkowy. Ten jest częścią składową pakietu
OpenOffice oraz
LibreOffice i jest alternatywą programu
Microsoft Excel. Służy do tworzenia nie tylko tabelek ale również kompleksowych zestawów powiązanych danych z wzorcami oraz funkcjami. Tabela jest zapisywana w nowym międzynarodowym standardzie dla dokumentów. Jest on oparty na XML i można go odczytać również wtedy, kiedy użytkownik nie posiada
OpenOffice lub
LibreOffice. Wyjściowym formatem dla tabeli
Calc jest plik
*.ods.
Praca z bazami danych typu Calc (Libre Office)
- Aktualnie brak standardowego podłączenia do plików typu
*.ods poprzez
ADO Provider. To eliminuje możliwość zastosowania obiektu
PmaAdo lub
PmaDatabase.
- Do takich plików można z aplikacji PROMOTIC przystępować skryptem poprzez interfejs API Libre Office, Open Office.
Przykład1:
Wytworzenie nowego pustego pliku, ustawienie referencji na pierwszy arkusz oraz wytworzenie opisu w pierwszym wierszu tabeli. Zapis wartości do drugiego wierszu tabeli oraz zapis pliku na dysk.
JavaScriptWybierz oraz skopiuj do schowka
function onClose()
{
oDoc.Close(false);
}
var oSM, oCR, oDesk, oDoc, oSh, oSheet, oCell, s, sPath, sFilePath, bDone;
var jArr = Pm.CreatePmArray().Create(1);
var args = jArr.SaveToVbArray();
var arg = jArr.SaveToVbArray();
sPath = Pm.DiscGetPath("data:");
s = Pm.StringReplace(sPath, "\\", "/");
sFilePath = s + "test2.ods";
// The service manager is always the starting point
// If there is no office running then an office is started up
oSM = Pm.AxGetObject("new", "com.sun.star.ServiceManager");
// Create the CoreReflection service that is later used to create structs
oCR = oSM.createInstance("com.sun.star.reflection.CoreReflection");
// Create the Desktop
oDesk = oSM.createInstance("com.sun.star.frame.Desktop");
// Open a new empty Calc document
oDoc = oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, args);
// Create a sheet object
oSh = oDoc.getSheets();
oSheet = oSh.GetByIndex(0);
oCell = oSheet.getCellByPosition(0, 0);
oCell.String = "A col";
oCell.CellBackColor = 6710932;
oCell = oSheet.getCellByPosition(1, 0);
oCell.String = "B col";
oCell.CellBackColor = 6710932;
oCell = oSheet.getCellByPosition(2, 0);
oCell.String = "C col";
oCell.CellBackColor = 6710932;
oSheet.getCellByPosition(0, 1).Value = 123;
oSheet.getCellByPosition(1, 1).Value = 222;
oSheet.getCellByPosition(2, 1).Value = 333;
bDone = oDoc.storeAsURL("file:///" + sFilePath, arg);
pMe.Root.AddEventTimer(2000, 1, onClose);
Przykład2:
Otwarcie istniejącego pliku, ustawienie referencji na pierwszy arkusz tabeli. Zapis wartości do trzeciego wiersza tabeli oraz zapis pliku na dysk.
JavaScriptWybierz oraz skopiuj do schowka
function onClose()
{
oDoc.Close(false);
}
var oSM, oCR, oDesk, oDoc, oSh, oSheet, oCell, s, sPath, sFilePath, bDone;
var jArr = Pm.CreatePmArray().Create(1);
var args = jArr.SaveToVbArray();
var arg = jArr.SaveToVbArray();
sPath = Pm.EvalMacro("$path.data:");
s = Pm.StringReplace(sPath, "\\", "/");
sFilePath = s + "test2.ods";
// The service manager is always the starting point
// If there is no office running then an office is started up
oSM = Pm.AxGetObject("new", "com.sun.star.ServiceManager");
// Create the CoreReflection service that is later used to create structs
oCR = oSM.createInstance("com.sun.star.reflection.CoreReflection");
// Create the Desktop
oDesk = oSM.createInstance("com.sun.star.frame.Desktop");
// Open Calc document
oDoc = oDesk.loadComponentFromURL("file:///" + sFilePath, "_blank", 0, args);
// Create a sheet object
oSh = oDoc.getSheets();
oSheet = oSh.GetByIndex(0);
oSheet.getCellByPosition(0, 2).Value = 375;
oSheet.getCellByPosition(1, 2).Value = Pm.Round(Pm.Random(0, 100), 0.1);
oSheet.getCellByPosition(2, 2).Value = Pm.Round(Pm.Random(0, 100), 0.1);
bDone = oDoc.storeAsURL("file:///" + sFilePath, arg);
pMe.Root.AddEventTimer(2000, 1, onClose);