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 unoidl.com.sun.star.table; using unoidl.com.sun.star.util; namespace main { class Program { static void Main(string[] args) { // получаем контекст компонентов офиса XComponentContext xContext = uno.util.Bootstrap.bootstrap(); // получаем сервис-менеджер XMultiComponentFactory xServiceManager = (XMultiComponentFactory)xContext.getServiceManager(); // получаем экземпляр сервиса UNO Desktop // получаем интерфейс XComponentLoader Object desktop = xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); 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 для работы с листами книги XSpreadsheets xSheets = xDoc.getSheets(); XIndexAccess xSheetIA = (XIndexAccess)xSheets; XProtectable xProtectable = (XProtectable)xSheetIA.getByIndex(0).Value; //Устанавливает пароль на первый лист с индексом 0 xProtectable.protect("1234"); // получаем интерфейс XStorable для текущего документа XStorable xStorable = (XStorable)xComponent; // задаем URL для сохранения документа string saveUrl = "file:///C:/test/document.ods"; // сохраняем документ xStorable.storeAsURL(saveUrl, loadProps); // закрываем документ //xComponent.dispose(); } } }