Exemplo n.º 1
0
        static void Main(string[] args)
        {
            WindowEnumerator enumerator = new WindowEnumerator("XLMAIN");
            DateTime startTime = DateTime.Now;
            IntPtr[] handles = enumerator.EnumerateWindows(1000);
            if (null != handles)
            {
                foreach (IntPtr item in handles)
                {
                    object proxy = ExcelApplicationWindow.GetApplicationProxyFromHandle(item);
                    if (null != proxy)
                    {
                        NetOffice.ExcelApi.Application application = new NetOffice.ExcelApi.Application(null, proxy);
                        Console.WriteLine("Excel.Application Hwnd:{0}", application.Hwnd);
                    }
                }
            }
            else
            {
                Console.WriteLine("Enumerate Windows failed because the timeout is reached.");
            }

            Console.WriteLine("Press any key..");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var wordApp = new NetOffice.WordApi.Application())
                using (var excelApp = new NetOffice.ExcelApi.Application())
                {
                    var doc = wordApp.Documents.Open("C:\\Users\\John\\Desktop\\test.docx");
                    var xls = excelApp.Workbooks.Open("C:\\Users\\John\\Desktop\\test.xlsx");

                    var customProperties = (DocumentProperties)doc.CustomDocumentProperties;

                    foreach (var property in customProperties)
                    {
                        Console.WriteLine(String.Format("Name: {0}, Value: {1}, Type: {2}", property.Name, property.Value, property.Type));
                    }

                    customProperties = (DocumentProperties)xls.CustomDocumentProperties;

                    foreach (var property in customProperties)
                    {
                        Console.WriteLine(String.Format("Name: {0}, Value: {1}, Type: {2}", property.Name, property.Value, property.Type));
                    }
                }

            Console.ReadKey();
        }
Exemplo n.º 3
0
        /*
         * public override string GetCustomUI(string ribbonId)
         * {
         *  _excel = new Application(null, ExcelDna.Integration.ExcelDnaUtil.Application);
         *  string ribbonXml = GetCustomRibbonXML();
         *  return ribbonXml;
         * }
         *
         * private string GetCustomRibbonXML()
         * {
         *  string ribbonXml;
         *  var thisAssembly = typeof(CustomRibbon).Assembly;
         *  var resourceName = typeof(CustomRibbon).Namespace + ".CustomRibbon.xml";
         *
         *  using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
         *  using (StreamReader reader = new StreamReader(stream))
         *  {
         *      ribbonXml = reader.ReadToEnd();
         *  }
         *
         *  if (ribbonXml == null)
         *  {
         *      throw new MissingManifestResourceException(resourceName);
         *  }
         *  return ribbonXml;
         * }
         */
        public void OnLoad(IRibbonUI ribbon)
        {
            if (ribbon == null)
            {
                throw new ArgumentNullException(nameof(ribbon));
            }

            _thisRibbon = ribbon;

            _excel = new Application(null, ExcelDna.Integration.ExcelDnaUtil.Application); //added this
            //_excel.WorkbookActivateEvent += OnInvalidateRibbon;
            //_excel.WorkbookDeactivateEvent += OnInvalidateRibbon;
            //_excel.SheetActivateEvent += OnInvalidateRibbon;
            //_excel.SheetDeactivateEvent += OnInvalidateRibbon;
            _thisRibbon.Invalidate();
            //if (_excel.ActiveWorkbook == null)
            //{
            //    _excel.Workbooks.Add();
            //}

            //get apikey
            Utils.apiKey = System.Configuration.ConfigurationManager.AppSettings["apiKey"];

            //get projects;
            _projects = Projects.GetProjects(Utils.apiKey);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            WindowEnumerator enumerator = new WindowEnumerator("XLMAIN");
            DateTime         startTime  = DateTime.Now;

            IntPtr[] handles = enumerator.EnumerateWindows(1000);
            if (null != handles)
            {
                foreach (IntPtr item in handles)
                {
                    object proxy = ExcelApplicationWindow.GetApplicationProxyFromHandle(item);
                    if (null != proxy)
                    {
                        NetOffice.ExcelApi.Application application = new NetOffice.ExcelApi.Application(null, proxy);
                        Console.WriteLine("Excel.Application Hwnd:{0}", application.Hwnd);
                    }
                }
            }
            else
            {
                Console.WriteLine("Enumerate Windows failed because the timeout is reached.");
            }

            Console.WriteLine("Press any key..");
            Console.ReadKey();
        }
