コード例 #1
0
 private XTextRange getTextRange(XTextRange from, XTextRange to)
 {
     if (from != null && to != null)
     {
         return(setXTextRange(from, to));
     }
     return(null);
 }
コード例 #2
0
 public XTextCursor setXTextRange(XTextCursor xTextCursor, XTextRange start, XTextRange end)
 {
     if (xTextCursor != null && start != null && end != null)
     {
         xTextCursor.gotoRange(start.getStart(), false);
         xTextCursor.gotoRange(end.getEnd(), true);
     }
     return(xTextCursor);
 }
コード例 #3
0
 //inserisce il testo nel bookmark, se va a buon fine ritorna true
 private bool InsertTxtBookmark(unoidl.com.sun.star.container.XNameAccess ElencoBookmark, string NomeBookmark, string Testo)
 {
     if (ElencoBookmark.hasByName(NomeBookmark))//verifica che esista il bookmark
     {
         XTextContent xFoundBookmark = (XTextContent)ElencoBookmark.getByName(NomeBookmark).Value;
         // work with bookmark
         XTextRange xFound = xFoundBookmark.getAnchor();
         xFound.setString(Testo);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #4
0
        /// <summary>
        /// Adds a new table to the document.
        /// </summary>
        /// <param name="col">The amount of columns</param>
        /// <param name="rows">The amount of rows</param>
        /// <returns></returns>
        public XTextTable AddTable(int col, int rows)
        {
            var Table = this.xMcFactory.createInstanceWithContext(OO.Services.TEXT_TEXT_TABLE, xContext);

            if (Table != null)
            {
                if (Table is XTextTable)
                {
                    ((XTextTable)Table).initialize(rows, col);
                }
                XTextRange xTextRange = Text.getEnd();
                Text.insertTextContent(xTextRange, Table as XTextContent, false);
            }
            return(Table as XTextTable);
        }
コード例 #5
0
        public XTextFrame AddTextFrame(int height, int width)
        {
            var textFrame = this.xMcFactory.createInstanceWithContext(OO.Services.TEXT_FRAME, xContext);

            if (textFrame != null)
            {
                if (textFrame is XTextFrame)
                {
                    Size size = OoUtils.MakeSize(width, height);
                    OoUtils.SetProperty(textFrame, "Size", size);
                    OoUtils.SetProperty(textFrame, "AnchorType", TextContentAnchorType.AS_CHARACTER);
                    OoUtils.SetProperty(textFrame, "LeftMargin", 0);
                    //util.Debug.GetAllProperties(textFrame);
                    XTextRange xTextRange = Text.getEnd();
                    NewParagraph();
                    Text.insertTextContent(xTextRange, textFrame as XTextFrame, false);
                    NewParagraph();
                }
            }
            return(textFrame as XTextFrame);
        }
コード例 #6
0
        private void registerListener(XTextRange tr)
        {
            //if (tr != null)
            //{
            //    //starterCursor
            //    var start = WriterDoc.CreateTextCursor(tr.getStart());

            //    //endCursor
            //    var end = WriterDoc.CreateTextCursor(tr.getEnd());

            //    //Debug.GetAllInterfacesOfObject(start);
            //    //Debug.GetAllProperties(start);


            //    /* XPropertySet:
            //     * addPropertyChangeListener
            //     * addVetoableChangeListener
            //    */

            //    ((XPropertySet)start).addPropertyChangeListener("", new TextRangeListener());

            //}
        }
コード例 #7
0
 public XTextCursor setXTextRange(XTextRange start, XTextRange end)
 {
     return(setXTextRange(CreateTextCursor(), start, end));
 }
コード例 #8
0
 /// <summary>
 /// Creates the text cursor.
 /// NOTE: You can have many non-visible Text Cursors as you want but there is only ONE View Cursor per document.
 /// </summary>
 /// <param name="range">The range.</param>
 /// <returns></returns>
 public XTextCursor CreateTextCursor(XTextRange range)
 {
     return(Text != null?Text.createTextCursorByRange(range) : null);
 }
コード例 #9
0
        /// <summary>
        /// Inserts a bookmark.
        /// </summary>
        /// <param name="xTextRange">The text range the bookmark should stand for.</param>
        /// <param name="sBookName">Name of the bookmark.</param>
        public void InsertBookmark(XTextRange xTextRange, String sBookName)
        {
            if (xTextRange == null)
                return;
            if (sBookName.Equals(""))
                sBookName = FunctionHelper.GetUniqueFrameName() + "_" + DateTime.Now;

            // create a bookmark on a TextRange
            try
            {
                // the bookmark service is a context depended service, you need
                // the MultiServiceFactory from the document
                Object xObject = xMcFactory.createInstanceWithContext(OO.Services.TEXT_BOOKMARK, this.xContext);

                // set the name from the bookmark
                XNamed xNameAccess = xObject as XNamed;

                if (xNameAccess != null)
                {
                    xNameAccess.setName(sBookName);

                    // create a XTextContent, for the method 'insertTextContent'
                    XTextContent xTextContent = (XTextContent)xNameAccess;

                    // insertTextContent need a TextRange not a cursor to specify the
                    // position from the bookmark
                    ((XTextDocument)Document).getText().insertTextContent(xTextRange, xTextContent, true);

                    System.Diagnostics.Debug.WriteLine("Insert bookmark: " + sBookName);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("ERROR: Insert bookmark faild because no MultiServiceFactory was created!");
                }



            }
            catch (unoidl.com.sun.star.uno.Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error while insering bookmark '" + sBookName + "':\n" + e);
            }
        }
コード例 #10
0
 public XTextCursor setXTextRange(XTextCursor xTextCursor, XTextRange start, XTextRange end)
 {
     if (xTextCursor != null && start != null && end != null)
     {
         xTextCursor.gotoRange(start.getStart(), false);
         xTextCursor.gotoRange(end.getEnd(), true);
     }
     return xTextCursor;
 }
コード例 #11
0
 public XTextCursor setXTextRange(XTextRange start, XTextRange end)
 {
     return setXTextRange(CreateTextCursor(), start, end);
 }
コード例 #12
0
 private XTextRange getTextRange(XTextRange from, XTextRange to)
 {
     if (from != null && to != null)
     {
         return setXTextRange(from, to);
     }
     return null;
 }
コード例 #13
0
 /// <summary>
 /// Creates the text cursor.
 /// NOTE: You can have many non-visible Text Cursors as you want but there is only ONE View Cursor per document.
 /// </summary>
 /// <param name="range">The range.</param>
 /// <returns></returns>
 public XTextCursor CreateTextCursor(XTextRange range)
 {
     return Text != null ? Text.createTextCursorByRange(range) : null;
 }
コード例 #14
0
 private void TestTextRangeEqualsText(XTextRange textRange, String text)
 {
     //if (!text.Equals(textRange.getString()))
     //    System.Diagnostics.Debug.WriteLine("WARNING: TextRange does not equals text");
 }
コード例 #15
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();
        }