Exemplo n.º 1
0
 public SpreadsheetDocHelper( String[] args )
 {
     // Connect to a running office and get the service manager
     mxMSFactory = connect( args );
     // Create a new spreadsheet document
     mxDocument = initDocument();
 }
Exemplo n.º 2
0
 public SpreadsheetDocHelper(String[] args)
 {
     // Connect to a running office and get the service manager
     mxMSFactory = connect(args);
     // Create a new spreadsheet document
     mxDocument = initDocument();
 }
Exemplo n.º 3
0
 /// <summary>
 /// init document
 /// </summary>
 /// <param name="filepath">open a exist document</param>
 /// <param name="ishidden">true is hidden docuement</param>
 public SpreadSheetHelper(string filepath, bool ishidden)
 {
     // Connect to a running office and get the service manager
     mxMSFactory = connect();
     // get a  spreadsheet document
     mxDocument = initDocument(filepath, ishidden);
 }
Exemplo n.º 4
0
        // ________________________________________________________________

        /// <summary>
        /// init document
        /// </summary>
        /// <param name="IsHidden">true is hidden docuement</param>
        public SpreadSheetHelper(bool IsHidden)
        {
            // Connect to a running office and get the service manager
            mxMSFactory = connect();
            // Create a new spreadsheet document
            mxDocument = initDocument("", IsHidden);
        }
Exemplo n.º 5
0
// ________________________________________________________________

        public SpreadsheetDocHelper()
        {
//        System.Diagnostics.Debugger.Launch();
            // Connect to a running office and get the service manager
            mxMSFactory = connect();
            // Create a new spreadsheet document
            mxDocument = initDocument();
        }
