1*cdf0e10cSrcweir// When this script is run on an existing, saved, spreadsheet, 2*cdf0e10cSrcweir// eg. /home/testuser/myspreadsheet.sxc, the script will export 3*cdf0e10cSrcweir// each sheet to a separate html file, 4*cdf0e10cSrcweir// eg. /home/testuser/myspreadsheet_sheet1.html, 5*cdf0e10cSrcweir// /home/testuser/myspreadsheet_sheet2.html etc 6*cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.UnoRuntime); 7*cdf0e10cSrcweirimportClass(Packages.com.sun.star.sheet.XSpreadsheetDocument); 8*cdf0e10cSrcweirimportClass(Packages.com.sun.star.container.XIndexAccess); 9*cdf0e10cSrcweirimportClass(Packages.com.sun.star.beans.XPropertySet); 10*cdf0e10cSrcweirimportClass(Packages.com.sun.star.beans.PropertyValue); 11*cdf0e10cSrcweirimportClass(Packages.com.sun.star.util.XModifiable); 12*cdf0e10cSrcweirimportClass(Packages.com.sun.star.frame.XStorable); 13*cdf0e10cSrcweirimportClass(Packages.com.sun.star.frame.XModel); 14*cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.AnyConverter); 15*cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.Type); 16*cdf0e10cSrcweir 17*cdf0e10cSrcweirimportClass(java.lang.System); 18*cdf0e10cSrcweir 19*cdf0e10cSrcweir//get the document object from the scripting context 20*cdf0e10cSrcweiroDoc = XSCRIPTCONTEXT.getDocument(); 21*cdf0e10cSrcweir//get the XSpreadsheetDocument interface from the document 22*cdf0e10cSrcweirxSDoc = UnoRuntime.queryInterface(XSpreadsheetDocument, oDoc); 23*cdf0e10cSrcweir//get the XModel interface from the document 24*cdf0e10cSrcweirxModel = UnoRuntime.queryInterface(XModel,oDoc); 25*cdf0e10cSrcweir//get the XIndexAccess interface used to access each sheet 26*cdf0e10cSrcweirxSheetsIndexAccess = UnoRuntime.queryInterface(XIndexAccess, xSDoc.getSheets()); 27*cdf0e10cSrcweir//get the XStorable interface used to save the document 28*cdf0e10cSrcweirxStorable = UnoRuntime.queryInterface(XStorable,xSDoc); 29*cdf0e10cSrcweir//get the XModifiable interface used to indicate if the document has been 30*cdf0e10cSrcweir//changed 31*cdf0e10cSrcweirxModifiable = UnoRuntime.queryInterface(XModifiable,xSDoc); 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir//set up an array of PropertyValue objects used to save each sheet in the 34*cdf0e10cSrcweir//document 35*cdf0e10cSrcweirstoreProps = new Array;//PropertyValue[1]; 36*cdf0e10cSrcweirstoreProps[0] = new PropertyValue(); 37*cdf0e10cSrcweirstoreProps[0].Name = "FilterName"; 38*cdf0e10cSrcweirstoreProps[0].Value = "HTML (StarCalc)"; 39*cdf0e10cSrcweirstoreUrl = xModel.getURL(); 40*cdf0e10cSrcweirstoreUrl = storeUrl.substring(0,storeUrl.lastIndexOf('.')); 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir//set only one sheet visible, and store to HTML doc 43*cdf0e10cSrcweirfor(var i=0;i<xSheetsIndexAccess.getCount();i++) 44*cdf0e10cSrcweir{ 45*cdf0e10cSrcweir setAllButOneHidden(xSheetsIndexAccess,i); 46*cdf0e10cSrcweir xModifiable.setModified(false); 47*cdf0e10cSrcweir xStorable.storeToURL(storeUrl+"_sheet"+(i+1)+".html", storeProps); 48*cdf0e10cSrcweir} 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir// now set all visible again 51*cdf0e10cSrcweirfor(var i=0;i<xSheetsIndexAccess.getCount();i++) 52*cdf0e10cSrcweir{ 53*cdf0e10cSrcweir xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i)); 54*cdf0e10cSrcweir xPropSet.setPropertyValue("IsVisible", true); 55*cdf0e10cSrcweir} 56*cdf0e10cSrcweir 57*cdf0e10cSrcweirfunction setAllButOneHidden(xSheetsIndexAccess,vis) { 58*cdf0e10cSrcweir //System.err.println("count="+xSheetsIndexAccess.getCount()); 59*cdf0e10cSrcweir //get an XPropertySet interface for the vis-th sheet 60*cdf0e10cSrcweir xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(vis)); 61*cdf0e10cSrcweir //set the vis-th sheet to be visible 62*cdf0e10cSrcweir xPropSet.setPropertyValue("IsVisible", true); 63*cdf0e10cSrcweir // set all other sheets to be invisible 64*cdf0e10cSrcweir for(var i=0;i<xSheetsIndexAccess.getCount();i++) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i)); 67*cdf0e10cSrcweir if(i!=vis) { 68*cdf0e10cSrcweir xPropSet.setPropertyValue("IsVisible", false); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir} 72