Exemplo n.º 1
0
        public void AddTest()
        {
            string str = "abcdefg.bmp";
            string tp  = COMUtil.getType(str);

            Assert.AreEqual(tp, "bmp");
        }
Exemplo n.º 2
0
        protected virtual TestIEDocument[] GetFrames(TestIEDocument root)
        {
            if (root != null)
            {
                IHTMLDocument doc = root.Document;
                if (doc != null)
                {
                    IHTMLDocument[] frames = COMUtil.GetFrames(doc);
                    if (frames != null && frames.Length > 0)
                    {
                        List <TestIEDocument> framesDocs = new List <TestIEDocument>();
                        foreach (IHTMLDocument frame in frames)
                        {
                            try
                            {
                                TestIEDocument frameDoc = new TestIEDocument(frame as IHTMLDocument2);
                                framesDocs.Add(frameDoc);
                            }
                            catch
                            {
                            }
                        }

                        return(framesDocs.ToArray());
                    }
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        /* IHTMLElement GetObjectFromPoint(int x, int y)
         * return element at expected point.
         */
        public Object GetElementByPoint(int x, int y)
        {
            try
            {
                IHTMLElement  ele      = _rootDocument.GetElementByPoint(x, y) as IHTMLElement;
                IHTMLDocument rootDoc  = _rootDocument.Document;
                IHTMLDocument frameDoc = null;
                while (ele != null && (ele is IHTMLIFrameElement || ele is IHTMLFrameElement))
                {
                    frameDoc = COMUtil.GetFrameDocument(ele as IHTMLFrameBase2);
                    Rectangle rect = WindowsAsstFunctions.GetOffsetPostion(rootDoc, frameDoc);
                    x       = x - rect.Left;
                    y       = y - rect.Top;
                    ele     = (frameDoc as IHTMLDocument2).elementFromPoint(x, y);
                    rootDoc = frameDoc;
                }

                if (ele.parentElement is IHTMLAnchorElement)
                {
                    ele = ele.parentElement;
                }

                return(ele);
            }
            catch (Exception ex)
            {
                throw new ObjectNotFoundException("Can not found object at point: (" + x.ToString() + "," + y.ToString() + "): " + ex.ToString());
            }
        }
        public void SaveAsXPSTest()
        {
            COMUtil        com   = new COMUtil();
            object         ppApp = null;
            PowerPointUtil pp    = new PowerPointUtil();

            string inputPath  = Environment.CurrentDirectory + @".\TestData\Sample.pptx";
            string outputPath = Environment.CurrentDirectory + @".\TestData\Sample.xps";

            File.Delete(outputPath);

            ppApp = com.CreateObject("Powerpoint.Application");
            //HACK msoFalseにするとエラーになる。
            //pp.SetVisible(ppApp, PowerPointUtil.MsoTriState.msoTrue);

            object presentations = pp.GetPresentations(ppApp);
            object presentation  = pp.Open2007(presentations, inputPath, PowerPointUtil.MsoTriState.msoFalse);

            try {
                //XPS形式で保存
                pp.SaveAs(presentation, outputPath, PowerPointUtil.PpFileFormat.PpSaveAsXPS);
            } finally {
                pp.Close(presentation);
                pp.Quit(ppApp);
                com.MReleaseComObject(presentation);
                com.MReleaseComObject(presentations);
                com.MReleaseComObject(ppApp);
            }

            Assert.AreEqual(File.Exists(outputPath), true);
        }
Exemplo n.º 5
0
        protected override void Execute(CodeActivityContext context)
        {
            object xlApp      = null;
            string targetFile = TargetExcelFile.Get(context);

            if (!System.IO.Path.IsPathRooted(targetFile))
            {
                targetFile = System.IO.Path.Combine(Environment.CurrentDirectory, targetFile);
            }

            try
            {
                xlApp = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));
                COMUtil.InvokeSetProperty(ref xlApp, "DisplayAlerts", new object[] { false });

                object xlWorkBooks = null;
                try
                {
                    xlWorkBooks = COMUtil.InvokeGetProperty(ref xlApp, "Workbooks");

                    object xlWorkBookObject = null;

                    try
                    {
                        xlWorkBookObject = COMUtil.InvokeByMethod(ref xlWorkBooks, "Open", new object[] {
                            targetFile                                                                                              // FileName
                            , Type.Missing                                                                                          // UpdateLinks
                            , false                                                                                                 // ReadOnly
                            , Type.Missing                                                                                          // Format
                            , !String.IsNullOrEmpty(ExcelBookPassword.Get(context)) ? ExcelBookPassword.Get(context) : Type.Missing // Password
                            , !String.IsNullOrEmpty(ExcelBookPassword.Get(context)) ? ExcelBookPassword.Get(context) : Type.Missing // WriteResPassword
                            , true                                                                                                  // Ignorereadonlyrecommended
                        });

                        COMUtil.InvokeSetProperty(ref xlWorkBookObject, "ReadOnlyRecommended", new object[] { SetReadOnlyRecommended.Get(context) });

                        COMUtil.InvokeByMethod(ref xlWorkBookObject, "Save", null);
                    }
                    finally
                    {
                        COMUtil.COMRelease(ref xlWorkBookObject, false);
                    }
                }
                finally
                {
                    COMUtil.COMRelease(ref xlWorkBooks, false);
                }

                COMUtil.InvokeSetProperty(ref xlApp, "DisplayAlerts", new object[] { true });

                COMUtil.InvokeByMethod(ref xlApp, "Quit", null);
            }
            finally
            {
                COMUtil.COMRelease(ref xlApp, true);
            }
        }
Exemplo n.º 6
0
        public void SelectedSheetsPrintOutTest()
        {
            //想定結果:全シートが印刷される
            //備考:
            //確認者:橋本, 確認日:2019/3/26

            COMUtil   comUtil = new COMUtil();
            ExcelUtil xls     = new ExcelUtil();
            object    app     = null;
            object    books   = null;
            object    book    = null;
            object    sheets  = null;

            try {
                //読取用Excelをオープン
                app = comUtil.CreateObject("Excel.Application");
                xls.SetVisible(app, true);
                //xls.SetDisplayAlerts(app, false);
                //xls.SetScreenUpdating(app, true);

                books = xls.GetWorkbooks(app);
                string path = Environment.CurrentDirectory + @"\TestData\Sample.xlsx";
                book = xls.Open(books, path);

                sheets = xls.GetWorksheets(book);
                //全シート選択
                xls.WorksheetsSelect(sheets);
                //印刷
                if (IsExistsMESPrinter())
                {
                    //MESPrinter
                    xls.SelectedSheetsPrintOut(app, "MESPrinter");
                }
                else
                {
                    //デフォルトプリンタ
                    xls.SelectedSheetsPrintOut(app);
                }

                xls.Close(book);
            } finally {
                xls.Quit(app);
                comUtil.MReleaseComObject(sheets);
                comUtil.MReleaseComObject(book);
                comUtil.MReleaseComObject(books);
                comUtil.MReleaseComObject(app);
                GC.Collect();
            }
        }
Exemplo n.º 7
0
        protected override void Execute(CodeActivityContext context)
        {
            // Excelの、プロセスがあるか、確認します
            try
            {
                if (System.Diagnostics.Process.GetProcessesByName("excel").Length == 0)
                {
                    throw new Exception();
                }
            }
            catch
            {
                throw new ApplicationException(Properties.Resources.Exception_Excel_Not_Started);
            }

            object xlApp = null;

            try
            {
                xlApp = Marshal.GetActiveObject("Excel.Application");


                object xlActiveSheet = null;

                try
                {
                    xlActiveSheet = COMUtil.InvokeGetProperty(ref xlApp, "ActiveSheet");

                    ActiveSheetName.Set(context, COMUtil.InvokeGetProperty(ref xlActiveSheet, "Name").ToString());
                }
                finally
                {
                    COMUtil.COMRelease(ref xlActiveSheet, false);
                }
            }
            finally
            {
                COMUtil.COMRelease(ref xlApp, true);
            }
        }