Ребята, помогите пожалуйста с такой проблемой - при работе с документом Calc документ создаётся, сохраняется, но после выполнения последней строчки кода не завершается работа программы. Помогите пожалуйста побороть. Заранее спасибо. Код программы: Код |
import java.io.File;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet;
import com.sun.star.chart.XDiagram; import com.sun.star.chart.XChartDocument;
import com.sun.star.container.XIndexAccess; import com.sun.star.container.XNameAccess; import com.sun.star.container.XNameContainer;
import com.sun.star.document.XEmbeddedObjectSupplier;
import com.sun.star.frame.XController; import com.sun.star.frame.XDesktop; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XModel; import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.uno.XComponentContext; import com.sun.star.util.XCloseable;
import com.sun.star.sheet.XCellRangeAddressable; import com.sun.star.sheet.XSpreadsheet; import com.sun.star.sheet.XSpreadsheets; import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.table.CellRangeAddress; import com.sun.star.table.XCell; import com.sun.star.table.XCellRange; import com.sun.star.table.XTableChart; import com.sun.star.table.XTableCharts; import com.sun.star.table.XTableChartsSupplier; import ooo.connector.BootstrapSocketConnector;
public class CalcTest { public static void main(String[] args) throws Exception {
XComponentContext xContext = null; try { xContext = BootstrapSocketConnector .bootstrap("/opt/openoffice/program"); System.out.println("Connected"); } catch (Exception e) { }
XSpreadsheetDocument myDoc = null;
System.out.println("Opening");
XMultiComponentFactory xMCF = null; XComponentLoader xCLoader; XSpreadsheetDocument xSpreadSheetDoc = null; XComponent xComp = null;
try { xMCF = xContext.getServiceManager(); Object oDesktop = xMCF.createInstanceWithContext( "com.sun.star.frame.Desktop", xContext); xCLoader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, oDesktop);
String str = "private:factory/scalc";
xComp = xCLoader.loadComponentFromURL(str, "_blank", 0, props); doc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComp);
} catch (Exception e) { System.err.println(" Exception " + e); e.printStackTrace(System.err); }
XSpreadsheet xSheet = null;
try { XSpreadsheets xSheets = myDoc.getSheets(); XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime .queryInterface(XIndexAccess.class, xSheets); xSheet = (XSpreadsheet) UnoRuntime.queryInterface( XSpreadsheet.class, oIndexSheets.getByIndex(0));
} catch (Exception e) { System.out.println("Couldn't get Sheet " + e); e.printStackTrace(System.err); }
XStorable storable = UnoRuntime.queryInterface(XStorable.class, myDoc);
PropertyValue[] properties = new PropertyValue[0];
String delim = System.getProperty("file.separator"); File f = new File("result.xls");
storable.storeToURL("file:///" + f.getAbsolutePath(), properties);
//Пробовал и XComponent, и XModel XComponent xModel = (XComponent) UnoRuntime.queryInterface( XComponent.class, doc); if (xModel != null) { com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable) UnoRuntime .queryInterface(com.sun.star.util.XCloseable.class, xModel); XCloseable xClosable = (XCloseable) UnoRuntime.queryInterface( XCloseable.class, xModel); if (xClosable != null) { System.out.println("close");
try { xClosable.close(true); } catch (com.sun.star.util.CloseVetoException exCloseVeto) { exCloseVeto.printStackTrace(); } } else { try { System.out.println("dispose"); com.sun.star.lang.XComponent xDisposeable = (com.sun.star.lang.XComponent) UnoRuntime .queryInterface(com.sun.star.lang.XComponent.class, xModel); if (xDisposeable == null) System.out.println("NULL"); xDisposeable.dispose(); } catch (Exception exModifyVeto) { exModifyVeto.printStackTrace();
}
}
System.out.println("done"); } }
|
При отладке получаю список переменных в приложении к посту. Это сообщение отредактировал(а) Feldsher - 19.2.2011, 16:10
Присоединённый файл ( Кол-во скачиваний: 6 )
__________.txt 9,37 Kb
|