コード例 #1
0
        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);
        }
コード例 #2
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();
            }
        }