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; 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; XCellRange xSheet = (XCellRange)xSheetIA.getByIndex(0).Value; //Получаем доступ к ячейкам по положению XCell xCellA1 = (XCell)xSheet.getCellByPosition(0, 0); XCell xCellA2 = (XCell)xSheet.getCellByPosition(1, 0); xCellA1.setFormula("Hello"); xCellA2.setFormula("World"); //Получаем доступ к ячейкам по имени или диапазону XCellRange xCellC1 = xSheet.getCellRangeByName("C1"); XCellRange xCellD1 = xSheet.getCellRangeByName("D1"); XCell xSetCellC1 = (XCell)xCellC1; XCell xSetCellD1 = (XCell)xCellD1; xSetCellC1.setFormula("From"); xSetCellD1.setFormula("ALMI Partner"); // получаем интерфейс XStorable для текущего документа XStorable xStorable = (XStorable)xComponent; // задаем URL для сохранения документа string saveUrl = "file:///C:/test/document.ods"; // сохраняем документ xStorable.storeAsURL(saveUrl, loadProps); // закрываем документ //xComponent.dispose(); } } }