summaryrefslogtreecommitdiffstats
path: root/scripting/examples/javascript
diff options
context:
space:
mode:
authorDuncan Foster <dfoster@openoffice.org>2003-06-05 14:24:45 +0000
committerDuncan Foster <dfoster@openoffice.org>2003-06-05 14:24:45 +0000
commitff69c9081d65f820fa7f60b6d877af88c536c511 (patch)
treee799cc06d8f157b8964cc46b138921a5ca59c563 /scripting/examples/javascript
parenttypo removed endif, put back now (diff)
downloadcore-ff69c9081d65f820fa7f60b6d877af88c536c511.tar.gz
core-ff69c9081d65f820fa7f60b6d877af88c536c511.zip
Added new JavaScript example script
Diffstat (limited to 'scripting/examples/javascript')
-rw-r--r--scripting/examples/javascript/ExportSheetsToHTML/exportsheetstohtml.js54
-rwxr-xr-xscripting/examples/javascript/ExportSheetsToHTML/parcel-descriptor.xml16
2 files changed, 70 insertions, 0 deletions
diff --git a/scripting/examples/javascript/ExportSheetsToHTML/exportsheetstohtml.js b/scripting/examples/javascript/ExportSheetsToHTML/exportsheetstohtml.js
new file mode 100644
index 000000000000..854a8a367efb
--- /dev/null
+++ b/scripting/examples/javascript/ExportSheetsToHTML/exportsheetstohtml.js
@@ -0,0 +1,54 @@
+importClass(Packages.com.sun.star.uno.UnoRuntime);
+importClass(Packages.com.sun.star.sheet.XSpreadsheetDocument);
+importClass(Packages.com.sun.star.container.XIndexAccess);
+importClass(Packages.com.sun.star.beans.XPropertySet);
+importClass(Packages.com.sun.star.beans.PropertyValue);
+importClass(Packages.com.sun.star.util.XModifiable);
+importClass(Packages.com.sun.star.frame.XStorable);
+importClass(Packages.com.sun.star.frame.XModel);
+importClass(Packages.com.sun.star.uno.AnyConverter);
+importClass(Packages.com.sun.star.uno.Type);
+
+importClass(java.lang.System);
+
+oDoc = XSCRIPTCONTEXT.getDocument();
+xSDoc = UnoRuntime.queryInterface(XSpreadsheetDocument, oDoc);
+xModel = UnoRuntime.queryInterface(XModel,oDoc);
+xSheetsIndexAccess = UnoRuntime.queryInterface(XIndexAccess, xSDoc.getSheets());
+xStorable = UnoRuntime.queryInterface(XStorable,xSDoc);
+xModifiable = UnoRuntime.queryInterface(XModifiable,xSDoc);
+
+storeProps = new Array;//PropertyValue[1];
+storeProps[0] = new PropertyValue();
+storeProps[0].Name = "FilterName";
+storeProps[0].Value = "HTML (StarCalc)";
+storeUrl = xModel.getURL();
+storeUrl = storeUrl.substring(0,storeUrl.lastIndexOf('.'));
+
+//set only one sheet visible, and store to HTML doc
+for(var i=0;i<xSheetsIndexAccess.getCount();i++)
+{
+ setAllButOneHidden(xSheetsIndexAccess,i);
+ xModifiable.setModified(false);
+ xStorable.storeToURL(storeUrl+"_sheet"+(i+1)+".html", storeProps);
+}
+
+// now set all visible again
+for(var i=0;i<xSheetsIndexAccess.getCount();i++)
+{
+ xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i));
+ xPropSet.setPropertyValue("IsVisible", true);
+}
+
+function setAllButOneHidden(xSheetsIndexAccess,vis) {
+ //System.err.println("count="+xSheetsIndexAccess.getCount());
+ xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(vis));
+ xPropSet.setPropertyValue("IsVisible", true);
+ for(var i=0;i<xSheetsIndexAccess.getCount();i++)
+ {
+ xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i));
+ if(i!=vis) {
+ xPropSet.setPropertyValue("IsVisible", false);
+ }
+ }
+}
diff --git a/scripting/examples/javascript/ExportSheetsToHTML/parcel-descriptor.xml b/scripting/examples/javascript/ExportSheetsToHTML/parcel-descriptor.xml
new file mode 100755
index 000000000000..51aa36446d59
--- /dev/null
+++ b/scripting/examples/javascript/ExportSheetsToHTML/parcel-descriptor.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<parcel language="JavaScript" xmlns:parcel="scripting.dtd">
+
+ <script language="JavaScript">
+ <locale lang="en">
+ <displayname value="ExportSheetsToHTML"/>
+ <description>
+ Saves each sheet in the current Calc document as a separate HTML file in the same directory as the original Calc document.
+ </description>
+ </locale>
+ <functionname value="ExportSheetsToHTML.js"/>
+ <logicalname value="ExportSheetsToHTML.JavaScript"/>
+ </script>
+
+</parcel>