예제 #1
1
        public static XComponent OpenFile(
            XComponentLoader XComponentLoader, string FileName, 
            bool Hidden, bool ReadOnly)
        {
            var FileProperties =
                new unoidl.com.sun.star.beans.PropertyValue[2];

            FileProperties[0] = new unoidl.com.sun.star.beans.PropertyValue()
                                    { Name = "Hidden", Value = new uno.Any(Hidden) };
            FileProperties[1] = new unoidl.com.sun.star.beans.PropertyValue()
                                    { Name = "ReadOnly", Value = new uno.Any(ReadOnly) };

            return XComponentLoader.loadComponentFromURL(
                PathConverter(FileName),"_blank", 0, FileProperties);
        }
        /// <summary>
        /// News the doc component.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <param name="xMsFactory"> </param>
        /// <param name="xContext"> </param>
        /// <returns></returns>
        public static XComponent OpenNewDocumentComponent(String docType, XComponentContext xContext = null, XMultiComponentFactory xMsFactory = null)
        {
            try
            {
                if (xContext == null)
                {
                    xContext = OO.GetContext();
                }

                if (xMsFactory == null)
                {
                    xMsFactory = OO.GetMultiComponentFactory(xContext);
                }

                var desktop = xMsFactory.createInstanceWithContext(OO.Services.FRAME_DESKTOP, xContext);
                var mxCompLoader = desktop as XComponentLoader;

                String loadUrl = OO.DocTypes.DOC_TYPE_BASE + docType;
                var loadProps = new unoidl.com.sun.star.beans.PropertyValue[0];
                if (mxCompLoader != null) 
                    return mxCompLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Desktop to XComponentLoader cast Exeption: " + ex);
            }
            return null;
        }
예제 #3
0
        /// <summary>
        /// 初始化一个文档
        /// </summary>
        /// <returns>该文档的XSpreadsheetDocument接口</returns>
        private unoidl.com.sun.star.sheet.XSpreadsheetDocument initDocument(string filepath, bool IsHidden)
        {
            XComponentLoader aLoader = (XComponentLoader)
                                       mxMSFactory.createInstance("com.sun.star.frame.Desktop");
            XComponent xComponent = null;

            unoidl.com.sun.star.beans.PropertyValue[] myArgs = new unoidl.com.sun.star.beans.PropertyValue[1];
            myArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            myArgs[0].Name  = "Hidden";
            myArgs[0].Value = new uno.Any(IsHidden);
            if (filepath == "")
            {
                xComponent = aLoader.loadComponentFromURL(
                    "private:factory/scalc", "_blank", 0,
                    myArgs);
            }
            else
            {
                xComponent = aLoader.loadComponentFromURL(
                    this.PathConverter(filepath), "_blank", 0,
                    myArgs);
            }

            return((unoidl.com.sun.star.sheet.XSpreadsheetDocument)xComponent);
        }
예제 #4
0
        /// <summary>
        /// News the doc component.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <param name="xMsFactory"> </param>
        /// <param name="xContext"> </param>
        /// <returns></returns>
        public static XComponent OpenNewDocumentComponent(String docType, XComponentContext xContext = null, XMultiComponentFactory xMsFactory = null)
        {
            try
            {
                if (xContext == null)
                {
                    xContext = OO.GetContext();
                }

                if (xMsFactory == null)
                {
                    xMsFactory = OO.GetMultiComponentFactory(xContext);
                }

                var desktop      = xMsFactory.createInstanceWithContext(OO.Services.FRAME_DESKTOP, xContext);
                var mxCompLoader = desktop as XComponentLoader;

                String loadUrl   = OO.DocTypes.DOC_TYPE_BASE + docType;
                var    loadProps = new unoidl.com.sun.star.beans.PropertyValue[0];
                if (mxCompLoader != null)
                {
                    return(mxCompLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps));
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Desktop to XComponentLoader cast Exeption: " + ex);
            }
            return(null);
        }
예제 #5
0
        /// <summary>
        /// Converts input document (ex. MyDocument.docx) to output pdf
        /// Requires full path to document (ex. C:\Documents\MyDocument.docx)
        /// </summary>
        /// <param name="from">input document</param>
        /// <param name="toPdf">output pdf file</param>
        public static void Convert(string from, string toPdf)
        {
            if (!File.Exists(from))
            {
                throw new FileNotFoundException("Can't find input file", from);
            }
            var pv = new unoidl.com.sun.star.beans.PropertyValue[1];

            pv[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            pv[0].Name  = "Hidden";
            pv[0].Value = new uno.Any(true);
            lock (sync)
            {
                XComponent xComponent;
                try
                {
                    xComponent = Loader.loadComponentFromURL("file:///" + from.Replace('\\', '/'), "_blank", 0, pv);
                }
                catch (DisposedException)
                {
                    Init();
                    xComponent = Loader.loadComponentFromURL("file:///" + from.Replace('\\', '/'), "_blank", 0, pv);
                }
                var xStorable = (XStorable)xComponent;
                pv[0].Name = "FilterName";
                switch (Path.GetExtension(from).ToLowerInvariant())
                {
                case ".xls":
                case ".xlsx":
                case ".ods":
                    pv[0].Value = new uno.Any("calc_pdf_Export");
                    break;

                default:
                    pv[0].Value = new uno.Any("writer_pdf_Export");
                    break;
                }
                xStorable.storeToURL("file:///" + toPdf.Replace('\\', '/'), pv);
                var xClosable = (XCloseable)xComponent;
                xClosable.close(true);
            }
        }
        /// <summary>
        /// News the doc component.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <returns></returns>
        public XComponent NewDocComponent(String docType)
        {
            var desktop = ((XMultiComponentFactory)mxMSFactory).createInstanceWithContext(
                OO.Services.FRAME_DESKTOP, m_xContext);

            try
            {
                XComponentLoader mxCompLoader = desktop as XComponentLoader;

                String loadUrl = OO.DocTypes.DOC_TYPE_BASE + docType;
                unoidl.com.sun.star.beans.PropertyValue[] loadProps = new unoidl.com.sun.star.beans.PropertyValue[0];
                return(mxCompLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps));
            }
            catch (System.Exception ex)
            {
                //TOD: check this and handle if possible
                System.Diagnostics.Debug.WriteLine("Desktop to XComponentLoader cast Exception: " + ex);
            }
            return(null);
        }
