Ejemplo n.º 1
0
        internal static XTransferableSupplier FindTransferableSupplier(XModel2 xModel2)
        {
            XTransferableSupplier result = null;

            try
            {
                if (xModel2 != null)
                {
                    XEnumeration xEnumeration = xModel2.getControllers();

                    while (xEnumeration.hasMoreElements())
                    {
                        XController xController = (XController)xEnumeration.nextElement().Value;
                        if (xController is XTransferableSupplier)
                        {
                            result = xController as XTransferableSupplier;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
        private void searchForDocs()
        {
            while (serach)
            {
                try
                {
                    if (XDesktop != null)
                    {
                        XEnumerationAccess xEnumerationAccess = XDesktop.getComponents();
                        XEnumeration       enummeraration     = xEnumerationAccess.createEnumeration();

                        var _uids = DesktopDocumentComponents.Keys;

                        while (enummeraration.hasMoreElements())
                        {
                            Any        anyelemet = enummeraration.nextElement();
                            XComponent element   = anyelemet.Value as XComponent;
                            if (element != null)
                            {
                                //FIXME: for debugging
                                //System.Diagnostics.Debug.WriteLine("Window from Desktop found _________________");
                                //Debug.GetAllInterfacesOfObject(element);
                                //System.Diagnostics.Debug.WriteLine("\tProperties _________________");
                                //Debug.GetAllProperties(element);
                                XPropertySet ps = element as XPropertySet;
                                if (ps != null)
                                {
                                    var uid = OoUtils.GetStringProperty(ps, "RuntimeUID");
                                    if (uid != null && !uid.Equals(""))
                                    {
                                        if (!DesktopDocumentComponents.ContainsKey(uid))
                                        {
                                            //FIXME: for fixing
                                            Console.WriteLine("Found new Desktop child with uid:" + uid);
                                            DesktopDocumentComponents.Add(uid, element);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (DisposedException dex) {
                    this.Dispose();
                    throw dex;
                }
                catch (System.Exception) { }


                //Console.WriteLine("\t\tSearch for Docs");
                Thread.Sleep(WAIT_TIME);
            }
        }
Ejemplo n.º 3
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();
        }