示例#1
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);
     }
 }
示例#2
0
        private bool VerifyRedirectParameter(ref XTextGraphicObjectsSupplier comp, string imageName)
        {
            logger.Debug("VerifyRedirectParameter");
            // Get old image
            Object       xImageObject = comp.getGraphicObjects().getByName(imageName).Value;
            XTextContent xImage       = (XTextContent)xImageObject;

            // Get property set object of the existing image (XContent)
            //  We will use this property set object to set the new Graphic property of the old image
            // to be the new image stream
            XPropertySet xPropSet = (XPropertySet)xImage;
            // Get XMCF to create a graphic provider component
            XMultiComponentFactory xMCF = localContext.getServiceManager();

            // Assign the new graphic image to existent page object
            //xPropSet.setPropertyValue("Graphic", new uno.Any(typeof(UNOIDL.graphic.XGraphic), xNewGraphic));
            //var crop = (UNOIDL.container.XIndexContainer) xPropSet.getPropertyValue("ImageMap").Value;
            var  size        = (Size)xPropSet.getPropertyValue("ActualSize").Value;
            var  url         = xPropSet.getPropertyValue("GraphicURL").Value as string;
            bool elementFind = false;

            if (ConfigurationManager.AppSettings["RedirectSizeFilter"] != null && size != null)
            {
                var sizeFilter      = ConfigurationManager.AppSettings["RedirectSizeFilter"].ToString().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                var arrOfSizeFilter = sizeFilter.Select(p => new { Width = int.Parse(p.Split(',')[0]), Height = int.Parse(p.Split(',')[1]) });
                if (arrOfSizeFilter.Count() > 0)
                {
                    elementFind = arrOfSizeFilter.Any(x => x.Width == size.Width && x.Height == size.Height);
                }
            }
            if (ConfigurationManager.AppSettings["RedirectUrlFilter"] != null && size != null)
            {
                var urlFilter = ConfigurationManager.AppSettings["RedirectUrlFilter"].ToString().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (urlFilter.Count() > 0)
                {
                    elementFind = urlFilter.Contains(url);
                }
            }
            return(elementFind);
        }
示例#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();
        }