예제 #7
0
        public void InsertGraphic(string imgpath)
        {
            Object            dispatchHelper    = mxMSFactory.createInstance("com.sun.star.frame.DispatchHelper");
            XDispatchHelper   dispatcher        = dispatchHelper as XDispatchHelper;
            XModel            xModel            = mxDocument as XModel;
            XFrame            xFrame            = xModel.getCurrentController().getFrame();
            XDispatchProvider xDispatchProvider = xFrame as XDispatchProvider;

            unoidl.com.sun.star.beans.PropertyValue[] MyProp = new unoidl.com.sun.star.beans.PropertyValue[4];
            MyProp[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[0].Name  = "FileName";
            MyProp[0].Value = new uno.Any(PathConverter(imgpath));
            MyProp[1]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[1].Name  = "FilterName";
            MyProp[1].Value = new uno.Any("<Tous les formats>");
            MyProp[2]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[2].Name  = "AsLink";
            MyProp[2].Value = new uno.Any(false);
            MyProp[3]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[3].Name  = "Style";
            MyProp[3].Value = new uno.Any("Image");
            dispatcher.executeDispatch(xDispatchProvider, ".uno:InsertGraphic", "", 0, MyProp);
        }
예제 #8
0
        /// <summary>
        /// Converts the file to a PDF file
        /// </summary>
        /// <param name="filePath">The full path of the file to be converted</param>
        public void ConvertToPdf(string filePath)
        {
            string           pdfExt         = FileExtension.PDF;
            FileCustom       fileCustom     = FileHelper.GetFileInfo(filePath);
            var              xLocalContext  = uno.util.Bootstrap.bootstrap();
            var              xRemoteFactory = (XMultiServiceFactory)xLocalContext.getServiceManager();
            XComponentLoader loader         = (XComponentLoader)xRemoteFactory.createInstance(LibreOfficeProperties.FRAME_DESKTOP);
            var              pv             = new unoidl.com.sun.star.beans.PropertyValue[1];

            pv[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            pv[0].Name  = LibreOfficeProperties.HIDDEN;
            pv[0].Value = new uno.Any(true);
            XComponent xComponent;

            xComponent = loader.loadComponentFromURL("file:///" + filePath.Replace('\\', '/'), LibreOfficeProperties.BLANK, 0, pv);
            var xStorable = (XStorable)xComponent;

            pv[0].Name = LibreOfficeProperties.FILTER_NAME;
            switch (fileCustom.Extension.ToLowerInvariant())
            {
            case FileExtension.XLS:
            case FileExtension.XLSX:
            case FileExtension.ODS:
                pv[0].Value = new uno.Any(LibreOfficeProperties.CALC_PDF_EXPORT);
                break;

            default:
                pv[0].Value = new uno.Any(LibreOfficeProperties.WRITER_PDF_EXPORT);
                break;
            }

            xStorable.storeToURL("file:///" + (fileCustom.Directory + @"\" + fileCustom.Name + pdfExt).Replace('\\', '/'), pv);
            var xClosable = (XCloseable)xComponent;

            xClosable.close(true);
        }
예제 #9
0
        public void CozdSchetWriter(string push, int ID)
        {
            DB5  db   = new DB5(kursach.Program.Pole.pole);
            DB16 db2  = new DB16(kursach.Program.Pole.pole);
            DB1  db1  = new DB1(kursach.Program.Pole.pole);
            DB14 db14 = new DB14(kursach.Program.Pole.pole);
            DB13 db13 = new DB13(kursach.Program.Pole.pole);

            Mapping.DB17 db17 = new Mapping.DB17(kursach.Program.Pole.pole);
            var          ec   = from n in db.JurnalRabot
                                where n.ID == Convert.ToInt32(ID)
                                select n;
            int temp = 0;

            foreach (var i in ec)
            {
                temp = i.IDZapisi;
            }
            var ec2 = from n in db2.Zapis
                      where n.ID == temp
                      select n;
            var Firma = from n in db17.Firma
                        where n.ID == 1
                        select n;
            string temp2 = "";

            foreach (var i in ec2)
            {
                temp2 = i.Data;
            }
            unoidl.com.sun.star.uno.XComponentContext     localContext        = uno.util.Bootstrap.bootstrap();
            unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager();
            XComponentLoader componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
            XComponent       xComponent      = componentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);

            ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().setString("Счет №" + ID + Environment.NewLine);

            unoidl.com.sun.star.text.XTextRange x = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().getEnd();  // в конец
            ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().insertString(x, "от " + temp2 + "г." + Environment.NewLine + Environment.NewLine + Environment.NewLine, true);
            unoidl.com.sun.star.text.XTextRange xi = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().getEnd(); // в конец
            foreach (var i in Firma)
            {
                ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().insertString(xi, "ИНН " + i.INN + " КПП " + i.KPP + Environment.NewLine + "Получатель " + i.Name + " № Счета " + i.Schet + Environment.NewLine + "Банк получателя " + i.Bank + " № Счета банка " + i.SchetBank + Environment.NewLine, true);
            }

            DB11 db11       = new DB11(kursach.Program.Pole.pole);
            var  Raspisanie = from n in db11.Raspisanie
                              where n.ID == temp
                              select n;

            foreach (var i in Raspisanie)
            {
                temp = i.IDVrach;
            }
            var Vrach = from n in db14.Vrach
                        where n.ID == temp
                        select n;

            foreach (var i in Vrach)
            {
                temp2 = i.FIO;
            }
            unoidl.com.sun.star.text.XTextRange x2 = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().getEnd();  // в конец
            ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().insertString(x2, "Исполнитель: " + temp2 + Environment.NewLine, true);

            foreach (var i in ec2)
            {
                temp = i.IDPacienta;
            }
            var ec3 = from n in db1.Pacient
                      where n.ID == temp
                      select n;

            foreach (var i in ec3)
            {
                temp2 = i.FIO;
            }
            unoidl.com.sun.star.text.XTextRange x3 = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().getEnd();  // в конец
            ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().insertString(x3, "Заказчик: " + temp2 + Environment.NewLine + Environment.NewLine + Environment.NewLine, true);

            //Таблица
            XFrame          frame           = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getCurrentController().getFrame();
            XDispatchHelper xDispatchHelper = (XDispatchHelper)multiServiceFactory.createInstance("com.sun.star.frame.DispatchHelper");

            unoidl.com.sun.star.beans.PropertyValue[] tableArgs = new unoidl.com.sun.star.beans.PropertyValue[4];
            tableArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            tableArgs[1]       = new unoidl.com.sun.star.beans.PropertyValue();
            tableArgs[2]       = new unoidl.com.sun.star.beans.PropertyValue();
            tableArgs[3]       = new unoidl.com.sun.star.beans.PropertyValue();
            tableArgs[0].Name  = "TableName";
            tableArgs[0].Value = new uno.Any("Акт");
            tableArgs[1].Name  = "Columns";
            tableArgs[1].Value = new uno.Any(4);
            tableArgs[2].Name  = "Rows";
            tableArgs[2].Value = new uno.Any(2);
            tableArgs[3].Name  = "Flags";
            tableArgs[3].Value = new uno.Any(9);
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any("Наименование Услуги");
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertTable", "", 0, tableArgs);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs2 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any("Цена");
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs2);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs3 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any("Скидка");
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs3);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs4 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any("Итого");
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs4);

            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            foreach (var i in ec2)
            {
                temp = i.IDUslugi;
            }
            var ec5 = from n in db13.Uslugi
                      where n.ID == temp
                      select n;

            foreach (var i in ec5)
            {
                temp2 = i.Name;
            }
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs5 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any(temp2);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs5);

            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            foreach (var i in ec)
            {
                temp2 = i.Cena.ToString();
            }
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs6 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any(temp2);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs6);

            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            foreach (var i in ec)
            {
                temp2 = i.Skidka.ToString();
            }
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs7 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any(temp2);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs7);

            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);
            foreach (var i in ec)
            {
                temp2 = i.Itog.ToString();
            }
            unoidl.com.sun.star.beans.PropertyValue[] cellTextArgs8 =
                new unoidl.com.sun.star.beans.PropertyValue[1];
            cellTextArgs[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            cellTextArgs[0].Name  = "Text";
            cellTextArgs[0].Value = new uno.Any(temp2);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs8);

            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:JumpToNextCell", "", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
            xDispatchHelper.executeDispatch((XDispatchProvider)frame, ".uno:InsertText", "", 0, cellTextArgs);

            unoidl.com.sun.star.text.XTextRange x4 = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().getEnd();  // в конец
            ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().insertString(x4, "Всего оказано услуг на сумму: " + temp2 + "рублей " + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine, true);
            string temp3 = "";

            foreach (var i in Vrach)
            {
                temp2 = i.FIO;
            }
            foreach (var i in ec3)
            {
                temp3 = i.FIO;
            }
            unoidl.com.sun.star.text.XTextRange x5 = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().getEnd();  // в конец
            foreach (var i in Firma)
            {
                ((unoidl.com.sun.star.text.XTextDocument)xComponent).getText().insertString(x5, "Исполнитель:__________________ " + temp2 + Environment.NewLine + "Бухгалтер:__________________" + i.Buh, true);
            }
            ((XStorable)xComponent).storeToURL(@"file:///" + push.Replace(@"\", "/"), new unoidl.com.sun.star.beans.PropertyValue[0]);
            xComponent.dispose();
        }
    // ________________________________________________________________
    /** All samples regarding the formatting of cells and ranges. */
    private void doFormattingSamples()
    {
        Console.WriteLine( "\n*** Formatting samples ***\n" );
        unoidl.com.sun.star.sheet.XSpreadsheet xSheet = getSpreadsheet( 1 );
        unoidl.com.sun.star.table.XCellRange xCellRange;
        unoidl.com.sun.star.beans.XPropertySet xPropSet = null;
        unoidl.com.sun.star.container.XIndexAccess xRangeIA = null;
        unoidl.com.sun.star.lang.XMultiServiceFactory xServiceManager;

        // --- Cell styles ---
        // get the cell style container
        unoidl.com.sun.star.style.XStyleFamiliesSupplier xFamiliesSupplier =
            (unoidl.com.sun.star.style.XStyleFamiliesSupplier) getDocument();
        unoidl.com.sun.star.container.XNameAccess xFamiliesNA =
            xFamiliesSupplier.getStyleFamilies();
        uno.Any aCellStylesObj = xFamiliesNA.getByName( "CellStyles" );
        unoidl.com.sun.star.container.XNameContainer xCellStylesNA =
            (unoidl.com.sun.star.container.XNameContainer) aCellStylesObj.Value;

        // create a new cell style
        xServiceManager =
            (unoidl.com.sun.star.lang.XMultiServiceFactory) getDocument();
        Object aCellStyle = xServiceManager.createInstance(
            "com.sun.star.style.CellStyle" );
        String aStyleName = "MyNewCellStyle";
        xCellStylesNA.insertByName(
            aStyleName, new uno.Any( typeof (Object), aCellStyle ) );

        // modify properties of the new style
        xPropSet = (unoidl.com.sun.star.beans.XPropertySet) aCellStyle;
        xPropSet.setPropertyValue(
            "CellBackColor", new uno.Any( (Int32) 0x888888 ) );
        xPropSet.setPropertyValue(
            "IsCellBackgroundTransparent", new uno.Any( false ) );

        // --- Query equal-formatted cell ranges ---
        // prepare example, use the new cell style
        xCellRange = xSheet.getCellRangeByName( "D2:F2" );
        xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange;
        xPropSet.setPropertyValue( "CellStyle", new uno.Any( aStyleName ) );

        xCellRange = xSheet.getCellRangeByName( "A3:G3" );
        xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange;
        xPropSet.setPropertyValue( "CellStyle", new uno.Any( aStyleName ) );

        // All ranges in one container
        xCellRange = xSheet.getCellRangeByName( "A1:G3" );
        Console.WriteLine( "Service CellFormatRanges:" );
        unoidl.com.sun.star.sheet.XCellFormatRangesSupplier xFormatSupp =
            (unoidl.com.sun.star.sheet.XCellFormatRangesSupplier) xCellRange;
        xRangeIA = xFormatSupp.getCellFormatRanges();
        Console.WriteLine( getCellRangeListString( xRangeIA ) );

        // Ranges sorted in SheetCellRanges containers
        Console.WriteLine( "\nService UniqueCellFormatRanges:" );
        unoidl.com.sun.star.sheet.XUniqueCellFormatRangesSupplier
            xUniqueFormatSupp =
            (unoidl.com.sun.star.sheet.XUniqueCellFormatRangesSupplier)
              xCellRange;
        unoidl.com.sun.star.container.XIndexAccess xRangesIA =
            xUniqueFormatSupp.getUniqueCellFormatRanges();
        int nCount = xRangesIA.getCount();
        for (int nIndex = 0; nIndex < nCount; ++nIndex)
        {
            uno.Any aRangesObj = xRangesIA.getByIndex( nIndex );
            xRangeIA =
                (unoidl.com.sun.star.container.XIndexAccess) aRangesObj.Value;
            Console.WriteLine(
                "Container " + (nIndex + 1) + ": " +
                getCellRangeListString( xRangeIA ) );
        }

        // --- Table auto formats ---
        // get the global collection of table auto formats,
        // use global service manager
        xServiceManager = getServiceManager();
        Object aAutoFormatsObj = xServiceManager.createInstance(
            "com.sun.star.sheet.TableAutoFormats" );
        unoidl.com.sun.star.container.XNameContainer xAutoFormatsNA =
            (unoidl.com.sun.star.container.XNameContainer) aAutoFormatsObj;

        // create a new table auto format and insert into the container
        String aAutoFormatName =  "Temp_Example";
        bool bExistsAlready = xAutoFormatsNA.hasByName( aAutoFormatName );
        uno.Any aAutoFormatObj;
        if (bExistsAlready)
            // auto format already exists -> use it
            aAutoFormatObj = xAutoFormatsNA.getByName( aAutoFormatName );
        else
        {
            // create a new auto format (with document service manager!)
            xServiceManager =
                (unoidl.com.sun.star.lang.XMultiServiceFactory) getDocument();
            aAutoFormatObj = new uno.Any(
                typeof (Object),
                xServiceManager.createInstance(
                    "com.sun.star.sheet.TableAutoFormat" ) );
            xAutoFormatsNA.insertByName( aAutoFormatName, aAutoFormatObj );
        }
        // index access to the auto format fields
        unoidl.com.sun.star.container.XIndexAccess xAutoFormatIA =
            (unoidl.com.sun.star.container.XIndexAccess) aAutoFormatObj.Value;

        // set properties of all auto format fields
        for (int nRow = 0; nRow < 4; ++nRow)
        {
            int nRowColor = 0;
            switch (nRow)
            {
                case 0:     nRowColor = 0x999999;   break;
                case 1:     nRowColor = 0xFFFFCC;   break;
                case 2:     nRowColor = 0xEEEEEE;   break;
                case 3:     nRowColor = 0x999999;   break;
            }

            for (int nColumn = 0; nColumn < 4; ++nColumn)
            {
                int nColor = nRowColor;
                if ((nColumn == 0) || (nColumn == 3))
                    nColor -= 0x333300;

                // get the auto format field and apply properties
                uno.Any aFieldObj = xAutoFormatIA.getByIndex(
                    4 * nRow + nColumn );
                xPropSet =
                    (unoidl.com.sun.star.beans.XPropertySet) aFieldObj.Value;
                xPropSet.setPropertyValue(
                    "CellBackColor", new uno.Any( (Int32) nColor ) );
            }
        }

        // set the auto format to the spreadsheet
        xCellRange = xSheet.getCellRangeByName( "A5:H25" );
        unoidl.com.sun.star.table.XAutoFormattable xAutoForm =
            (unoidl.com.sun.star.table.XAutoFormattable) xCellRange;
        xAutoForm.autoFormat( aAutoFormatName );

        // remove the auto format
        if (!bExistsAlready)
            xAutoFormatsNA.removeByName( aAutoFormatName );

        // --- Conditional formats ---
        xSheet = getSpreadsheet( 0 );
        prepareRange( xSheet, "K20:K23", "Cond. Format" );
        setValue( xSheet, "K21", 1 );
        setValue( xSheet, "K22", 2 );
        setValue( xSheet, "K23", 3 );

        // get the conditional format object of the cell range
        xCellRange = xSheet.getCellRangeByName( "K21:K23" );
        xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange;
        unoidl.com.sun.star.sheet.XSheetConditionalEntries xEntries =
            (unoidl.com.sun.star.sheet.XSheetConditionalEntries)
              xPropSet.getPropertyValue( "ConditionalFormat" ).Value;

        // create a condition and apply it to the range
        unoidl.com.sun.star.beans.PropertyValue[] aCondition =
            new unoidl.com.sun.star.beans.PropertyValue[3];
        aCondition[0] = new unoidl.com.sun.star.beans.PropertyValue();
        aCondition[0].Name  = "Operator";
        aCondition[0].Value =
            new uno.Any(
                typeof (unoidl.com.sun.star.sheet.ConditionOperator),
                unoidl.com.sun.star.sheet.ConditionOperator.GREATER );
        aCondition[1] = new unoidl.com.sun.star.beans.PropertyValue();
        aCondition[1].Name  = "Formula1";
        aCondition[1].Value = new uno.Any( "1" );
        aCondition[2] = new unoidl.com.sun.star.beans.PropertyValue();
        aCondition[2].Name  = "StyleName";
        aCondition[2].Value = new uno.Any( aStyleName );
        xEntries.addNew( aCondition );
        xPropSet.setPropertyValue(
            "ConditionalFormat",
            new uno.Any(
                typeof (unoidl.com.sun.star.sheet.XSheetConditionalEntries),
                xEntries ) );
    }
    private void doDatabaseSamples()
    {
        Console.WriteLine( "\n*** Samples for database operations ***\n" );
        unoidl.com.sun.star.sheet.XSpreadsheet xSheet = getSpreadsheet( 2 );

        // --- put some example data into the sheet ---
        unoidl.com.sun.star.table.XCellRange xRange =
            xSheet.getCellRangeByName( "B3:D24" );
        unoidl.com.sun.star.sheet.XCellRangeData xData =
            (unoidl.com.sun.star.sheet.XCellRangeData) xRange;
        uno.Any [][] aValues =
        {
            new uno.Any [] { new uno.Any( "Name" ),
                             new uno.Any( "Year" ),
                             new uno.Any( "Sales" ) },
            new uno.Any [] { new uno.Any( "Alice" ),
                             new uno.Any( (Double) 2001 ),
                             new uno.Any( (Double) 4.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
                             new uno.Any( (Double) 1997 ),
                             new uno.Any( (Double) 3.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
                             new uno.Any( (Double) 1998 ),
                             new uno.Any( (Double) 8.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
                             new uno.Any( (Double) 1997 ),
                             new uno.Any( (Double) 8.0 ) },
            new uno.Any [] { new uno.Any( "Alice" ),
                             new uno.Any( (Double) 2002 ),
                             new uno.Any( (Double) 9.0 ) },
            new uno.Any [] { new uno.Any( "Alice" ),
                             new uno.Any( (Double) 1999 ),
                             new uno.Any( (Double) 7.0 ) },
            new uno.Any [] { new uno.Any( "Alice" ),
                             new uno.Any( (Double) 1996 ),
                             new uno.Any( (Double) 3.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
                             new uno.Any( (Double) 2000 ),
                             new uno.Any( (Double) 1.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
                             new uno.Any( (Double) 1999 ),
                             new uno.Any( (Double) 5.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
                             new uno.Any( (Double) 2002 ),
                             new uno.Any( (Double) 1.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
              new uno.Any( (Double) 2001 ),
              new uno.Any( (Double) 5.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
              new uno.Any( (Double) 2000 ),
              new uno.Any( (Double) 1.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
              new uno.Any( (Double) 1996 ),
              new uno.Any( (Double) 8.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
              new uno.Any( (Double) 1996 ),
              new uno.Any( (Double) 7.0 ) },
            new uno.Any [] { new uno.Any( "Alice" ),
              new uno.Any( (Double) 1997 ),
              new uno.Any( (Double) 3.0 ) },
            new uno.Any [] { new uno.Any( "Alice" ),
              new uno.Any( (Double) 2000 ),
              new uno.Any( (Double) 9.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
              new uno.Any( (Double) 1998 ),
              new uno.Any( (Double) 1.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
              new uno.Any( (Double) 1999 ),
              new uno.Any( (Double) 6.0 ) },
            new uno.Any [] { new uno.Any( "Carol" ),
              new uno.Any( (Double) 2002 ),
              new uno.Any( (Double) 8.0 ) },
            new uno.Any [] { new uno.Any( "Alice" ),
              new uno.Any( (Double) 1998 ),
              new uno.Any( (Double) 5.0 ) },
            new uno.Any [] { new uno.Any( "Bob" ),
              new uno.Any( (Double) 2001 ),
              new uno.Any( (Double) 6.0 ) }
        };
        xData.setDataArray( aValues );

        // --- filter for second column >= 1998 ---
        unoidl.com.sun.star.sheet.XSheetFilterable xFilter =
            (unoidl.com.sun.star.sheet.XSheetFilterable) xRange;
        unoidl.com.sun.star.sheet.XSheetFilterDescriptor xFilterDesc =
            xFilter.createFilterDescriptor( true );
        unoidl.com.sun.star.sheet.TableFilterField[] aFilterFields =
            new unoidl.com.sun.star.sheet.TableFilterField[1];
        aFilterFields[0] = new unoidl.com.sun.star.sheet.TableFilterField();
        aFilterFields[0].Field        = 1;
        aFilterFields[0].IsNumeric    = true;
        aFilterFields[0].Operator =
            unoidl.com.sun.star.sheet.FilterOperator.GREATER_EQUAL;
        aFilterFields[0].NumericValue = 1998;
        xFilterDesc.setFilterFields( aFilterFields );
        unoidl.com.sun.star.beans.XPropertySet xFilterProp =
            (unoidl.com.sun.star.beans.XPropertySet) xFilterDesc;
        xFilterProp.setPropertyValue(
            "ContainsHeader", new uno.Any( true ) );
        xFilter.filter( xFilterDesc );

        // --- do the same filter as above, using criteria from a cell range ---
        unoidl.com.sun.star.table.XCellRange xCritRange =
            xSheet.getCellRangeByName( "B27:B28" );
        unoidl.com.sun.star.sheet.XCellRangeData xCritData =
            (unoidl.com.sun.star.sheet.XCellRangeData) xCritRange;
        uno.Any [][] aCritValues =
        {
            new uno.Any [] { new uno.Any( "Year" ) },
            new uno.Any [] { new uno.Any( ">= 1998" ) }
        };
        xCritData.setDataArray( aCritValues );
        unoidl.com.sun.star.sheet.XSheetFilterableEx xCriteria =
            (unoidl.com.sun.star.sheet.XSheetFilterableEx) xCritRange;
        xFilterDesc = xCriteria.createFilterDescriptorByObject( xFilter );
        if ( xFilterDesc != null )
            xFilter.filter( xFilterDesc );

        // --- sort by second column, ascending ---
        unoidl.com.sun.star.util.SortField[] aSortFields =
            new unoidl.com.sun.star.util.SortField[1];
        aSortFields[0] = new unoidl.com.sun.star.util.SortField();
        aSortFields[0].Field         = 1;
        aSortFields[0].SortAscending = true;

        unoidl.com.sun.star.beans.PropertyValue[] aSortDesc =
            new unoidl.com.sun.star.beans.PropertyValue[2];
        aSortDesc[0] = new unoidl.com.sun.star.beans.PropertyValue();
        aSortDesc[0].Name   = "SortFields";
        aSortDesc[0].Value  =
            new uno.Any(
                typeof (unoidl.com.sun.star.util.SortField []),
                aSortFields );
        aSortDesc[1] = new unoidl.com.sun.star.beans.PropertyValue();
        aSortDesc[1].Name   = "ContainsHeader";
        aSortDesc[1].Value  = new uno.Any( true );

        unoidl.com.sun.star.util.XSortable xSort =
            (unoidl.com.sun.star.util.XSortable) xRange;
        xSort.sort( aSortDesc );

        // --- insert subtotals ---
        unoidl.com.sun.star.sheet.XSubTotalCalculatable xSub =
            (unoidl.com.sun.star.sheet.XSubTotalCalculatable) xRange;
        unoidl.com.sun.star.sheet.XSubTotalDescriptor xSubDesc =
            xSub.createSubTotalDescriptor( true );
        unoidl.com.sun.star.sheet.SubTotalColumn[] aColumns =
            new unoidl.com.sun.star.sheet.SubTotalColumn[1];
        // calculate sum of third column
        aColumns[0] = new unoidl.com.sun.star.sheet.SubTotalColumn();
        aColumns[0].Column   = 2;
        aColumns[0].Function = unoidl.com.sun.star.sheet.GeneralFunction.SUM;
        // group by first column
        xSubDesc.addNew( aColumns, 0 );
        xSub.applySubTotals( xSubDesc, true );

        String aDatabase = getFirstDatabaseName();
        String aTableName = getFirstTableName( aDatabase );
        if ( aDatabase != null && aTableName != null )
        {
            // --- import from database ---
            unoidl.com.sun.star.beans.PropertyValue[] aImportDesc =
                new unoidl.com.sun.star.beans.PropertyValue[3];
            aImportDesc[0] = new unoidl.com.sun.star.beans.PropertyValue();
            aImportDesc[0].Name     = "DatabaseName";
            aImportDesc[0].Value    = new uno.Any( aDatabase );
            aImportDesc[1] = new unoidl.com.sun.star.beans.PropertyValue();
            aImportDesc[1].Name     = "SourceType";
            aImportDesc[1].Value    =
                new uno.Any(
                    typeof (unoidl.com.sun.star.sheet.DataImportMode),
                    unoidl.com.sun.star.sheet.DataImportMode.TABLE );
            aImportDesc[2] = new unoidl.com.sun.star.beans.PropertyValue();
            aImportDesc[2].Name     = "SourceObject";
            aImportDesc[2].Value    = new uno.Any( aTableName );

            unoidl.com.sun.star.table.XCellRange xImportRange =
                xSheet.getCellRangeByName( "B35:B35" );
            unoidl.com.sun.star.util.XImportable xImport =
                (unoidl.com.sun.star.util.XImportable) xImportRange;
            xImport.doImport( aImportDesc );

            // --- use the temporary database range to find the
            // imported data's size ---
            unoidl.com.sun.star.beans.XPropertySet xDocProp =
                (unoidl.com.sun.star.beans.XPropertySet) getDocument();
            uno.Any aRangesObj = xDocProp.getPropertyValue( "DatabaseRanges" );
            unoidl.com.sun.star.container.XNameAccess xRanges =
                (unoidl.com.sun.star.container.XNameAccess) aRangesObj.Value;
            String[] aNames = xRanges.getElementNames();
            for ( int i=0; i<aNames.Length; i++ )
            {
                uno.Any aRangeObj = xRanges.getByName( aNames[i] );
                unoidl.com.sun.star.beans.XPropertySet xRangeProp =
                    (unoidl.com.sun.star.beans.XPropertySet) aRangeObj.Value;
                bool bUser = (Boolean)
                    xRangeProp.getPropertyValue( "IsUserDefined" ).Value;
                if ( !bUser )
                {
                    // this is the temporary database range -
                    // get the cell range and format it
                    unoidl.com.sun.star.sheet.XCellRangeReferrer xRef =
                        (unoidl.com.sun.star.sheet.XCellRangeReferrer)
                          aRangeObj.Value;
                    unoidl.com.sun.star.table.XCellRange xResultRange =
                        xRef.getReferredCells();
                    unoidl.com.sun.star.beans.XPropertySet xResultProp =
                        (unoidl.com.sun.star.beans.XPropertySet) xResultRange;
                    xResultProp.setPropertyValue(
                        "IsCellBackgroundTransparent", new uno.Any( false ) );
                    xResultProp.setPropertyValue(
                        "CellBackColor", new uno.Any( (Int32) 0xFFFFCC ) );
                }
            }
        }
        else
            Console.WriteLine("can't get database");
    }
예제 #12
0
    // ________________________________________________________________
    /** This sample function performs all changes on the view. */
    public void doSampleFunction()
    {
        unoidl.com.sun.star.sheet.XSpreadsheetDocument xDoc = getDocument();
        unoidl.com.sun.star.frame.XModel xModel =
            (unoidl.com.sun.star.frame.XModel) xDoc;
        unoidl.com.sun.star.frame.XController xController =
            xModel.getCurrentController();

        // --- Spreadsheet view ---
        // freeze the first column and first two rows
        unoidl.com.sun.star.sheet.XViewFreezable xFreeze =
            (unoidl.com.sun.star.sheet.XViewFreezable) xController;
        if ( null != xFreeze )
            Console.WriteLine( "got xFreeze" );
        xFreeze.freezeAtPosition( 1, 2 );

        // --- View pane ---
        // get the cell range shown in the second pane and assign
        // a cell background to them
        unoidl.com.sun.star.container.XIndexAccess xIndex =
            (unoidl.com.sun.star.container.XIndexAccess) xController;
        uno.Any aPane = xIndex.getByIndex(1);
        unoidl.com.sun.star.sheet.XCellRangeReferrer xRefer =
            (unoidl.com.sun.star.sheet.XCellRangeReferrer) aPane.Value;
        unoidl.com.sun.star.table.XCellRange xRange = xRefer.getReferredCells();
        unoidl.com.sun.star.beans.XPropertySet xRangeProp =
            (unoidl.com.sun.star.beans.XPropertySet) xRange;
        xRangeProp.setPropertyValue(
            "IsCellBackgroundTransparent", new uno.Any( false ) );
        xRangeProp.setPropertyValue(
            "CellBackColor", new uno.Any( (Int32) 0xFFFFCC ) );

        // --- View settings ---
        // change the view to display green grid lines
        unoidl.com.sun.star.beans.XPropertySet xProp =
            (unoidl.com.sun.star.beans.XPropertySet) xController;
        xProp.setPropertyValue(
            "ShowGrid", new uno.Any( true ) );
        xProp.setPropertyValue(
            "GridColor", new uno.Any( (Int32) 0x00CC00 ) );

        // --- Range selection ---
        // let the user select a range and use it as the view's selection
        unoidl.com.sun.star.sheet.XRangeSelection xRngSel =
            (unoidl.com.sun.star.sheet.XRangeSelection) xController;
        ExampleRangeListener aListener = new ExampleRangeListener();
        xRngSel.addRangeSelectionListener( aListener );
        unoidl.com.sun.star.beans.PropertyValue[] aArguments =
            new unoidl.com.sun.star.beans.PropertyValue[2];
        aArguments[0] = new unoidl.com.sun.star.beans.PropertyValue();
        aArguments[0].Name   = "Title";
        aArguments[0].Value  = new uno.Any( "Please select a range" );
        aArguments[1] = new unoidl.com.sun.star.beans.PropertyValue();
        aArguments[1].Name   = "CloseOnMouseRelease";
        aArguments[1].Value  = new uno.Any( true );
        xRngSel.startRangeSelection( aArguments );
        Monitor.Enter( aListener );
        try
        {
            Monitor.Wait( aListener );       // wait until the selection is done
        }
        finally
        {
            Monitor.Exit( aListener );
        }
        xRngSel.removeRangeSelectionListener( aListener );
        if ( aListener.aResult != null && aListener.aResult.Length != 0 )
        {
            unoidl.com.sun.star.view.XSelectionSupplier xSel =
                (unoidl.com.sun.star.view.XSelectionSupplier) xController;
            unoidl.com.sun.star.sheet.XSpreadsheetView xView =
                (unoidl.com.sun.star.sheet.XSpreadsheetView) xController;
            unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
                xView.getActiveSheet();
            unoidl.com.sun.star.table.XCellRange xResultRange =
                xSheet.getCellRangeByName( aListener.aResult );
            xSel.select(
                new uno.Any(
                    typeof (unoidl.com.sun.star.table.XCellRange),
                    xResultRange ) );
        }
    }
예제 #13
0
        protected override void InternalConvert(string sourceFileName, string destinationFileName)
        {
            //Debug.WriteLine($"Start Convert: {Thread.CurrentThread.ManagedThreadId} - {sourceFileName} - {destinationFileName}");

            /*try
             * {*/
            if (!File.Exists(sourceFileName))
            {
                throw new FileNotFoundException("File not found", sourceFileName);
            }

            XComponentLoader loader = LOComponentLoader.Instance;

            XComponent component;

            {
                var pv = new unoidl.com.sun.star.beans.PropertyValue[1];
                pv[0] = new unoidl.com.sun.star.beans.PropertyValue()
                {
                    Name  = "Hidden",
                    Value = new uno.Any(true)
                };
                component = loader.loadComponentFromURL("file:///" +
                                                        Path.GetFullPath(sourceFileName).Replace('\\', '/'), "_blank", 0, pv);
            }

            try
            {
                //Debug.WriteLine($"File opened: {Thread.CurrentThread.ManagedThreadId} - {sourceFileName} - {destinationFileName}");

                string destinationFullPath  = Path.GetFullPath(destinationFileName);
                string destinationDirectory = Path.GetDirectoryName(destinationFullPath);

                if (!Directory.Exists(destinationDirectory))
                {
                    Directory.CreateDirectory(destinationDirectory);
                }

                var storable = (XStorable)component;

                var pv = new unoidl.com.sun.star.beans.PropertyValue[1];
                pv[0] = new unoidl.com.sun.star.beans.PropertyValue()
                {
                    Name  = "FilterName",
                    Value = new uno.Any(this.libreOfficeFilterName)
                };
                System.Exception saveException = null;

                Thread saveThread = new Thread(() =>
                {
                    try
                    {
                        storable.storeToURL("file:///" +
                                            Path.GetFullPath(destinationFileName).Replace('\\', '/'), pv);
                    }
                    catch (System.Exception e)
                    {
                        saveException = e;
                    }
                });
                saveThread.Start();

                if (!saveThread.Join(this.SaveTimeout))
                {
                    saveThread.Abort();
                    throw new TimeoutException("File save timeout.");
                }
                else if (saveException != null)
                {
                    throw saveException;
                }

                //Debug.WriteLine($"File saved: {Thread.CurrentThread.ManagedThreadId} - {sourceFileName} - {destinationFileName}");
            }
            finally
            {
                Thread closeThread = new Thread(() =>
                {
                    try
                    {
                        ((XCloseable)component).close(true);
                    }
                    catch
                    {
                    }
                });
                closeThread.Start();

                if (!closeThread.Join(this.CloseTimeout))
                {
                    closeThread.Abort();
                }

                //Debug.WriteLine($"File closed: {Thread.CurrentThread.ManagedThreadId} - {sourceFileName} - {destinationFileName}");
            }

            /*}
             * catch (System.Exception e)
             * {
             *  Debug.WriteLine($"File exception: {Thread.CurrentThread.ManagedThreadId} - {sourceFileName} - {destinationFileName}");
             *  File.WriteAllText(destinationFileName, e.Message + "\n" + e.StackTrace);
             * }*/
        }
예제 #14
0
    /** This sample function performs all changes on the view. */
    public void doSampleFunction()
    {
        unoidl.com.sun.star.sheet.XSpreadsheetDocument xDoc = getDocument();
        unoidl.com.sun.star.frame.XModel xModel             =
            (unoidl.com.sun.star.frame.XModel)xDoc;
        unoidl.com.sun.star.frame.XController xController =
            xModel.getCurrentController();

        // --- Spreadsheet view ---
        // freeze the first column and first two rows
        unoidl.com.sun.star.sheet.XViewFreezable xFreeze =
            (unoidl.com.sun.star.sheet.XViewFreezable)xController;
        if (null != xFreeze)
        {
            Console.WriteLine("got xFreeze");
        }
        xFreeze.freezeAtPosition(1, 2);

        // --- View pane ---
        // get the cell range shown in the second pane and assign
        // a cell background to them
        unoidl.com.sun.star.container.XIndexAccess xIndex =
            (unoidl.com.sun.star.container.XIndexAccess)xController;
        uno.Any aPane = xIndex.getByIndex(1);
        unoidl.com.sun.star.sheet.XCellRangeReferrer xRefer =
            (unoidl.com.sun.star.sheet.XCellRangeReferrer)aPane.Value;
        unoidl.com.sun.star.table.XCellRange   xRange     = xRefer.getReferredCells();
        unoidl.com.sun.star.beans.XPropertySet xRangeProp =
            (unoidl.com.sun.star.beans.XPropertySet)xRange;
        xRangeProp.setPropertyValue(
            "IsCellBackgroundTransparent", new uno.Any(false));
        xRangeProp.setPropertyValue(
            "CellBackColor", new uno.Any((Int32)0xFFFFCC));

        // --- View settings ---
        // change the view to display green grid lines
        unoidl.com.sun.star.beans.XPropertySet xProp =
            (unoidl.com.sun.star.beans.XPropertySet)xController;
        xProp.setPropertyValue(
            "ShowGrid", new uno.Any(true));
        xProp.setPropertyValue(
            "GridColor", new uno.Any((Int32)0x00CC00));

        // --- Range selection ---
        // let the user select a range and use it as the view's selection
        unoidl.com.sun.star.sheet.XRangeSelection xRngSel =
            (unoidl.com.sun.star.sheet.XRangeSelection)xController;
        ExampleRangeListener aListener = new ExampleRangeListener();

        xRngSel.addRangeSelectionListener(aListener);
        unoidl.com.sun.star.beans.PropertyValue[] aArguments =
            new unoidl.com.sun.star.beans.PropertyValue[2];
        aArguments[0]       = new unoidl.com.sun.star.beans.PropertyValue();
        aArguments[0].Name  = "Title";
        aArguments[0].Value = new uno.Any("Please select a range");
        aArguments[1]       = new unoidl.com.sun.star.beans.PropertyValue();
        aArguments[1].Name  = "CloseOnMouseRelease";
        aArguments[1].Value = new uno.Any(true);
        xRngSel.startRangeSelection(aArguments);
        Monitor.Enter(aListener);
        try
        {
            Monitor.Wait(aListener);         // wait until the selection is done
        }
        finally
        {
            Monitor.Exit(aListener);
        }
        xRngSel.removeRangeSelectionListener(aListener);
        if (aListener.aResult != null && aListener.aResult.Length != 0)
        {
            unoidl.com.sun.star.view.XSelectionSupplier xSel =
                (unoidl.com.sun.star.view.XSelectionSupplier)xController;
            unoidl.com.sun.star.sheet.XSpreadsheetView xView =
                (unoidl.com.sun.star.sheet.XSpreadsheetView)xController;
            unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
                xView.getActiveSheet();
            unoidl.com.sun.star.table.XCellRange xResultRange =
                xSheet.getCellRangeByName(aListener.aResult);
            xSel.select(
                new uno.Any(
                    typeof(unoidl.com.sun.star.table.XCellRange),
                    xResultRange));
        }
    }
예제 #15
0
파일: main.cs 프로젝트: staherianYMCA/test
        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);
        }