using System; using unoidl.com.sun.star.lang; using unoidl.com.sun.star.uno; using unoidl.com.sun.star.frame; using unoidl.com.sun.star.beans; using unoidl.com.sun.star.awt; using unoidl.com.sun.star.sheet; using unoidl.com.sun.star.container; using uno; namespace main { class Program { static void Main(string[] args) { // получаем контекст компонентов офиса XComponentContext xContext = uno.util.Bootstrap.bootstrap(); // получаем сервис-менеджер XMultiComponentFactory xServiceManager = (XMultiComponentFactory)xContext.getServiceManager(); Object desktop = xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); // получаем экземпляр сервиса UNO Desktop // получаем интерфейс XComponentLoader XComponentLoader xComponentLoader = (XComponentLoader)desktop; // создаем новый документ PropertyValue[] loadProps = new PropertyValue[2]; loadProps[0] = new PropertyValue(); loadProps[0].Name = "FilterName"; loadProps[0].Value = new uno.Any("calc8"); loadProps[1] = new PropertyValue(); loadProps[1].Name = "Overwrite"; loadProps[1].Value = new uno.Any(true); XComponent xComponent = xComponentLoader.loadComponentFromURL("file:///C:/test/document.ods", "_blank", 0, loadProps); XSpreadsheetDocument xDoc = (XSpreadsheetDocument)xComponent; XSpreadsheets xSheets = xDoc.getSheets(); XIndexAccess xSheetIA = (XIndexAccess)xSheets; // Создаем новые листы и вставляем их в конец списка листов xSheets.insertNewByName("List1", (short)xSheetIA.getCount()); xSheets.insertNewByName("List2", (short)xSheetIA.getCount()); xSheetIA.getByIndex(0); XNameContainer xNC = (XNameContainer)xSheetIA; //Удаляем лист с названием - List2 xNC.removeByName("List1"); // получаем интерфейс XStorable для текущего документа XStorable xStorable = (XStorable)xComponent; // задаем URL для сохранения документа string saveUrl = "file:///C:/test/document.ods"; // сохраняем документ xStorable.storeAsURL(saveUrl, loadProps); // закрываем документ //xComponent.dispose(); } } }