Exemplo n.º 6
0
 public SpreadsheetDocHelper()
 {
     //        System.Diagnostics.Debugger.Launch();
     // Connect to a running office and get the service manager
     mxMSFactory = connect();
     // Create a new spreadsheet document
     mxDocument = initDocument();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Get the Desktop
 /// </summary>
 /// <param name="multiservicefactory">A multi service factory</param>
 /// <returns>Desktop object</returns>
 public static unoidl.com.sun.star.frame.XDesktop GetDesktop(
     unoidl.com.sun.star.lang.XMultiServiceFactory multiservicefactory)
 {
     try
     {
         return((unoidl.com.sun.star.frame.XDesktop)multiservicefactory.createInstance("com.sun.star.frame.Desktop"));
     }
     catch (System.Exception ex)
     {
         throw;
     }
 }
 // ________________________________________________________________
 public SpreadsheetDocHelper( String[] args )
 {
     // Connect to a running office and get the service manager
     mxMSFactory = connect( args );
     // Create a new spreadsheet document
     try {
     mxDocument = initDocument();
     } catch {
     Console.WriteLine("Error: unable to properly initialize document! That\n" +
         "usually happens when UNO bootstrap went wrong. Please check that soffice\n" +
         "binary in your path points to right OOo installation or use UNO_PATH\n" +
     "environment variable to set path to your soffice binary.");
     Environment.Exit(1);
     }
 }
Exemplo n.º 9
0
        void PerformLoad()
        {
            // Start LibreOffice and load file
            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();
            desktop = (XDesktop)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
            var componentLoader = (XComponentLoader)desktop;

            component = componentLoader.loadComponentFromURL(CreateFileUrl(file.FullName), "_blank", 0, new PropertyValue[] { });

            // TODO: while/before loading, set the viewsettings ViewId:=view1, PageKind:=0 to reset to the default view
            // (instead of notes or outline view). Unfortunately these settings aren't accesible in the API ...

            // Get the main window's handle and hide the window
            document = (XModel)component;
            XWindow window = document.getCurrentController().getFrame().getContainerWindow();

            window.setVisible(false);
            XSystemDependentWindowPeer xWindowPeer = (XSystemDependentWindowPeer)(window);

            mainHandle = new IntPtr((int)xWindowPeer.getWindowHandle(new byte[] { }, SystemDependent.SYSTEM_WIN32).Value);
            //ShowWindow(mainHandle, 0);

            presentation = (XPresentation2)((XPresentationSupplier)component).getPresentation();

            CreateThumbnails();

            listener.SlideTransitionStarted += (sender, args) =>
            {
                OnSlideIndexChanged();
            };

            Start();
            controller.gotoSlideIndex(0);

            LoadPreviewProvider();

            base.OnLoaded(true);
        }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
0
        public byte[] Convert(byte[] fileSource, string fileExtension, string extReq, AttachConversionMode mode)
        {
            logger.DebugFormat("Convert {0} to {1}", fileExtension, extReq);
            string fileName = Path.GetTempFileName();

            try
            {
                return(RetryingPolicyAction <byte[]>(() => {
                    File.WriteAllBytes(fileName + fileExtension, fileSource);
                    if (localContext == null)
                    {
                        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");

                    PropertyValue[] propertyValue = new PropertyValue[2];
                    PropertyValue aProperty = new PropertyValue();
                    aProperty.Name = "Hidden";
                    aProperty.Value = new uno.Any(true);
                    propertyValue[0] = aProperty;

                    propertyValue[1] = new PropertyValue();
                    propertyValue[1].Name = "IsSkipEmptyPages";
                    propertyValue[1].Value = new uno.Any(true);

                    XComponent xComponent = null;
                    bool toConvert = false;
                    string fileConvertedName;
                    try
                    {
                        string fileToConvertName = PathConverter(fileName + fileExtension);
                        fileConvertedName = PathConverter(fileName + "." + extReq);
                        logger.DebugFormat("Url to comvert: {0} - {1}", fileToConvertName, fileConvertedName);
                        xComponent = componentLoader.loadComponentFromURL(
                            fileToConvertName,
                            "_blank",
                            0,
                            propertyValue
                            );
                        if (xComponent == null)
                        {
                            throw new DocumentNotConvertible_Exception();
                        }

                        logger.Debug("Verify if is to process...");
                        if (fileExtension.Contains("doc") && (UseRedirectMethod(xComponent)))
                        {
                            logger.Debug("No conversion to do...");
                            toConvert = true;
                        }
                        else
                        {
                            object xls = null;

                            if (xComponent is XSpreadsheetDocument)
                            {
                                xls = xComponent as XSpreadsheetDocument;
                            }
                            else if (xComponent is XTextDocument)
                            {
                                xls = xComponent as XTextDocument;
                            }

                            if (xls != null)
                            {
                                //Se i nomi degli sheets sono fra quelli non convertibili, usare il converter Office.
                                if (xls is XSpreadsheetDocument)
                                {
                                    var sheetNames = (xls as XSpreadsheetDocument)
                                                     .getSheets()
                                                     .getElementNames()
                                                     .ToArray();

                                    for (int i = 0; i < sheetNames.Length; i++)
                                    {
                                        sheetNames[i] = (sheetNames[i] ?? string.Empty).ToUpper();
                                    }

                                    var namesSet = (ConfigurationManager.AppSettings["RedirectSheetNames"] ?? string.Empty)
                                                   .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                                                   .OrderByDescending(x => x.Length);

                                    var founded = false;

                                    foreach (var set in namesSet)
                                    {
                                        var names = set
                                                    .Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

                                        if (names.Length <= sheetNames.Length)
                                        {
                                            founded = true;
                                            foreach (var n in names)
                                            {
                                                if (!sheetNames.Contains(n.ToUpper()))
                                                {
                                                    founded = false;
                                                    break;
                                                }
                                            }

                                            if (founded)
                                            {
                                                logger.Debug("No conversion to do...");
                                                return null;
                                            }
                                        }
                                    }
                                }

                                //var xls = xComponent as XSpreadsheetDocument;
                                var styles = (xls as XStyleFamiliesSupplier).getStyleFamilies();
                                var pageStyles = styles.getByName("PageStyles").Value as XNameContainer;

                                bool scaleToPages = false;

                                var configured = ConfigurationManager.AppSettings["ScaleToPages"];
                                try
                                {
                                    if (!string.IsNullOrEmpty(configured))
                                    {
                                        var dummy = bool.Parse(configured);
                                        scaleToPages = dummy;
                                    }
                                }
                                catch { logger.ErrorFormat("Invalid value for configured parameter \"{0}\". Current value is \"{1}\".", "ScaleToPages", configured); }

                                var configValue = ConfigurationManager.AppSettings["StampaConforme.ForcePortrait"];
                                var forcePortrait = !string.IsNullOrEmpty(configValue) && configValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);
                                logger.Info("StampaConforme.ForcePortrait: " + forcePortrait.ToString());

                                foreach (var nome in pageStyles.getElementNames())
                                {
                                    var props = pageStyles.getByName(nome).Value as XPropertySet;
                                    if (forcePortrait)
                                    {
                                        var isLandscape = (bool)props.getPropertyValue("IsLandscape").Value;
                                        if (isLandscape)
                                        {
                                            var size = props.getPropertyValue("Size").Value as Size;
                                            var w = size.Width;
                                            size.Width = size.Height;
                                            size.Height = w;
                                            props.setPropertyValue("Size", new uno.Any(typeof(Size), size));
                                            props.setPropertyValue("IsLandscape", new uno.Any(false));
                                        }
                                    }

                                    if (scaleToPages && props.getPropertySetInfo().hasPropertyByName("ScaleToPages"))
                                    {
                                        props.setPropertyValue("ScaleToPages", new uno.Any((short)1));
                                    }
                                }
                            }

                            PropertyValue[] saveProps = new PropertyValue[2];
                            saveProps[0] = new PropertyValue();
                            saveProps[0].Name = "FilterName";
                            saveProps[0].Value = new uno.Any("writer_pdf_Export");

                            saveProps[1] = new PropertyValue();
                            saveProps[1].Name = "IsSkipEmptyPages";
                            saveProps[1].Value = new uno.Any(true);
                            logger.Debug("loadComponentFromURL end.");

                            ((XStorable)xComponent).storeToURL(fileConvertedName, saveProps);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        throw;
                    }
                    finally
                    {
                        if (xComponent != null)
                        {
                            xComponent.dispose();
                        }
                    }
                    logger.DebugFormat("Conversione END - ToConvert: {0}", toConvert);
                    if (toConvert)
                    {
                        return null;
                    }
                    else
                    {
                        return File.ReadAllBytes(fileName + "." + extReq);
                    }
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }
            finally
            {
                try
                {
                    File.Delete(fileName + fileExtension);
                    File.Delete(fileName + extReq);
                    File.Delete(fileName);
                }
                catch { }
            }
        }