| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
// When this script is run on an existing, saved, spreadsheet, |
| 19 |
// eg. /home/testuser/myspreadsheet.sxc, the script will export |
| 20 |
// each sheet to a separate html file, |
| 21 |
// eg. /home/testuser/myspreadsheet_sheet1.html, |
| 22 |
// /home/testuser/myspreadsheet_sheet2.html etc |
| 23 |
importClass(Packages.com.sun.star.uno.UnoRuntime); |
| 24 |
importClass(Packages.com.sun.star.sheet.XSpreadsheetDocument); |
| 25 |
importClass(Packages.com.sun.star.container.XIndexAccess); |
| 26 |
importClass(Packages.com.sun.star.beans.XPropertySet); |
| 27 |
importClass(Packages.com.sun.star.beans.PropertyValue); |
| 28 |
importClass(Packages.com.sun.star.util.XModifiable); |
| 29 |
importClass(Packages.com.sun.star.frame.XStorable); |
| 30 |
importClass(Packages.com.sun.star.frame.XModel); |
| 31 |
importClass(Packages.com.sun.star.uno.AnyConverter); |
| 32 |
importClass(Packages.com.sun.star.uno.Type); |
| 33 |
|
| 34 |
importClass(java.lang.System); |
| 35 |
|
| 36 |
//get the document object from the scripting context |
| 37 |
oDoc = XSCRIPTCONTEXT.getDocument(); |
| 38 |
//get the XSpreadsheetDocument interface from the document |
| 39 |
xSDoc = UnoRuntime.queryInterface(XSpreadsheetDocument, oDoc); |
| 40 |
//get the XModel interface from the document |
| 41 |
xModel = UnoRuntime.queryInterface(XModel,oDoc); |
| 42 |
//get the XIndexAccess interface used to access each sheet |
| 43 |
xSheetsIndexAccess = UnoRuntime.queryInterface(XIndexAccess, xSDoc.getSheets()); |
| 44 |
//get the XStorable interface used to save the document |
| 45 |
xStorable = UnoRuntime.queryInterface(XStorable,xSDoc); |
| 46 |
//get the XModifiable interface used to indicate if the document has been |
| 47 |
//changed |
| 48 |
xModifiable = UnoRuntime.queryInterface(XModifiable,xSDoc); |
| 49 |
|
| 50 |
//set up an array of PropertyValue objects used to save each sheet in the |
| 51 |
//document |
| 52 |
storeProps = new Array;//PropertyValue[1]; |
| 53 |
storeProps[0] = new PropertyValue(); |
| 54 |
storeProps[0].Name = "FilterName"; |
| 55 |
storeProps[0].Value = "HTML (StarCalc)"; |
| 56 |
storeUrl = xModel.getURL(); |
| 57 |
storeUrl = storeUrl.substring(0,storeUrl.lastIndexOf('.')); |
| 58 |
|
| 59 |
//set only one sheet visible, and store to HTML doc |
| 60 |
for(var i=0;i<xSheetsIndexAccess.getCount();i++) |
| 61 |
{ |
| 62 |
setAllButOneHidden(xSheetsIndexAccess,i); |
| 63 |
xModifiable.setModified(false); |
| 64 |
xStorable.storeToURL(storeUrl+"_sheet"+(i+1)+".html", storeProps); |
| 65 |
} |
| 66 |
|
| 67 |
// now set all visible again |
| 68 |
for(var i=0;i<xSheetsIndexAccess.getCount();i++) |
| 69 |
{ |
| 70 |
xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i)); |
| 71 |
xPropSet.setPropertyValue("IsVisible", true); |
| 72 |
} |
| 73 |
|
| 74 |
function setAllButOneHidden(xSheetsIndexAccess,vis) { |
| 75 |
//System.err.println("count="+xSheetsIndexAccess.getCount()); |
| 76 |
//get an XPropertySet interface for the vis-th sheet |
| 77 |
xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(vis)); |
| 78 |
//set the vis-th sheet to be visible |
| 79 |
xPropSet.setPropertyValue("IsVisible", true); |
| 80 |
// set all other sheets to be invisible |
| 81 |
for(var i=0;i<xSheetsIndexAccess.getCount();i++) |
| 82 |
{ |
| 83 |
xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i)); |
| 84 |
if(i!=vis) { |
| 85 |
xPropSet.setPropertyValue("IsVisible", false); |
| 86 |
} |
| 87 |
} |
| 88 |
} |