Exemplo n.º 5
0
        public override string GetCustomUI(string ribbonId)
        {
            _excel = new Application(null, ExcelDna.Integration.ExcelDnaUtil.Application);
            string ribbonXml = GetCustomRibbonXML();

            return(ribbonXml);
        }
Exemplo n.º 6
0
 static void Main(string[] args)
 {
     var excel      = new NetOffice.ExcelApi.Application();
     var word       = new NetOffice.WordApi.Application();
     var outlook    = new NetOffice.OutlookApi.Application();
     var powerpoint = new NetOffice.PowerPointApi.Application();
 }
Exemplo n.º 7
0
        public String Version()
        {
            using (var excel = new NetOffice.ExcelApi.Application())
            {
                var version = excel.Version;

                excel.Quit();

                return version;
            }
        }
Exemplo n.º 8
0
        public MainWindow()
        {
            InitializeComponent();
            using (var excelApplication = new NetOffice.ExcelApi.Application())
            {
                try
                {
                    // Création du fichier de travail.
                    var workBook = excelApplication.Workbooks.Add();
                    // Positionnement sur le premier onglet.
                    var workSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[1];

                    // Ajout des données dans les différentes cellules.
                    workSheet.Cells[1, 2].Value  = "Langues (en millions de locuteurs) :";
                    workSheet.Cells[2, 1].Value  = "Mandarin";
                    workSheet.Cells[2, 2].Value  = "860";
                    workSheet.Cells[3, 1].Value  = "Espagnol";
                    workSheet.Cells[3, 2].Value  = "469";
                    workSheet.Cells[4, 1].Value  = "Anglais";
                    workSheet.Cells[4, 2].Value  = "362";
                    workSheet.Cells[5, 1].Value  = "Arabe";
                    workSheet.Cells[5, 2].Value  = "276";
                    workSheet.Cells[6, 1].Value  = "Bengali";
                    workSheet.Cells[6, 2].Value  = "270";
                    workSheet.Cells[7, 1].Value  = "Hindi";
                    workSheet.Cells[7, 2].Value  = "269";
                    workSheet.Cells[8, 1].Value  = "Portugais";
                    workSheet.Cells[8, 2].Value  = "222";
                    workSheet.Cells[9, 1].Value  = "Russe";
                    workSheet.Cells[9, 2].Value  = "150";
                    workSheet.Cells[10, 1].Value = "Japonais";
                    workSheet.Cells[10, 2].Value = "125";
                    workSheet.Cells[11, 1].Value = "Lahnda/Pendjabi";
                    workSheet.Cells[11, 2].Value = "112";

                    // Ajout d'un diagramme et positionnement.
                    var chart = ((NetOffice.ExcelApi.ChartObjects)workSheet.ChartObjects()).Add(150, 200, 500, 400);
                    // Définition du type de diagramme.
                    chart.Chart.ChartType = NetOffice.ExcelApi.Enums.XlChartType.xlPie;
                    // Association du diagramme aux données de la grille.
                    chart.Chart.SetSourceData(workSheet.Range("A1:B11"));

                    // Enregistrement du fichier.
                    workBook.SaveAs(@"C:\Users\toky\Desktop\newDep\test.xlsx");
                }
                finally
                {
                    // Sortie de l'application Excel.
                    excelApplication.Quit();
                }
            }
        }
