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.text; using unoidl.com.sun.star.drawing; using unoidl.com.sun.star.awt; 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("writer8"); loadProps[1] = new PropertyValue(); loadProps[1].Name = "Overwrite"; loadProps[1].Value = new uno.Any(true); XComponent xComponent = xComponentLoader.loadComponentFromURL("file:///C:/test/document.odt", "_blank", 0, loadProps); //Получаем объект документа XTextDocument xDoc = (XTextDocument)xComponent; //Получаем объект текста XText xText = (XText)xDoc.getText(); //Получаем объект XMultiServiceFactory для создания TextGraphicObject XMultiServiceFactory xServiceFactory = (XMultiServiceFactory)xDoc; //Получаем объект XTextContent для вставки в метод insertTextContent() интерфейса XText. И создаем экземпляр объекта TextGraphicObject XTextContent xTextContent = (XTextContent)xServiceFactory.createInstance("com.sun.star.text.TextGraphicObject"); //Получаем объект XShape для доступа к размеру фигуры XShape xShape = (XShape)xTextContent; //Получаем доступ к свойствам XPropertySet xProps = (XPropertySet)xShape; string imagePath = "file:///C:/test/test.jpg"; xProps.setPropertyValue("GraphicURL", new uno.Any(imagePath)); //Вставляем изображение xText.insertTextContent(xText.getEnd(), xTextContent, true); Size size = new Size(); size.Width = 10000; size.Height = 10000; xShape.setSize(size); XShape xShapeEllipse = (XShape)xServiceFactory.createInstance("com.sun.star.drawing.EllipseShape"); XPropertySet xPropsEllipse = (XPropertySet)xShapeEllipse; Size sizeEllipse = new Size(); Point positionEllipse = new Point(); sizeEllipse.Width = 10000; sizeEllipse.Height = 10000; positionEllipse.X = (int)(0.9 * (30000 - size.Width)); positionEllipse.Y = (int)(0.5 * (15000 - size.Width)); xShapeEllipse.setSize(sizeEllipse); xShapeEllipse.setPosition(positionEllipse); xPropsEllipse.setPropertyValue("FillColor", new uno.Any(0xFF0000)); XTextContent xTextContentEllipse = (XTextContent)xShapeEllipse; xText.insertTextContent(xText.getEnd(), xTextContentEllipse, false); // получаем интерфейс XStorable для текущего документа XStorable xStorable = (XStorable)xComponent; // задаем URL для сохранения документа string saveUrl = "file:///C:/test/document.odt"; // сохраняем документ xStorable.storeAsURL(saveUrl, loadProps); // закрываем документ //xComponent.dispose(); } } }