Added new JavaScript example script
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
16
scripting/examples/javascript/ExportSheetsToHTML/parcel-descriptor.xml
Executable file
16
scripting/examples/javascript/ExportSheetsToHTML/parcel-descriptor.xml
Executable file
@@ -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>
|
Reference in New Issue
Block a user