Exemplo n.º 9
0
        private static void Verify0000001002560(string filename)
        {
            using (var excel = new NetOffice.ExcelApi.Application())
            {
                var workBook  = excel.Workbooks.Open(filename);
                var workSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[1];

                Assert.AreEqual("reading.test", workSheet.Cells[2, 1].Value);
                Assert.AreEqual("読み込みテスト", workSheet.Cells[2, 2].Value);

                excel.Quit();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Destruct the Office application objects and remove event handlers
        /// </summary>
        private void DestructApplication()
        {
            if (this.excelApplication != null)
            {
                // unregister events
                this.excelApplication.WorkbookActivateEvent   -= this.OnWorkbookActivateEvent;
                this.excelApplication.WorkbookDeactivateEvent -= this.OnWorkbookDeactivateEvent;

                // set excel instance to null
                this.officeApplicationWrapper.Excel = null;
                this.excelApplication = null;
            }
        }
        public void CreateReport(string outFilePath)
        {
            using (var excelApp = new NetOffice.ExcelApi.Application())
            {
                excelApp.DisplayAlerts = false;
                var workbook = excelApp.Workbooks.Add();

                CreateCompetitorListWorksheet(workbook.Worksheets[1] as NetOffice.ExcelApi.Worksheet);
                CreateSpectatorListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet);
                CreateRefereeListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet);
                CreateCoachListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet);
                CreateSparringListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet);
                CreateFormsListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet);

                workbook.SaveAs(outFilePath);
                excelApp.Quit();
            }
        }
        public bool IsRegistered()
        {
            var app = new NetOffice.ExcelApi.Application();

            // grab an immutable copy of the installed Excel version code
            var versionToken = app.Version;

            var key = Registry.CurrentUser.OpenSubKey($"Software\\Microsoft\\Office\\{versionToken}\\Excel\\Options", true);

            if (key == null)
            {
                return(false);
            }
            var allChildValues = key.GetValueNames();

            // check if the plug-in is already installed...
            var openValues = allChildValues.Where(v => v.StartsWith("OPEN")).ToList();
            var result     = openValues.Any(v => key.GetValue(v).ToString().Contains(registerName));

            key.Close();
            return(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initialize the Office application objects, setup event handlers
        /// </summary>
        /// <param name="application">
        /// The application object that is used in the current addin
        /// </param>
        private void InitializeApplication(object application)
        {
            var excel = application as NetOffice.ExcelApi.Application;

            if (excel != null)
            {
                // set the excel application object
                this.excelApplication = excel;
                this.excelApplication.DisplayAlerts  = true;
                this.excelApplication.ScreenUpdating = true;

                // set the excel instance to the office application wrapper
                this.officeApplicationWrapper.Excel = excel;

                // create event handlers
                this.excelApplication.WorkbookActivateEvent   += this.OnWorkbookActivateEvent;
                this.excelApplication.WorkbookDeactivateEvent += this.OnWorkbookDeactivateEvent;

                logger.Debug("The current addin is loaded for Excel");
                return;
            }
        }
        public void Register()
        {
            var app     = new NetOffice.ExcelApi.Application();
            var version = app.Version;

            app.Quit();

            var key = Registry.CurrentUser.OpenSubKey($"Software\\Microsoft\\Office\\{version}\\Excel\\Options", true);

            if (key == null)
            {
                return;
            }
            var allChildValues = key.GetValueNames();
            // check if the plug-in is already installed...
            var openValues = allChildValues.Where(v => v.StartsWith("OPEN")).ToList();

            if (openValues.Any(v => key.GetValue(v).ToString().Contains(registerName)))
            {
                return;
            }

            var path = InstallationPath;

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

            var xllToRegister = $"{path}\\{registerName}";

            var incr         = openValues.Count > 1 ? (openValues.Count - 1).ToString() : "";
            var newOpenValue = $"OPEN{incr}";

            key.SetValue(newOpenValue, xllToRegister);
            key.Close();
        }
Exemplo n.º 15
0
        private static bool?IsExcelPasswordProtected(string fileName)
        {
            using (var exceldApplication = new NetOffice.ExcelApi.Application())
            {
                try
                {
                    // exceldApplication.Visible = false;
                    //exceldApplication.show

                    //var newWorkbook = exeldApplication.Workbooks.Open(fileName, false, true, string.Empty, "test" );
                    var newWorkbook = exceldApplication.Workbooks.Open(fileName, null, null, null, password: "******");

                    // read text of document
                    string text = newWorkbook.Sheets[0].ToString();
                }
                catch (Exception e)
                {
                    var inner = e.InnerException;
                    if (inner?.InnerException != null)
                    {
                        inner = inner.InnerException;
                        string sErrorMessage = inner.Message;

                        if (sErrorMessage.StartsWith("The password is incorrect") || sErrorMessage.StartsWith("Het wachtwoord is onjuist"))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(false);
            }
        }
Exemplo n.º 16
0
        void makeGraph()
        {
            // Open Excel API
            using (var excelApplication = new NetOffice.ExcelApi.Application())
            {
                // Add workbook
                var workBook = excelApplication.Workbooks.Add();
                workBook.Worksheets.Add();
                // set worksheet to set data
                var dataSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[1];
                dataSheet.Name = "Data";
                // set worksheet to set chart
                var chartSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[2];
                chartSheet.Name = "Charts";

                // input data
                progressBar1.Maximum = li.Count;
                for (int i = 0; i < li.Count; i++)
                {
                    dataSheet.Cells[1, i + 1].Value = fileName[i];
                    for (int j = 0; j < li[i].Count; j++)
                    {
                        dataSheet.Cells[j + 2, i + 1].Value = li[i][j];
                    }

                    var chart = ((NetOffice.ExcelApi.ChartObjects)chartSheet.ChartObjects()).Add(0, 200*i, 350, 200);
                    chart.Chart.ChartType = NetOffice.ExcelApi.Enums.XlChartType.xlLine;
                    chart.Chart.SetSourceData(dataSheet.Range(dataSheet.Cells[1, i + 1], dataSheet.Cells[li[i].Count, i + 1]));

                    progressBar1.PerformStep();
                }

                workBook.SaveAs(sfd());
                excelApplication.Quit();
            }
        }
Exemplo n.º 17
0
 void NetOffice.ExcelApi.Tools.ITaskPane.OnConnection(NetOffice.ExcelApi.Application application, object[] customArguments)
 {
 }
Exemplo n.º 18
0
 public SettingsForm(Application xl)
 {
     _excel = xl;
     InitializeComponent();
 }
Exemplo n.º 19
0
 public void OnConnection(NetOffice.ExcelApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
     Counter            = new PerformanceCounter("Process", "% Processor Time", "Excel");
     UsageTimer.Enabled = true;
 }
Exemplo n.º 20
0
 public void OnConnection(NetOffice.ExcelApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
     StartTime = DateTime.Now;
     buttonEnabled_Click(buttonEnabled, new EventArgs());
 }
Exemplo n.º 21
0
        private async Task <StreamlabsChatBotData> GatherStreamlabsChatBotSettings(string filePath)
        {
            try
            {
                StreamlabsChatBotData data = new StreamlabsChatBotData();
                await Task.Run(() =>
                {
                    using (NetOffice.ExcelApi.Application application = new NetOffice.ExcelApi.Application())
                    {
                        application.DisplayAlerts = false;

                        NetOffice.ExcelApi.Workbook workbook = application.Workbooks.Open(filePath);
                        if (workbook != null)
                        {
                            foreach (NetOffice.ExcelApi.Worksheet worksheet in workbook.Worksheets.AsEnumerable())
                            {
                                if (worksheet != null)
                                {
                                    List <List <string> > dataValues = new List <List <string> >();

                                    int totalColumns = 0;
                                    bool hasValue    = false;
                                    do
                                    {
                                        hasValue = false;
                                        NetOffice.ExcelApi.Range range = worksheet.Cells[1, totalColumns + 1];
                                        if (range.Value != null)
                                        {
                                            totalColumns++;
                                            hasValue = true;
                                        }
                                    } while (hasValue);

                                    int currentRow       = 2;
                                    List <string> values = new List <string>();
                                    do
                                    {
                                        values = new List <string>();
                                        for (int i = 1; i <= totalColumns; i++)
                                        {
                                            NetOffice.ExcelApi.Range range = worksheet.Cells[currentRow, i];
                                            if (range.Value != null)
                                            {
                                                values.Add(range.Value.ToString());
                                            }
                                            else
                                            {
                                                values.Add(string.Empty);
                                            }
                                        }

                                        if (!values.All(v => string.IsNullOrEmpty(v)))
                                        {
                                            dataValues.Add(values);
                                        }
                                        currentRow++;
                                    } while (!values.All(v => string.IsNullOrEmpty(v)));

                                    if (worksheet.Name.Equals("Commands"))
                                    {
                                        data.AddCommands(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Timers"))
                                    {
                                        data.AddTimers(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Quotes") || worksheet.Name.Equals("Extra Quotes"))
                                    {
                                        data.AddQuotes(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Ranks"))
                                    {
                                        data.AddRanks(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Currency"))
                                    {
                                        data.AddViewers(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Events"))
                                    {
                                        data.AddEvents(dataValues);
                                    }
                                }
                            }
                        }
                        application.Quit();
                    }
                });

                return(data);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            return(null);
        }
Exemplo n.º 22
0
        void NetOffice.ExcelApi.Tools.ITaskPane.OnConnection(NetOffice.ExcelApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
        {
            TestAddin addin = customArguments[0] as TestAddin;

            addin.TaskPaneOkay = true;
        }
Exemplo n.º 23
0
 public void OnConnection(NetOffice.ExcelApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
 }