Ejemplo n.º 1
0
        public void CreateNewDocumentAndDoAPrintOut()
        {
            string fileToPrint = AARunMeFirstAndOnce.outPutFolder + "fileToPrint.odt";

            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a standard paragraph using the ParagraphBuilder
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);

            //Add some simple text
            paragraph.TextContent.Add(new SimpleText(document, "Some simple text!"));
            //Add the paragraph to the document
            document.Content.Add(paragraph);
            //Save empty
            document.SaveTo(fileToPrint);

            //Now print the new document via the OpenOfficeLib
            //Get the Component Context
            XComponentContext xComponentContext = Connector.GetComponentContext();
            //Get a MultiServiceFactory
            XMultiServiceFactory xMultiServiceFactory = Connector.GetMultiServiceFactory(xComponentContext);
            //Get a Dektop instance
            XDesktop xDesktop = Connector.GetDesktop(xMultiServiceFactory);

            //Convert a windows path to an OpenOffice one
            fileToPrint = Component.PathConverter(fileToPrint);
            //Load the document you want to print
            XComponent xComponent = Component.LoadDocument(
                (XComponentLoader)xDesktop, fileToPrint, "_blank");

            //Print the XComponent
            Printer.Print(xComponent);
        }
Ejemplo n.º 2
0
        public static void ConvertToPdf(string inputFile, string outputFile)
        {
            if (ConvertExtensionToFilterType(Path.GetExtension(inputFile)) == null)
            {
                throw new InvalidProgramException("Unknown file type for OpenOffice. File = " + inputFile);
            }

            //StartOpenOffice();

            //Get a ComponentContext
            var xLocalContext = Bootstrap.bootstrap();
            //Get MultiServiceFactory
            XMultiServiceFactory xRemoteFactory = (XMultiServiceFactory)xLocalContext.getServiceManager();
            //Get a CompontLoader
            XComponentLoader aLoader = (XComponentLoader)xRemoteFactory.createInstance("com.sun.star.frame.Desktop");
            //Load the sourcefile

            XComponent xComponent = null;

            try
            {
                xComponent = initDocument(aLoader, PathConverter(inputFile), "_blank");
                //Wait for loading
                while (xComponent == null)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                // save/export the document
                saveDocument(xComponent, inputFile, PathConverter(outputFile));
            }
            catch { throw; }
            finally { xComponent.dispose(); }
        }
