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