Ejemplo n.º 3
0
        internal static Object CreateObjectFromService(Object _msf, String[] services)
        {
            try
            {
                // get MSF
                XMultiServiceFactory msf = _msf as XMultiServiceFactory;

                if (msf == null)
                {
                    msf = OO.GetMultiServiceFactory();
                }
                if (msf != null && services != null && services.Length > 0)
                {
                    string[] serv = msf.getAvailableServiceNames();
                    System.Diagnostics.Debug.WriteLine("Available Service Names: " + String.Join("\n\t", serv));

                    //object component = msf.createInstance(services[0]);
                    // object component = msf.createInstance("com.sun.star.document.ExportGraphicObjectResolver");
                    object component = msf.createInstance("com.sun.star.document.ImportEmbeddedObjectResolver");

                    //Debug.GetAllServicesOfObject(component);
                    Debug.GetAllInterfacesOfObject(component);

                    var n = ((XNameAccess)component).getElementNames();


                    return(component);
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Ejemplo n.º 4
0
        //ファイルを開く
        public void OpenFile(string filePath)
        {
            //parameterファイルを開く
            string path = filePath;

            // pathをURIに変換
            Uri.TryCreate(path, UriKind.Absolute, out uriCalcFile);

            // OpenOfficeファイルを開くためのおまじない
            // コンポーネントコンテキストの取得
            localContext = Bootstrap.bootstrap();
            // サービスマネージャーの取得
            multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();
            // コンポーネントローダーの取得
            loader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");

            // 非表示で実行するためのプロパティ指定
            calcProp          = new PropertyValue[1];
            calcProp[0]       = new PropertyValue();
            calcProp[0].Name  = "Hidden";
            calcProp[0].Value = new uno.Any(true);

            // Calcファイルを開く
            doc = (XSpreadsheetDocument)loader.loadComponentFromURL(uriCalcFile.ToString(), "_blank", 0, calcProp);
            // シート群を取得
            sheets = doc.getSheets();
        }
        protected override bool AddMenuEnties(ContextMenuExecuteEvent aEvent, XMultiServiceFactory xMenuElementFactory, XIndexContainer xContextMenu)
        {
            debugEvent(aEvent);

            xContextMenu.insertByIndex(0, Any.Get(CreateLineSeperator(xMenuElementFactory)));
            xContextMenu.insertByIndex(0, Any.Get(CreateMenueEntry(xMenuElementFactory, "testZeug", ".uno:open", "")));
            return(true);
        }
Ejemplo n.º 6
0
        public OpenOffice()
        {
            // Start a new instance of OpenOffice.org if it is not running.
            // https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/CLI/Writing_Client_Programs
            context = uno.util.Bootstrap.bootstrap();

            service = (XMultiServiceFactory)context.getServiceManager();
            desktop = (XComponentLoader)service.createInstance("com.sun.star.frame.Desktop");
        }
Ejemplo n.º 7
0
        protected XDrawPagesSupplier UseDraw()
        {
            try
            {
                //create new draw document and insert rectangle shape
                XComponent         xDrawComponent     = NewDocComponent("sdraw");
                XDrawPagesSupplier xDrawPagesSupplier = xDrawComponent as XDrawPagesSupplier;

                Object       drawPages         = xDrawPagesSupplier.getDrawPages();
                XIndexAccess xIndexedDrawPages = drawPages as XIndexAccess;

                Object drawPage = xIndexedDrawPages.getByIndex(0).Value;

                System.Diagnostics.Debug.WriteLine(xIndexedDrawPages.getCount());

                if (drawPage is XDrawPage)
                {
                    XDrawPage xDrawPage = (XDrawPage)drawPage;

                    if (xDrawPage is XComponent)
                    {
                        (xDrawPage as XComponent).addEventListener(new TestOOoEventListerner());
                    }

                    // get internal service factory of the document
                    XMultiServiceFactory xDrawFactory = xDrawComponent as XMultiServiceFactory;

                    Object drawShape = xDrawFactory.createInstance(
                        "com.sun.star.drawing.RectangleShape");
                    XShape xDrawShape = drawShape as XShape;
                    xDrawShape.setSize(new Size(10000, 20000));
                    xDrawShape.setPosition(new Point(5000, 5000));
                    xDrawPage.add(xDrawShape);

                    // XText xShapeText = (XText)drawShape // COMMENTED BY CODEIT.RIGHT;
                    XPropertySet xShapeProps = (XPropertySet)drawShape;

                    // wrap text inside shape
                    xShapeProps.setPropertyValue("TextContourFrame", new uno.Any(true));
                    return(xDrawPagesSupplier);
                }
                else
                {
                    //TODO: handle if no drwapage was found
                    System.Diagnostics.Debug.WriteLine("no XDrawPage found");
                    System.Diagnostics.Debug.WriteLine(drawPage);
                }
            }
            catch (unoidl.com.sun.star.lang.DisposedException e)
            { //works from Patch 1
                MXContext = null;
                throw e;
            }

            return(null);
        }
        /// <summary>
        /// Creates a menue entry.
        /// </summary>
        /// <param name="xMenuElementFactory">The x menu element factory.</param>
        /// <param name="text">The text.</param>
        /// <param name="commandUrl">The command URL.</param>
        /// <param name="helpUrl">The help URL.</param>
        /// <param name="subContainer">The sub container.</param>
        /// <returns></returns>
        protected XPropertySet CreateMenueEntry(XMultiServiceFactory xMenuElementFactory, string text, string commandUrl, string helpUrl, XIndexContainer subContainer)
        {
            var entry = CreateMenueEntry(xMenuElementFactory, text, commandUrl, helpUrl);

            if (entry != null)
            {
                entry.setPropertyValue("SubContainer", Any.Get(subContainer));
            }
            return(entry);
        }
        /// <summary>
        /// Creates a line seperator.
        /// </summary>
        /// <param name="xMenuElementFactory">The x menu element factory.</param>
        /// <returns></returns>
        protected XPropertySet CreateLineSeperator(XMultiServiceFactory xMenuElementFactory)
        {
            // create a line separator for our new help sub menu
            XPropertySet xSeparator =
                (XPropertySet)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerSeparator");
            short aSeparatorType = ActionTriggerSeparatorType.LINE;

            xSeparator.setPropertyValue("SeparatorType", Any.Get(aSeparatorType));
            return(xSeparator);
        }
 /// <summary>
 /// Provides an easy way to dispatch an URL using one call instead of multiple ones.
 /// Normally a complete dispatch is splitted into different parts: 
 /// - converting and parsing the URL 
 /// - searching for a valid dispatch object available on a dispatch provider 
 /// - dispatching of the URL and it's parameters
 /// </summary>
 /// <param name="_msf">The MSF.</param>
 /// <returns>The dispatch helper or <c>null</c></returns>
 internal static XDispatchHelper GetDispatcher(XMultiServiceFactory _msf = null)
 {
     if (_msf == null) _msf = OO.GetMultiServiceFactory();
     if (_msf != null)
     {
         //Create the Dispatcher
         return _msf.createInstance("com.sun.star.frame.DispatchHelper") as XDispatchHelper;
     }
     return null;
 }
        /// <summary>
        /// Event Listener to get called.
        /// </summary>
        /// <param name="aEvent">A event.</param>
        /// <returns></returns>
        public ContextMenuInterceptorAction notifyContextMenuExecute(ContextMenuExecuteEvent aEvent)
        {
            XIndexContainer      xContextMenu        = aEvent.ActionTriggerContainer;
            XMultiServiceFactory xMenuElementFactory = (XMultiServiceFactory)xContextMenu;

            if (AddMenuEnties(aEvent, xMenuElementFactory, xContextMenu))
            {
                return(ContextMenuInterceptorAction.CONTINUE_MODIFIED);
            }
            return(ContextMenuInterceptorAction.IGNORED);
        }
Ejemplo n.º 12
0
 protected static void TryInitServiceManager()
 {
     try
     {
         XComponentContext    context = uno.util.Bootstrap.bootstrap();
         XMultiServiceFactory manager = (XMultiServiceFactory)context.getServiceManager();
         serviceManager = (XComponentLoader)manager.createInstance("com.sun.star.frame.Desktop");
     }
     catch
     {
     }
 }
        /// <summary>
        /// Creates a sub menu container.
        /// </summary>
        /// <param name="xMenuElementFactory">The x menu element factory.</param>
        /// <param name="entries">The entries.</param>
        /// <returns></returns>
        protected XIndexContainer CreateSubMenuContainer(XMultiServiceFactory xMenuElementFactory, XPropertySet[] entries = null)
        {
            var entry = (XIndexContainer)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerContainer");

            if (entry != null && entries != null && entries.Length > 0)
            {
                for (int i = 0; i < entries.Length; i++)
                {
                    entry.insertByIndex(i, Any.Get(entries[i]));
                }
            }
            return(entry);
        }
 /// <summary>
 /// Provides an easy way to dispatch an URL using one call instead of multiple ones.
 /// Normally a complete dispatch is splitted into different parts:
 /// - converting and parsing the URL
 /// - searching for a valid dispatch object available on a dispatch provider
 /// - dispatching of the URL and it's parameters
 /// </summary>
 /// <param name="_msf">The MSF.</param>
 /// <returns>The dispatch helper or <c>null</c></returns>
 internal static XDispatchHelper GetDispatcher(XMultiServiceFactory _msf = null)
 {
     if (_msf == null)
     {
         _msf = OO.GetMultiServiceFactory();
     }
     if (_msf != null)
     {
         //Create the Dispatcher
         return(_msf.createInstance("com.sun.star.frame.DispatchHelper") as XDispatchHelper);
     }
     return(null);
 }
        /// <summary>
        /// Creates the menue entry.
        /// </summary>
        /// <param name="xMenuElementFactory">The x menu element factory.</param>
        /// <param name="text">The text.</param>
        /// <param name="commandUrl">The command URL.</param>
        /// <param name="helpUrl">The help URL.</param>
        /// <returns></returns>
        protected XPropertySet CreateMenueEntry(XMultiServiceFactory xMenuElementFactory, string text, string commandUrl, string helpUrl)
        {
            var entry =
                (XPropertySet)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTrigger");

            if (entry != null)
            {
                var properties = new Dictionary <String, Object>
                {
                    { "Text", text }, { "CommandURL", commandUrl }, { "HelpURL", helpUrl }
                };
                entry = CreateEntry(entry, properties);
            }
            return(entry);
        }
        /// <summary>
        /// Creates a progress bar control.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="_nPosX">The X position.</param>
        /// <param name="_nPosY">The Y position.</param>
        /// <param name="_nWidth">Width of the element.</param>
        /// <param name="_nHeight">Height of the element.</param>
        /// <param name="_nProgressMax">The max value.</param>
        /// <param name="_nProgress">The current progress value.</param>
        /// <param name="visible">if set to <c>true</c> the progress bar will be visble while creation.
        /// ATTENTION: from the scratch it is set to <c>true</c>. If you want to hide it while creation 
        /// set this to <c>false</c> and change the 'EnableVisible' property to true after creation.</param>
        /// <param name="xMSF">A XMultiServiceFactory for controll creation.</param>
        /// <returns>a XProgressBar or <c>null</c></returns>
        public static XProgressBar CreateProgressBar(String name, int _nPosX, int _nPosY, int _nWidth, int _nHeight, int _nProgressMax, int _nProgress, bool visible = true, XMultiServiceFactory xMSF = null)
        {
            try
            {
                // check service factory 
                xMSF = xMSF != null ? xMSF : OO.GetMultiServiceFactory();

                //try to generate unique name
                name = AbstractControllBase.GenerateUniqueName(String.IsNullOrWhiteSpace(name) ? "ProgressBar_" : name + "_");

                // create a control model
                Object oPBModel = xMSF.createInstance(OO.Services.AWT_CONTROL_PROGRESS_BAR_MODEL);
                // create a control
                Object xPBControl = xMSF.createInstance(OO.Services.AWT_CONTROL_PROGRESS_BAR);

                if (xPBControl == null && oPBModel != null)
                {
                    string defaultControllName = OoUtils.GetStringProperty(oPBModel, "DefaultControl");
                    if (!String.IsNullOrWhiteSpace(defaultControllName))
                    {
                        xPBControl = xMSF.createInstance(defaultControllName);
                    }
                }

                if (oPBModel != null && xPBControl != null && xPBControl is XControl && oPBModel is XControlModel)
                {
                    ((XControl)xPBControl).setModel(((XControlModel)oPBModel));

                    XMultiPropertySet xPBModelMPSet = oPBModel as XMultiPropertySet;

                    if (xPBModelMPSet != null)
                    {
                        // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
                        xPBModelMPSet.setPropertyValues(
                                new String[] { "EnableVisible", "Height", "Name", "PositionX", "PositionY", "ProgressValue", "ProgressValueMax", "ProgressValueMin", "Width" },
                                Any.Get(new Object[] { visible, _nHeight, name, _nPosX, _nPosY, _nProgress, _nProgressMax, 0, _nWidth }));
                    }
                    return xPBControl as XProgressBar;
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Control creation exception: " + ex);
            }

            return null;

        }
Ejemplo n.º 17
0
        public OpenOffice()
        {
            /// This will start a new instance of OpenOffice.org if it is not running,
            /// or it will obtain an existing instance if it is already open.
            context = uno.util.Bootstrap.bootstrap();

            /// The next step is to create a new OpenOffice.org service manager
            service = (XMultiServiceFactory)context.getServiceManager();

            /// Create a new Desktop instance using our service manager
            component = (XComponentLoader)service.createInstance("com.sun.star.frame.Desktop");

            // Getting filters
            XNameContainer filters = (XNameContainer)service.createInstance("com.sun.star.document.FilterFactory");

            foreach (string filter in filters.getElementNames())
            {
                this.filters.Add(filter);
            }
        }
Ejemplo n.º 18
0
        public virtual string GetOpenOfficeProperty(string nodePath, string node)
        {
            if (!nodePath.StartsWith("/"))
            {
                nodePath = "/" + nodePath;
            }
            Any property;

            // create the provider and remember it as a XMultiServiceFactory
            try
            {
                const string         sProviderService = "com.sun.star.configuration.ConfigurationProvider";
                object               configProvider   = _connection.RemoteServiceManager.createInstanceWithContext(sProviderService, _connection.ComponentContext);
                XMultiServiceFactory xConfigProvider  = (XMultiServiceFactory)configProvider;

                // The service name: Need only read access:
                const string sReadOnlyView = "com.sun.star.configuration.ConfigurationAccess";
                // creation arguments: nodepath
                PropertyValue aPathArgument = new PropertyValue
                {
                    Name  = "nodepath",
                    Value = new Any(nodePath)
                };
                Any[] aArguments = new Any[1];
                aArguments[0] = aPathArgument.Value;

                // create the view
                //XInterface xElement = (XInterface) xConfigProvider.createInstanceWithArguments(sReadOnlyView, aArguments);
                XNameAccess xChildAccess = (XNameAccess)xConfigProvider.createInstanceWithArguments(sReadOnlyView, aArguments);

                // get the value
                property = xChildAccess.getByName(node);
            }
            catch (Exception exception)
            {
                throw new OpenOfficeException("Could not retrieve property", exception);
            }
            return(property.ToString());
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            InitOpenOfficeEnvironment();
            XMultiServiceFactory multiServiceFactory = Connect();
            XComponent           xComponent          = null;

            string docFileName = @"C:\test3.doc";

            try
            {
                XComponentLoader componentLoader =
                    (XComponentLoader)multiServiceFactory
                    .createInstance("com.sun.star.frame.Desktop");
                //set the property
                PropertyValue[] propertyValue = new PropertyValue[1];
                PropertyValue   aProperty     = new PropertyValue();
                aProperty.Name   = "Hidden";
                aProperty.Value  = new uno.Any(false);
                propertyValue[0] = aProperty;
                xComponent       =
                    componentLoader
                    .loadComponentFromURL(PathConverter(docFileName),
                                          "_blank", 0, propertyValue);
                XTextDocument      xTextDocument      = ((XTextDocument)xComponent);
                XEnumerationAccess xEnumerationAccess =
                    (XEnumerationAccess)xTextDocument.getText();
                XEnumeration xParagraphEnumeration =
                    xEnumerationAccess.createEnumeration();
                while (xParagraphEnumeration.hasMoreElements())
                {
                    uno.Any      element = xParagraphEnumeration.nextElement();
                    XServiceInfo xinfo   = (XServiceInfo)element.Value;
                    if (xinfo.supportsService("com.sun.star.text.TextTable"))
                    {
                        Console.WriteLine("Found Table!");

                        XTextTable xTextTable = (XTextTable)element.Value;
                        String[]   cellNames  = xTextTable.getCellNames();

                        for (int i = 0; i < cellNames.Length; i++)
                        {
                            XCell  xCell     = xTextTable.getCellByName(cellNames[i]);
                            XText  xTextCell = (XText)xCell;
                            String strText   = xTextCell.getString();
                            Console.WriteLine(strText);
                        }
                    }
                    else
                    {
                        XTextContent       xTextElement           = (XTextContent)element.Value;
                        XEnumerationAccess xParaEnumerationAccess =
                            (XEnumerationAccess)xTextElement;
                        // create another enumeration to get all text portions of
                        //the paragraph
                        XEnumeration xTextPortionEnum =
                            xParaEnumerationAccess.createEnumeration();
                        //step 3  Through the Text portions Enumeration, get interface
                        //to each individual text portion
                        while (xTextPortionEnum.hasMoreElements())
                        {
                            XTextRange xTextPortion =
                                (XTextRange)xTextPortionEnum.nextElement().Value;
                            Console.Write(xTextPortion.getString());
                        }
                    }
                }
            }
            catch (unoidl.com.sun.star.uno.Exception exp1)
            {
                Console.WriteLine(exp1.Message);
                Console.WriteLine(exp1.StackTrace);
            }
            catch (System.Exception exp2)
            {
                Console.WriteLine(exp2.Message);
                Console.WriteLine(exp2.StackTrace);
            }
            finally
            {
                xComponent.dispose();
                xComponent = null;
            }
            Console.WriteLine("Done.");
            Console.ReadLine();
        }
        /// <summary>
        /// Gets the multi service factory.
        /// DEPRECATED: for libre office this is always <c>NULL</c>. Use <see cref="XMultiComponentFactory"/> instead.
        /// </summary>
        /// <param name="xCompContext">The x comp context.</param>
        /// <param name="xMcf">The x MCF.</param>
        /// <returns></returns>
        public static XMultiServiceFactory GetMultiServiceFactory(XComponentContext xCompContext = null,
                                                                  XMultiComponentFactory xMcf = null)
        {
            if (_xMsf == null)
            {
                if (xCompContext == null)
                {
                    xCompContext = GetContext();
                }
                if (xMcf == null)
                {
                    xMcf = GetMultiComponentFactory(xCompContext);
                }

                if (_xMsf == null)
                {
                    if (xCompContext != null && xCompContext is XComponentContext)
                    {
                        _xMsf = ((XComponentContext)xCompContext).getServiceManager() as XMultiServiceFactory;
                    }
                }

                if (_xMsf == null) {
                    _xMsf = xMcf.createInstanceWithContext(Services.MULTI_SERVICE_FACTORY, xCompContext) as XMultiServiceFactory;
                }

                addListener(_xMsf);

            }
            return _xMsf;
        }
 /// <summary>
 /// Adds the menu enties.
 /// </summary>
 /// <param name="aEvent">A event.</param>
 /// <param name="xMenuElementFactory">The x menu element factory.</param>
 /// <param name="xContextMenu">The x context menu.</param>
 /// <returns></returns>
 protected abstract bool AddMenuEnties(ContextMenuExecuteEvent aEvent, XMultiServiceFactory xMenuElementFactory, XIndexContainer xContextMenu);
        public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext,
                                                     int posX, int posY, int width, int height, string title
                                                     )
        {
            //dialog model
            Object oDialogModel = xMultiComponentFactory.createInstanceWithContext(
                "com.sun.star.awt.UnoControlDialogModel", xContext);


            XPropertySet xPSetDialog = (XPropertySet)oDialogModel;

            xPSetDialog.setPropertyValue("PositionX", Any.Get(posX));
            xPSetDialog.setPropertyValue("PositionY", Any.Get(posY));
            xPSetDialog.setPropertyValue("Width", Any.Get(width));
            xPSetDialog.setPropertyValue("Height", Any.Get(height));
            xPSetDialog.setPropertyValue("Title", Any.Get(title));

            // get service manager from  dialog model
            XMultiServiceFactory MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

            // dialog control model
            Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext(
                "com.sun.star.awt.UnoControlDialog", xContext);


            XControl      MXDialogControl = (XControl)oUnoDialog;
            XControlModel xControlModel   = (XControlModel)oDialogModel;

            MXDialogControl.setModel(xControlModel);



            XToolkit xToolkit = (XToolkit)xMultiComponentFactory
                                .createInstanceWithContext("com.sun.star.awt.Toolkit",
                                                           xContext);

            WindowDescriptor aDescriptor = new WindowDescriptor();

            aDescriptor.Type = WindowClass.TOP;
            aDescriptor.WindowServiceName = "";
            aDescriptor.ParentIndex       = -1;
            aDescriptor.Parent            = xToolkit.getDesktopWindow();
            aDescriptor.Bounds            = new Rectangle(100, 200, 300, 400);

            aDescriptor.WindowAttributes = WindowAttribute.BORDER
                                           | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE
                                           | WindowAttribute.CLOSEABLE;

            XWindowPeer xPeer = xToolkit.createWindow(aDescriptor);

            XWindow xWindow = (XWindow)xPeer;

            xWindow.setVisible(false);
            MXDialogControl.createPeer(xToolkit, xPeer);

            // execute the dialog
            XDialog xDialog = (XDialog)oUnoDialog;

            xDialog.execute();

            // dispose the dialog
            XComponent xComponent = (XComponent)oUnoDialog;

            xComponent.dispose();

            return(oUnoDialog as XControlContainer);
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            Socket
                s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

            string
                sUnoIni = "file:///c:/OpenOffice.org%203/URE/bin/uno.ini";

            XComponentContext
            //xLocalContext = uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(sUnoIni, null);
                xLocalContext = uno.util.Bootstrap.defaultBootstrap_InitialComponentContext();

            XMultiComponentFactory
                xLocalServiceManager = xLocalContext.getServiceManager();

            XUnoUrlResolver
                xUrlResolver = (XUnoUrlResolver)xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext);

            XMultiServiceFactory
                xRemoteServiceManager = (XMultiServiceFactory)xUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");

            XDesktop
                Desktop = (XDesktop)xRemoteServiceManager.createInstance("com.sun.star.frame.Desktop");

            /*
             * XDesktop
             *      remoteDesktop = (XDesktop)xRemoteServiceManager.createInstance("com.sun.star.frame.Desktop");
             *
             * XComponentLoader
             *      Desktop = (XComponentLoader)remoteDesktop; // (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
             *
             * XComponent
             *      Document = Desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
             *
             * XText
             *      Text = ((XTextDocument)Document).getText();
             *
             * Text.setString("Hello I'm the first text!");
             *
             * XTextCursor
             *      Cursor = Text.createTextCursor();
             *
             * Text.insertString(Cursor, "Line# 1\n", false);
             * Text.insertString(Cursor, "Line# 2", false);
             *
             * XTextTable
             *      Table;
             *
             * if ((Table = (XTextTable)multiServiceFactory.createInstance("com.sun.star.text.TextTable")) != null)
             * {
             *      Table.initialize(2, 2);
             *      Text.insertTextContent(Text.getEnd(), Table, false);
             * }
             *
             *
             * unoidl.com.sun.star.beans.PropertyValue[]
             *      Params = new unoidl.com.sun.star.beans.PropertyValue[2];
             *
             * unoidl.com.sun.star.beans.PropertyValue
             *      Param = new unoidl.com.sun.star.beans.PropertyValue();
             *
             * Param.Name = "FilterName";
             * Param.Value = new uno.Any("writer_pdf_Export");
             * Params[0] = Param;
             *
             * Param = new unoidl.com.sun.star.beans.PropertyValue();
             * Param.Name = "CompressionMode";
             * Param.Value = new uno.Any("1");
             * Params[1] = Param;
             *
             * string
             *      CurrentDirectory = System.IO.Directory.GetCurrentDirectory(),
             *      DocumentDestName;
             *
             * CurrentDirectory = CurrentDirectory.Substring(0, CurrentDirectory.LastIndexOf("bin", CurrentDirectory.Length - 1));
             *
             * if (File.Exists(DocumentDestName = (CurrentDirectory + "test_out.pdf")))
             *      File.Delete(DocumentDestName);
             *
             * DocumentDestName = DocumentDestName.Replace(Path.DirectorySeparatorChar, '/').Replace("#", "%23");
             *
             * ((XStorable)Document).storeToURL("file:///" + DocumentDestName, Params);
             */
        }
Ejemplo n.º 24
0
        private static void ConvertToPdf(string filePath)
        {
            Process[] ps = Process.GetProcessesByName("soffice.exe");
            if (ps.Length != 0)
            {
                throw new InvalidProgramException("OpenOffice not found.  Is OpenOffice installed?");
            }
            if (ps.Length > 0)
            {
                return;
            }
            Process p = new Process
            {
                StartInfo =
                {
                    Arguments      = "-headless -nofirststartwizard",
                    FileName       = "soffice.exe",
                    CreateNoWindow = true
                }
            };
            bool result = p.Start();

            if (result == false)
            {
                throw new InvalidProgramException("OpenOffice failed to start.");
            }
            XComponentContext    xLocalContext  = Bootstrap.bootstrap();
            XMultiServiceFactory xRemoteFactory = (XMultiServiceFactory)xLocalContext.getServiceManager();
            XComponentLoader     aLoader        = (XComponentLoader)xRemoteFactory.createInstance("com.sun.star.frame.Desktop");
            XComponent           xComponent     = null;

            try
            {
                PropertyValue[] openProps = new PropertyValue[1];
                openProps[0] = new PropertyValue {
                    Name = "Hidden", Value = new Any(true)
                };
                xComponent = aLoader.loadComponentFromURL(PathConverter(filePath), "_blank", 0, openProps);
                while (xComponent == null)
                {
                    Thread.Sleep(1000);
                }
                PropertyValue[] propertyValues = new PropertyValue[2];
                propertyValues[1] = new PropertyValue {
                    Name = "Overwrite", Value = new Any(true)
                };
                propertyValues[0] = new PropertyValue {
                    Name = "FilterName", Value = new Any(ConvertExtensionToFilterType(Path.GetExtension(filePath)))
                };
                ((XStorable)xComponent).storeToURL(PathConverter(OutputFolder + Path.GetFileNameWithoutExtension(filePath) + ".pdf"), propertyValues);
            }
            catch (System.Exception e)
            {
                log.Error("Eccezione la conversione del file OpenOffice " + filePath);
                log.Error(e.StackTrace);
                File.Move(filePath, ErrorFolder + Path.GetFileName(filePath));
            }
            finally
            {
                if (xComponent != null)
                {
                    xComponent.dispose();
                }
                CloseProcess("soffice");
                File.Delete(filePath);
            }
        }
 /// <summary>
 /// Creates the menue entry.
 /// </summary>
 /// <param name="xMenuElementFactory">The x menu element factory.</param>
 /// <param name="text">The text.</param>
 /// <param name="commandUrl">The command URL.</param>
 /// <param name="helpUrl">The help URL.</param>
 /// <returns></returns>
 protected XPropertySet CreateMenueEntry(XMultiServiceFactory xMenuElementFactory, string text, string commandUrl, string helpUrl)
 {
     var entry =
                 (XPropertySet)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTrigger");
     if (entry != null)
     {
         var properties = new Dictionary<String, Object>
                              {{"Text", text}, {"CommandURL", commandUrl}, {"HelpURL", helpUrl}};
         entry = CreateEntry(entry, properties);
     }
     return entry;
 }
 /// <summary>
 /// Creates a line seperator.
 /// </summary>
 /// <param name="xMenuElementFactory">The x menu element factory.</param>
 /// <returns></returns>
 protected XPropertySet CreateLineSeperator(XMultiServiceFactory xMenuElementFactory)
 {
     // create a line separator for our new help sub menu
     XPropertySet xSeparator =
         (XPropertySet)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerSeparator");
     short aSeparatorType = ActionTriggerSeparatorType.LINE;
     xSeparator.setPropertyValue("SeparatorType", Any.Get(aSeparatorType));
     return xSeparator;
 }
        public static void ExportExcelLO(string FileName, DataSet ds)
        {
            try
            {
                string unoPath = @"C:\Program Files (x86)\LibreOffice 5\program";
                Environment.SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process);
                Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";"
                                                   + unoPath, EnvironmentVariableTarget.Process);

                XComponentContext    oStrap   = uno.util.Bootstrap.bootstrap();
                XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
                XComponentLoader     desktop  = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
                string          url           = @"private:factory/scalc";
                PropertyValue[] loadProps     = new PropertyValue[3];
                loadProps[0] = new PropertyValue()
                {
                    Name  = "Hidden",
                    Value = new uno.Any(true)
                };

                loadProps[1] = new PropertyValue()
                {
                    Name  = "FilterName",
                    Value = new uno.Any("MS Excel 97")
                };

                loadProps[2] = new PropertyValue()
                {
                    Name  = "ReadOnly",
                    Value = new uno.Any(false)
                };

                XComponent    document = desktop.loadComponentFromURL(url, "_blank", 0, loadProps);
                XSpreadsheets oSheets = ((XSpreadsheetDocument)document).getSheets();
                XIndexAccess  oSheetsIA = (XIndexAccess)oSheets;
                XSpreadsheet  sheet = (XSpreadsheet)oSheetsIA.getByIndex(0).Value;
                int           ii = 0; XCell celija = null;
                foreach (DataColumn kol in ds.Tables[0].Columns)
                {
                    celija = sheet.getCellByPosition(ii, 0);
                    ((XText)celija).setString(kol.ColumnName);
                    //((XPropertySet)celija).setPropertyValue("CellBackColor", new uno.Any(654321));
                    //((XPropertySet)celija).setPropertyValue("CharColor", new uno.Any(333444));
                    ii++;
                }
                ds.Tables[0].AcceptChanges(); ii = 0;
                foreach (DataRow red in ds.Tables[0].Rows)
                {
                    int jj = 0; ii++;
                    foreach (object ob in red.ItemArray)
                    {
                        celija = sheet.getCellByPosition(jj, ii);
                        ((XText)celija).setString(ob.ToString());
                        //((XPropertySet)celija).setPropertyValue("CellBackColor", new uno.Any(888777));
                        jj++;
                    }
                }
                ((XStorable)document).storeToURL("file:///" + FileName.Replace(@"\", "/"), loadProps);
                System.Diagnostics.Process.Start(FileName);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// Adds the menu enties.
 /// </summary>
 /// <param name="aEvent">A event.</param>
 /// <param name="xMenuElementFactory">The x menu element factory.</param>
 /// <param name="xContextMenu">The x context menu.</param>
 /// <returns></returns>
 protected abstract bool AddMenuEnties(ContextMenuExecuteEvent aEvent, XMultiServiceFactory xMenuElementFactory, XIndexContainer xContextMenu);
 /// <summary>
 /// Creates a sub menu container.
 /// </summary>
 /// <param name="xMenuElementFactory">The x menu element factory.</param>
 /// <param name="entries">The entries.</param>
 /// <returns></returns>
 protected XIndexContainer CreateSubMenuContainer(XMultiServiceFactory xMenuElementFactory, XPropertySet[] entries = null)
 {
     var entry = (XIndexContainer)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerContainer");
     if (entry != null && entries != null && entries.Length > 0)
     {
         for (int i = 0; i < entries.Length; i++)
         {
             entry.insertByIndex(i,Any.Get(entries[i]));
         }
     }
     return entry;
 }
 /// <summary>
 /// Creates a menue entry.
 /// </summary>
 /// <param name="xMenuElementFactory">The x menu element factory.</param>
 /// <param name="text">The text.</param>
 /// <param name="commandUrl">The command URL.</param>
 /// <param name="helpUrl">The help URL.</param>
 /// <param name="subContainer">The sub container.</param>
 /// <returns></returns>
 protected XPropertySet CreateMenueEntry(XMultiServiceFactory xMenuElementFactory, string text, string commandUrl, string helpUrl, XIndexContainer subContainer)
 {
     var entry = CreateMenueEntry(xMenuElementFactory, text, commandUrl, helpUrl);
     if (entry != null)
     {
         entry.setPropertyValue("SubContainer", Any.Get(subContainer));
     }
     return entry;
 }
        protected override bool AddMenuEnties(ContextMenuExecuteEvent aEvent, XMultiServiceFactory xMenuElementFactory, XIndexContainer xContextMenu)
        {
            debugEvent(aEvent);

            xContextMenu.insertByIndex(0, Any.Get(CreateLineSeperator(xMenuElementFactory)));
            xContextMenu.insertByIndex(0, Any.Get(CreateMenueEntry(xMenuElementFactory, "testZeug", ".uno:open", "")));
            return true;
        }
Ejemplo n.º 32
0
        private void CreaReport(object sender, DoWorkEventArgs e)
        {
            string PathTemplate = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "template.odt";

            if (File.Exists(PathTemplate))
            {
                //The C# application starts OpenOffice.org by using it's bootstrap method:
                XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
                //This will start a new instance of OpenOffice.org if it is not running,
                //or it will obtain an existing instance if it is already open.
                //The next step is to create a new OpenOffice.org service manager:
                XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();

                XComponentLoader oDesk = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");

                //string url = @"private:factory/swriter";
                PropertyValue[] propVals = new PropertyValue[0];

                XComponent oDoc = oDesk.loadComponentFromURL(PathConverter(PathTemplate), "_blank", 0, propVals);

                //string docText = "This will be my first paragraph.\n\r";
                //docText += "This will be my second paragraph.\n\r";

                //And then this is written to the body of the document:
                //((XTextDocument)oDoc).getText().setString(docText);

                XBookmarksSupplier xBS = (XBookmarksSupplier)oDoc;

                unoidl.com.sun.star.container.XNameAccess xNamedBookmarks = xBS.getBookmarks();

                //inserimento dati nei bookmark
                //grassi
                InsertTxtBookmark(xNamedBookmarks, "bPalma", oPalmaRaf.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmaAfr", oPalmaAfr.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmaOle60", oPalmaOle60.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmaOle62", oPalmaOle62.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmaOle64", oPalmaOle64.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmaSte48", oPalmaSt48.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmaSte53", oPalmaSt53.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bCocco", oCoccoRaf.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bCoccoIdr", oCoccoIdr.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmisto", oPalmistoR.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmistoIdr", oPalmistoI.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmistoSte", oPalmistoSt.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bPalmistoFra", oPalmistoFraz.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bSoia", oSoiaRaf.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bColza", oColzaRaf.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bArachide", oArachideR.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bVinacciolo", oVinacciolo.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bMais", oMaisRaf.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bGirasoleAO", oGirasoleALino.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bGirasoleAL", oGirasoleAOle.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bSesamo", oSesamoRaff.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bNocciola", oNocciola.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bOliva", oOliva.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bBurroCacao", oBurroCacao.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bBabassu", oBabassu.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bKarite", oKarite.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bBurro", oBurro.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bStrutto", oStrutto.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bSego", oSegoRaf.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bX", oX.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bY", oY.ToString());
                InsertTxtBookmark(xNamedBookmarks, "bZ", oZ.ToString());
                //acidi grassi calcolati
                InsertTxtBookmark(xNamedBookmarks, "bC4-0", AcidiGrassiOtt[0].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC6-0", AcidiGrassiOtt[1].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC8-0", AcidiGrassiOtt[2].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC10-0", AcidiGrassiOtt[3].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC12-0", AcidiGrassiOtt[4].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC14-0", AcidiGrassiOtt[5].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC14-1", AcidiGrassiOtt[6].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC15-0", AcidiGrassiOtt[7].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC16-ISO", AcidiGrassiOtt[8].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC16-0", AcidiGrassiOtt[9].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC16-1", AcidiGrassiOtt[10].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC17-ISO", AcidiGrassiOtt[11].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC17-0", AcidiGrassiOtt[12].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC17-1", AcidiGrassiOtt[13].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC18-0", AcidiGrassiOtt[14].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC18-ISO", AcidiGrassiOtt[15].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC18-1", AcidiGrassiOtt[16].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC18-2", AcidiGrassiOtt[17].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC18-3", AcidiGrassiOtt[18].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC18-CON", AcidiGrassiOtt[19].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC20-0", AcidiGrassiOtt[20].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC20-1", AcidiGrassiOtt[21].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC22-0", AcidiGrassiOtt[22].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bC22-1", AcidiGrassiOtt[23].ToString("F2"));
                //acidi grassi inseriti a mano (forniti dal gascromatografo)
                InsertTxtBookmark(xNamedBookmarks, "bGC4-0", AcidiGrassiRic[0].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC6-0", AcidiGrassiRic[1].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC8-0", AcidiGrassiRic[2].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC10-0", AcidiGrassiRic[3].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC12-0", AcidiGrassiRic[4].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC14-0", AcidiGrassiRic[5].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC14-1", AcidiGrassiRic[6].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC15-0", AcidiGrassiRic[7].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC16-ISO", AcidiGrassiRic[8].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC16-0", AcidiGrassiRic[9].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC16-1", AcidiGrassiRic[10].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC17-ISO", AcidiGrassiRic[11].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC17-0", AcidiGrassiRic[12].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC17-1", AcidiGrassiRic[13].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC18-0", AcidiGrassiRic[14].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC18-ISO", AcidiGrassiRic[15].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC18-1", AcidiGrassiRic[16].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC18-2", AcidiGrassiRic[17].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC18-3", AcidiGrassiRic[18].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC18-CON", AcidiGrassiRic[19].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC20-0", AcidiGrassiRic[20].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC20-1", AcidiGrassiRic[21].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC22-0", AcidiGrassiRic[22].ToString("F2"));
                InsertTxtBookmark(xNamedBookmarks, "bGC22-1", AcidiGrassiRic[23].ToString("F2"));
                //numero di iodio
                InsertTxtBookmark(xNamedBookmarks, "bnIodio", oNiodio.ToString("F2"));

                //And then the file is saved to disk:
                //((XStorable)oDoc).storeAsURL(PathConverter(@"C:\test.odt"), propVals);
                //((XStorable)oDoc).storeAsURL(PathConverter(SaveTo), propVals);
                PropertyValue[] propValsOut = new PropertyValue[1];
                propValsOut[0]      = new PropertyValue();
                propValsOut[0].Name = "FilterName";
                switch (Estensione)
                {
                case ".odt":
                    break;

                case ".doc":
                    propValsOut[0].Value = new uno.Any("MS Word 97");
                    break;

                case ".pdf":
                    propValsOut[0].Value = new uno.Any("writer_pdf_Export");
                    break;

                default:
                    break;
                }

                ((XStorable)oDoc).storeToURL(PathConverter(SaveTo), propValsOut);
                //chiude
                ((XComponent)oDoc).dispose();
                //And then any memory that's been used can be freed up:
                oDoc = null;
            }
            else
            {
                MessageBox.Show("Template non trovato:\n" + PathTemplate);
            }
        }
Ejemplo n.º 33
0
        static void Main()
        {
            XComponentContext
                localContext = uno.util.Bootstrap.bootstrap();

            XMultiServiceFactory
                ServiceManager = (XMultiServiceFactory)localContext.getServiceManager();

            XComponentLoader
                Desktop = (XComponentLoader)ServiceManager.createInstance("com.sun.star.frame.Desktop");

            XComponent
                Document = Desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);

            XText
                Text = ((XTextDocument)Document).getText();

            Text.setString("Hello I'm the first text!");

            XTextCursor
                Cursor = Text.createTextCursor();

            Text.insertString(Cursor, "Line# 1\n", false);
            Text.insertString(Cursor, "Line# 2", false);

            XTextTable
                Table;

            if ((Table = (XTextTable)((XMultiServiceFactory)Document).createInstance("com.sun.star.text.TextTable")) != null)
            {
                Table.initialize(2, 2);
                Text.insertTextContent(Text.getEnd(), Table, false);
            }


            unoidl.com.sun.star.beans.PropertyValue[]
            Params = new unoidl.com.sun.star.beans.PropertyValue[2];

            unoidl.com.sun.star.beans.PropertyValue
                Param = new unoidl.com.sun.star.beans.PropertyValue();

            Param.Name  = "FilterName";
            Param.Value = new uno.Any("writer_pdf_Export");
            Params[0]   = Param;

            Param       = new unoidl.com.sun.star.beans.PropertyValue();
            Param.Name  = "CompressionMode";
            Param.Value = new uno.Any("1");
            Params[1]   = Param;

            string
                CurrentDirectory = System.IO.Directory.GetCurrentDirectory(),
                DocumentDestName;

            CurrentDirectory = CurrentDirectory.Substring(0, CurrentDirectory.LastIndexOf("bin", CurrentDirectory.Length - 1));

            if (File.Exists(DocumentDestName = (CurrentDirectory + "test_out.pdf")))
            {
                File.Delete(DocumentDestName);
            }

            DocumentDestName = DocumentDestName.Replace(Path.DirectorySeparatorChar, '/').Replace("#", "%23");

            ((XStorable)Document).storeToURL("file:///" + DocumentDestName, Params);
            ((XCloseable)Document).close(true);
        }
 /// <summary>
 /// Gets the component loader.
 /// </summary>
 /// <param name="multiServiceFactory"> The multi service factory. </param>
 /// <returns> The component loader </returns>
 public static XComponentLoader GetComponentLoader(XMultiServiceFactory multiServiceFactory)
 {
     return((XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop"));
 }