예제 #1
0
 public void replaceContent(List <Segment> segments, string path)
 {
     Microsoft.Office.Interop.PowerPoint.Application   application         = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Interop.PowerPoint.Application   pwpApp              = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = pwpApp.Presentations;
     Microsoft.Office.Interop.PowerPoint.Presentation  presentation        = multi_presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
     try
     {
         foreach (Segment segment in segments)
         {
             int    shape  = segment.shape;
             int    slide  = segment.slide;
             string source = segment.getTMSource();
             string target = segment.getTMTarget();
             if (!string.IsNullOrEmpty(target))
             {
                 Microsoft.Office.Interop.PowerPoint.TextRange textRange = presentation.Slides[slide].Shapes[shape].TextFrame.TextRange;
                 textRange.Replace(source, target, 0, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
             }
         }
         presentation.Save();
         presentation.Close();
         pwpApp.Quit();
     }
     catch (Exception ex)
     {
         presentation.Save();
         presentation.Close();
         pwpApp.Quit();
         File.Delete(path);
     }
 }
예제 #2
0
        //To create ppt with generated .gif files
        private void CreatePPT(string sruninFileName)
        {
            string sTemplatePPTPath = Utility.m_sBinPath + "Template.pptm";
            string sNewPPTPath      = Utility.m_sOutputFolderPath + "" + sruninFileName + ".pptm";

            try
            {
                string[] sFiles = System.IO.Directory.GetFiles(Utility.m_sOutputFolderPath, "*.gif");
                if (System.IO.File.Exists(sTemplatePPTPath))
                {
                    System.IO.File.Copy(sTemplatePPTPath, sNewPPTPath, true);
                    Powerpoint.Application  pptApp       = new Powerpoint.Application();
                    Powerpoint.Presentation presentation = pptApp.Presentations.Open(sNewPPTPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);
                    Powerpoint.Slides       oSlides      = presentation.Slides;
                    for (int i = 0; i < sFiles.Length; i++)
                    {
                        int slide_index = i + 2;
                        Powerpoint.Slide        oSlide  = (Powerpoint.Slide)presentation.Slides._Index(slide_index);
                        Powerpoint.CustomLayout oLayout = (Powerpoint.CustomLayout)oSlide.CustomLayout;
                        pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                        Powerpoint.Slide oNewSlide = presentation.Slides.AddSlide(slide_index + 1, oLayout);
                        oNewSlide.Shapes.AddPicture(sFiles[i], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 86, 688, 401);
                    }
                    presentation.Save();
                }
                else
                {
                    MessageBox.Show(sTemplatePPTPath + " file doesn't exists in this path");
                }
            }
            catch (Exception ee)
            {
                Utility.WriteErrorLog(ee);
            }
        }
예제 #3
0
        //edits text in project description ppt
        private static void EditPPT(string parkName, string projectName)
        {
            string pPath = localPath + parkName + "\\" + projectName + "\\Project Description, Photos, Map\\Project Description.pptx";

            if (!File.Exists(pPath))
            {
                return;
            }

            PPT.Application  pApp   = new PPT.Application();
            PPT.Presentation pPres  = pApp.Presentations.Open(pPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            PPT.Slide        pSlide = pPres.Slides[1];

            foreach (PPT.Shape s in pSlide.Shapes)
            {
                if (s.Name.Equals("Title 2"))
                {
                    s.TextFrame.TextRange.Delete();
                    s.TextFrame.TextRange.InsertBefore(projectName);
                }

                if (s.Name.Equals("Text Placeholder 3"))
                {
                    s.TextFrame.TextRange.Delete();
                    s.TextFrame.TextRange.InsertBefore(parkName);
                }
            }

            pPres.Save();
            pPres.Close();
            pApp.Quit();
            pApp = null;
            GC.Collect();
        }
예제 #4
0
 private void  除空白页ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (fName != "")
     {
         PowerPoint.Application  pptapp = new PowerPoint.Application();
         PowerPoint.Presentation pptpr  = pptapp.Presentations.Open(fName, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
         int n = 0;
         for (int i = pptpr.Slides.Count; i >= 1; i--)
         {
             PowerPoint.Slide oslide = pptpr.Slides[i];
             if (oslide.Shapes.Count == 0)
             {
                 oslide.Delete();
                 n += 1;
             }
         }
         if (pptpr.Slides.Count == 0)
         {
             pptpr.Slides.AddSlide(1, pptpr.SlideMaster.CustomLayouts[7]);
         }
         pptpr.Save();
         Properties.Settings.Default.GalleryRefresh = 1;
         pptpr.Close();
         MessageBox.Show("共删除了 " + n + " 个空白页");
     }
     else
     {
         MessageBox.Show("请先加载库");
     }
 }
예제 #5
0
        public void PPTSave(string filePath)
        {
            try
            {
                filePath = filePath.Replace('/', '\\');
                if (filePath.Equals(m_PptPresSet.FullName))
                {
                    m_PptPresSet.Save();
                }
                else
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    POWERPOINT.PpSaveAsFileType format = POWERPOINT.PpSaveAsFileType.ppSaveAsDefault;
                    m_PptPresSet.SaveAs(filePath, format, Microsoft.Office.Core.MsoTriState.msoFalse);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void DeleteSlide(int index)
        {
            //TODO: try-catch
            PPT.Application   app  = new PPT.Application();
            PPT.Presentations pres = app.Presentations;

            PPT.Presentation pptx = pres.Open(LibraryFile.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

            PPT.Slides slides = pptx.Slides;
            PPT.Slide  slide  = slides[index];

            slide.Delete();

            pptx.Save();
            pptx.Close();

            slide.ReleaseCOM();
            slide = null;

            slides.ReleaseCOM();
            slides = null;

            pptx.ReleaseCOM();
            pptx = null;

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;
        }
예제 #7
0
 public static void SaveFile(PowerPoint.Presentation pre, string fileName = "")
 {
     if (string.IsNullOrEmpty(fileName))
     {
         try
         {
             pre.Save();
         }
         catch (Exception e)
         {
             throw new Exception("Can't save file", e);
         }
     }
     else
     {
         try
         {
             pre.SaveAs(fileName);
         }
         catch (Exception e)
         {
             throw new Exception("Can't save file in " + fileName, e);
         }
     }
 }
        private void cmdCreateDictionary_Click(object sender, EventArgs e)
        {
            dictionaryName = txtDictionary.Text;

            if (!api.dictionary_exists(dictionaryName))
            {
                if (dictionaryName != "")
                {
                   // PowerPoint.Presentation pres = Globals.ThisAddIn.Application.ActivePresentation;
                    pres = Globals.ThisAddIn.Application.ActivePresentation;
                    string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    location = filePath + "\\Dictionaries\\" + dictionaryName;

                    pres.SaveAs(location, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                    pres.Save();

                    api.addDictionary(dictionaryName, location + ".pptx");

                    MessageBox.Show("Dictionary added");
                    pnlAssociations.Enabled = true;
                    pnlDictionary.Enabled = false;

                }
            }
            else
            {
                MessageBox.Show("Already exists");
            }
        }
예제 #9
0
        //Accept button
        private void accept_Click(object sender, EventArgs e)
        {
            String localFileName = "";

            try
            {
                disableAllButtons();
                if (application is Word.Document)
                {
                    Word.Document activeDocument = ((Word.Document)application);
                    activeDocument.Save(); // Saves the document
                    localFileName = activeDocument.FullName;
                }
                else if (application is Excel.Workbook)
                {
                    Excel.Workbook actitiveWorkBook = ((Excel.Workbook)application);
                    actitiveWorkBook.Save(); // Saves the document;
                    localFileName = actitiveWorkBook.FullName;
                }
                else if (application is PowerPoint.Presentation)
                {
                    PowerPoint.Presentation activePresentation = ((PowerPoint.Presentation)application);
                    activePresentation.Save(); // Saves the document
                    localFileName = activePresentation.FullName;
                }
                else if (application is Visio.Document)
                {
                    Visio.Document activeDocument = ((Visio.Document)application);
                    activeDocument.Save(); // Saves the document
                    localFileName = activeDocument.FullName;
                }
                else if (application is String)
                {
                    localFileName = (String)application;
                }

                String docPath = Util.getOpenKMPath(localFileName, (MSOpenKMCore.ws.folder)actualNode.Tag);
                // Must save a temporary file to be uploaded
                File.Copy(localFileName, localFileName + "_TEMP");
                localFileName = localFileName + "_TEMP";
                DocumentLogic.create(localFileName, docPath, configXML.getHost(), configXML.getUser(), configXML.getPassword());
                File.Delete(localFileName); // Deletes temporary file
                MessageBox.Show(resources.GetString("uploaded"));
            }
            catch (Exception ex)
            {
                // Ensure temporary file is deleted
                if (!localFileName.Equals("") && File.Exists(localFileName))
                {
                    File.Delete(localFileName); // Deletes temporary file
                }
                String errorMsg = "TreeForm - (accept_Click)\n" + ex.Message + "\n\n" + ex.StackTrace;
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Hide();
            }
        }
예제 #10
0
        public List <IFileItem> AppendShapes(List <PPT.Shape> srcShapes)
        {
            PPT.Application   ppt             = null;
            PPT.Presentations pres            = null;
            PPT.Presentation  pptPresentation = null;
            try
            {
                ppt  = new PPT.Application();
                pres = ppt.Presentations;

                pptPresentation = pres.Open(FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);

                PPT.DocumentWindow wnd = pptPresentation.Windows[1];
                //wnd.Height = 200;
                //wnd.Top = -200;
                wnd.WindowState = PPT.PpWindowState.ppWindowMinimized;
                wnd             = null;

                PPT.Slides gSlides    = pptPresentation.Slides;
                int        startIndex = gSlides.Count + 1;
                int        count      = 0;
                foreach (PPT.Shape shape in srcShapes)
                {
                    PPT.Slide slide = gSlides.Add(startIndex + count++, PPT.PpSlideLayout.ppLayoutBlank);
                    shape.Copy();
                    slide.Shapes.Paste();
                    slide.Tags.Add(ShapeTag.Tag, ShapeTag.Value);

                    slide.ReleaseCOM();
                    slide = null;
                }
                List <IFileItem> newItems = new List <IFileItem>();
                newItems = fileIndex.UpdateIndex(pptPresentation, startIndex);

                return(newItems);
            }
            finally
            {
                if (pptPresentation != null)
                {
                    pptPresentation.Save();
                    pptPresentation.Close();
                }
                pptPresentation.ReleaseCOM();
                pptPresentation = null;

                pres.ReleaseCOM();
                pres = null;

                ppt.ReleaseCOM();
                ppt = null;
            }
        }
        /// <summary>
        /// 设置PPT文件属性
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <param name="fileId">文件Id</param>
        public static void SetPPTFileID(string filePath, string fileId)
        {
            PowerPoint.Application  application  = null;
            PowerPoint.Presentation presentation = null;
            try
            {
                _log.Debug($"SetPPTFileID Start.");
                application = new PowerPoint.Application();

                // 设置文件
                presentation = application.Presentations.Open(filePath, WithWindow: Microsoft.Office.Core.MsoTriState.msoFalse);
                var  oDocBuiltInProps    = presentation.BuiltInDocumentProperties;
                Type typeDocBuiltInProps = oDocBuiltInProps.GetType();

                //Set the Comments property.
                typeDocBuiltInProps.InvokeMember("Item", BindingFlags.Default | BindingFlags.SetProperty, null, oDocBuiltInProps, new object[] { "Comments", fileId });

                presentation.Save();
            }
            catch (Exception ex)
            {
                _log.Debug($"SetPPTFileID Exception: {ex.Message}");
            }
            finally
            {
                KillProcessesTask("POWERPOINT");

                try
                {
                    if (presentation != null)
                    {
                        presentation.Close();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(presentation);
                    }
                }
                catch (Exception ex)
                {
                    presentation = null;
                    _log.Debug($"SetPPTFileID DocClose Finally Exception: {ex.Message}");
                }
                try
                {
                    application.Quit();
                }
                catch (Exception ex)
                {
                    application = null;
                    _log.Debug($"SetPPTFileID AppClose Finally Exception: {ex.Message}");
                }
                _log.Debug($"SetPPTFileID End.");
            }
        }
예제 #12
0
        public string CommitBuild()
        {
            templateSlide.Delete();
            workingPPT.Save();
            workingPPT.Close();

            if (isTemporaryTask)
            {
                File.Move(workingFile, workingFile + ".pptx");
                workingFile += ".pptx";
            }
            return(workingFile);
        }
예제 #13
0
 protected override void CleanContentProperties()
 {
     Office.DocumentProperties docProperties = (Office.DocumentProperties)presentation.CustomDocumentProperties;
     foreach (Office.DocumentProperty prop in docProperties)
     {
         if (prop.Name.Equals(CONTENT_ID_NAME, StringComparison.InvariantCulture))
         {
             prop.Delete();
             break;
         }
     }
     docProperties = (Office.DocumentProperties)presentation.CustomDocumentProperties;
     foreach (Office.DocumentProperty prop in docProperties)
     {
         if (prop.Name.Equals(REPOSITORY_ID_NAME, StringComparison.InvariantCulture))
         {
             prop.Delete();
             break;
         }
     }
     presentation.Save();
 }
예제 #14
0
        public List <Segment> redPPTXFile(string path, char[] delimiters)
        {
            string         filename = Path.GetFileName(path);
            List <Segment> result   = new List <Segment>();

            try
            {
                Microsoft.Office.Interop.PowerPoint.Application   application         = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Application   pwpApp              = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = pwpApp.Presentations;
                Microsoft.Office.Interop.PowerPoint.Presentation  presentation        = multi_presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                foreach (Slide slide in presentation.Slides)
                {
                    int indexShape = 1;
                    foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
                    {
                        if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
                        {
                            var textFrame = shape.TextFrame;
                            if (textFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                            {
                                var           textRange = textFrame.TextRange;
                                string        text      = textRange.Text.ToString();
                                List <string> tmp       = splitTxtContentToSegment(text, delimiters);
                                foreach (string str in tmp)
                                {
                                    tm tm = new tm();
                                    tm.Source = str;
                                    int     indexSlide = slide.SlideIndex;
                                    Segment segment    = new Segment();
                                    segment.slide = indexSlide;
                                    segment.shape = indexShape;
                                    segment.file  = filename;
                                    segment.setTM(tm);
                                    result.Add(segment);
                                }
                            }
                        }
                        indexShape++;
                    }
                }

                presentation.Save();
                presentation.Close();
                pwpApp.Quit();
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
예제 #15
0
        /// <summary>
        /// 给ppt添加页眉
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static bool AddPageHeaderFooterForPPT(string filepath)
        {
            try
            {
                //加载PPT文档
                Microsoft.Office.Interop.PowerPoint._Application app = new Microsoft.Office.Interop.PowerPoint.Application();
                app.Visible = MsoTriState.msoTrue;
                Microsoft.Office.Interop.PowerPoint.Presentation ppt = app.Presentations.Open(filepath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);


                //设置水印文字和字体
                System.Drawing.Font font = new System.Drawing.Font("宋体", 10);
                String watermark         = "内部资料";

                foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in ppt.Slides)
                {
                    //slide.DisplayMasterShapes = MsoTriState.msoCTrue;
                    slide.HeadersFooters.Footer.Visible = MsoTriState.msoCTrue;
                    slide.HeadersFooters.Footer.Text    = watermark;
                }

                //ppt.SaveAs(@"C:\Users\Administrator\Desktop\Test_yemei.pptx",PpSaveAsFileType.ppSaveAsDefault);
                ppt.Save();
                ppt.Close();
                app.Quit();
                app = null;
                GC.Collect();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// Handles button for creating dictionaries
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdCreateDictionary_Click(object sender, EventArgs e)
        {
            dictionaryName = txtDictionary.Text;
            //dictionaryName = txtDictionary.Text.ToLower(); ?

            if (!api.dictionary_exists(dictionaryName))
            {
                if (dictionaryName != "")
                {

                    presentation = Globals.ThisAddIn.Application.ActivePresentation;

                    location = filePath + "\\" + dictionaryName;

                    presentation.SaveAs(location, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                    presentation.Save();

                    api.addDictionary(dictionaryName, location + ".pptx");

                    MessageBox.Show("Dictionary added. You may now add keywords to the dictionary");

                    pnlAssociations.Enabled = true;
                    pnlDictionary.Enabled = false;

                }
                else
                {
                    MessageBox.Show("Dictionary name cannot be blank - Please enter a dictionary name");
                }
            }
            else
            {
                MessageBox.Show("\""+ dictionaryName + "\"" + " dictionary already exists");
            }
        }
 public void Save()
 {
     _presentation.Save();
 }
예제 #18
0
        public void Output(ShiftingReport report, string filename)
        {
            ppt         = new PowerPoint.Application();
            ppt.Visible = Office.MsoTriState.msoTrue;
            PowerPoint.Presentation targetPres = ppt.Presentations.Add();
            targetPres.SaveAs(filename);
            targetPres.PageSetup.SlideSize = (PowerPoint.PpSlideSizeType.ppSlideSizeOnScreen);

            int index = 0;

            foreach (string region in report.Regions)
            {
                List <ReportTable> tables = (from r in report.ReportTables
                                             where r.region == region
                                             select r).ToList();
                List <string> hint = new List <string>()
                {
                    "光明畅优", "光明健能", "光明E+", "蒙牛", "伊利",
                };
                tables.Sort(new Comparison <ReportTable>((x, y) =>
                {
                    int xidx = hint.FindIndex(s => s.Equals(x.vendor));
                    int yidx = hint.FindIndex(s => s.Equals(y.vendor));
                    if (xidx < 0)
                    {
                        xidx = hint.Count;
                        hint.Add(x.vendor);
                    }
                    if (yidx < 0)
                    {
                        yidx = hint.Count;
                        hint.Add(y.vendor);
                    }
                    return(xidx > yidx ? 1 : -1);
                }));
                foreach (ReportTable table in tables)
                {
                    targetPres.Slides.InsertFromFile(tmplPPTFilename, index * 2, 1, 2);

                    PowerPoint.Slide slideText  = targetPres.Slides[index * 2 + 1];
                    PowerPoint.Slide slideChart = targetPres.Slides[index * 2 + 2];

                    ReplaceTextInSlide(slideText, "{region}", table.region);
                    ReplaceTextInSlide(slideText, "{vendor}", table.vendor);
                    ReplaceTextInSlide(slideChart, "{region}", table.region);
                    ReplaceTextInSlide(slideChart, "{vendor}", table.vendor);

                    BuildChart(table, slideChart.SlideNumber, 2, row =>
                    {
                        Dictionary <string, string> dict = new Dictionary <string, string>()
                        {
                            { "shiftingtotal", "品牌转换" },
                            { "retainedbuyers", "原有消费者购买增加/减少" },
                            { "new/lostbuyers", "购买清单中增加/删除品牌" },
                            { "nonbuyers", "新增/流失品类消费者" },
                        };
                        string key   = row[0].Trim().Replace(" ", "").ToLower();
                        string value = null;
                        if (dict.TryGetValue(key, out value))
                        {
                            string[] newrow = new string[row.Length];
                            Array.Copy(row, newrow, row.Length);
                            newrow[0] = value;
                            return(newrow);
                        }
                        return(null);
                    });

                    BuildChart(table, slideChart.SlideNumber, 4, row =>
                    {
                        string key = row[0].Trim().Replace(" ", "");
                        Regex cn   = new Regex("[\u4e00-\u9fa5]+");
                        if (cn.IsMatch(key))
                        {
                            string[] newrow = new string[row.Length];
                            Array.Copy(row, newrow, row.Length);
                            newrow[0] = key;
                            return(newrow);
                        }
                        return(null);
                    });
                    targetPres.Save();
                    index += 1;
                }
            }
        }
예제 #19
0
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (fName != "")
            {
                List <int> del = new List <int>();
                int        n   = listView1.SelectedItems.Count;
                for (int i = n - 1; i >= 0; i--)
                {
                    ListViewItem item = listView1.SelectedItems[i];
                    item.Remove();
                    del.Add(item.ImageIndex);
                }

                listView1.Clear();
                this.listView1.Refresh();
                imageList1.Images.Clear();

                if (!Directory.Exists(Location + @"temp_gallery2\"))
                {
                    Directory.CreateDirectory(Location + @"temp_gallery2\");
                }

                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Location + @"temp_gallery2\");

                PowerPoint.Application  pptapp = new PowerPoint.Application();
                PowerPoint.Presentation pptpr  = pptapp.Presentations.Open(fName, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
                for (int k = del.Count() - 1; k >= 0; k--)
                {
                    int cn = del[k];
                    if (k != del.Count() - 1)
                    {
                        cn = cn - 1;
                    }
                    int sn = 0;
                    if (pptpr.Slides.Count > 1)
                    {
                        for (int i = 1; i <= pptpr.Slides.Count; i++)
                        {
                            PowerPoint.Slide oslide = pptpr.Slides[i];
                            if (oslide.Shapes.Count != 0)
                            {
                                sn += oslide.Shapes.Count;
                                if (cn + 1 <= sn)
                                {
                                    oslide.Shapes[oslide.Shapes.Count - (sn - cn - 1)].Delete();
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        pptpr.Slides[1].Shapes[cn + 1].Delete();
                    }
                }
                pptpr.Save();
                if (pptpr.Slides.Count != 0)
                {
                    for (int i = 1; i <= pptpr.Slides.Count; i++)
                    {
                        PowerPoint.Slide oslide = pptpr.Slides[i];
                        if (oslide.Shapes.Count != 0)
                        {
                            for (int j = 1; j <= oslide.Shapes.Count; j++)
                            {
                                PowerPoint.Shape oshape = oslide.Shapes[j];
                                int k = dir.GetFiles().Length + 1;
                                oshape.Export(Location + @"temp_gallery2\gshape_" + k + ".png", PowerPoint.PpShapeFormat.ppShapeFormatPNG);
                                Image  img = Image.FromFile(Location + @"temp_gallery2\gshape_" + k + ".png");
                                Bitmap bmp = new Bitmap(img);
                                img.Dispose();
                                imageList1.Images.Add(bmp);
                            }
                        }
                    }
                }

                Properties.Settings.Default.GalleryRefresh = 1;
                Directory.Delete(Location + @"temp_gallery2\", true);

                pptpr.Close();
                listView1.LargeImageList = imageList1;
                listView1.BeginUpdate();
                for (int i = 0; i < imageList1.Images.Count; i++)
                {
                    ListViewItem item = new ListViewItem();
                    item.ImageIndex = i;
                    listView1.Items.Add(item);
                }
                this.listView1.EndUpdate();
            }
            else
            {
                MessageBox.Show("请先加载库");
            }
        }
예제 #20
0
        /// <summary>
        /// スタンプ貼付け処理
        /// </summary>
        /// <param name="secrecyLevel">機密区分</param>
        /// <param name="fileName">ファイル名</param>
        /// <returns>true:成功 false:失敗</returns>
        public Boolean SetStampPowerPoint(Secrecy secrecyLevel, string fileName)
        {
            // 一時ファイル名取得
            string imageFilePath = System.IO.Path.GetTempFileName();

            PowerPoint.Application   pptApp  = null;
            PowerPoint.Presentations ppPress = null;
            PowerPoint.Presentation  pptFile = null;
            PowerPoint._Slide        slide   = null;
            Bitmap bmpSrc = null;

            try
            {
                // 現在開いているPowerPointの取得
                pptApp  = new PowerPoint.Application();
                ppPress = pptApp.Presentations;

                foreach (PowerPoint.Presentation ppt in ppPress)
                {
                    if (ppt.FullName == fileName)
                    {
                        // 既に開いている場合
                        return(false);
                    }
                }

                pptFile = ppPress.Open(
                    fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse
                    );

                if (pptFile == null)
                {
                    return(false);
                }

                // 先頭のスライド取得
                slide = (PowerPoint.Slide)pptFile.Slides[1];

                // スタンプ表示OFF・区分"以外"の場合はスタンプをセットしない
                // スタンプ画像を削除して終了
                if (this.chkChange.Checked == false || this.rdoElse.Checked == true)
                {
                    // 指定した名前のオブジェクトを削除
                    this.DeletePowerPointShapes(ref pptApp, ref pptFile, this.STAMP_SHAPE_NAME);

                    return(true);
                }


                // スタンプ画像をリソースから取得
                bmpSrc = this.GetStampImage(secrecyLevel);

                // 画像が取得できない場合は中断
                if (bmpSrc == null)
                {
                    return(false);
                }

                // スタンプ倍率変更
                double dStampWidth  = bmpSrc.Width / STAMP_MAGNIFICATION;
                double dStampHeight = bmpSrc.Height / STAMP_MAGNIFICATION;

                // 透過処理
                float alpha = (float)(this.nudAlpha.Value * (decimal)0.01);
                bmpSrc = this.CreateAlphaImage(bmpSrc, alpha);

                // ファイルを一時保存
                bmpSrc.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png);

                // スタンプの水平位置を PPTの幅 - 画像の幅 で算出
                float leftLocation = slide.Master.Width - (float)dStampWidth;


                // 指定した名前のオブジェクトを削除
                this.DeletePowerPointShapes(ref pptApp, ref pptFile, this.STAMP_SHAPE_NAME);


                // 画像貼付処理
                PowerPoint.Shape stampShape = slide.Shapes.AddPicture(imageFilePath,
                                                                      MsoTriState.msoFalse,
                                                                      MsoTriState.msoTrue,
                                                                      leftLocation,
                                                                      0,
                                                                      (float)dStampWidth,
                                                                      (float)dStampHeight);
                // 貼付けた画像のオブジェクト名を設定
                stampShape.Name = this.STAMP_SHAPE_NAME;

                if (pptFile != null)
                {
                    pptFile.Save();
                }
            }
            catch
            {
                Encoding sjisEnc    = Encoding.GetEncoding("Shift_JIS");
                int      FileLength = sjisEnc.GetByteCount(fileName);
                // ファイルパス最大200バイト以上の場合は実行不可とする
                if (FileLength >= FILEPATH_OUT_RANGE)
                {
                    // 文字数エラー
                    string Msg = string.Format(Resources.msgErrorArgumentOutOfRange + "{0}", fileName);
                    MessageBox.Show(Msg, Resources.msgError, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                return(false);
            }
            finally
            {
                if (pptFile != null)
                {
                    pptFile.Close();
                }

                slide   = null;
                pptFile = null;
                ppPress = null;
                pptApp  = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();

                // 一時ファイル削除
                System.IO.File.Delete(imageFilePath);

                if (bmpSrc != null)
                {
                    bmpSrc.Dispose();
                }
            }

            return(true);
        }
예제 #21
0
        public List <IFileItem> AppendSlides(List <PPT.Slide> srcSlides)
        {
            PPT.Application   ppt             = null;
            PPT.Presentations pres            = null;
            PPT.Presentation  pptPresentation = null;
            try
            {
                ppt  = new PPT.Application();
                pres = ppt.Presentations;

                pptPresentation = pres.Open(FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);

                PPT.DocumentWindow wnd = pptPresentation.Windows[1];
                //wnd.Height = 200;
                //wnd.Top = -200;
                wnd.WindowState = PPT.PpWindowState.ppWindowMinimized;
                wnd             = null;

                #region Alt. slower approach by copy ppt and insert slides from file
                //Copy
                //string tempFile = @"c:\WRK\Temp.pptx";
                //ppt.ActivePresentation.SaveCopyAs(tempFile, PPT.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                //PPT.Presentation tempPPT = ppt.Presentations.Open(tempFile,MsoTriState.msoFalse,MsoTriState.msoFalse, MsoTriState.msoFalse);

                //List<string> slideNames = slides.Select(slide => slide.Name).ToList();
                //var v = from PPT.Slide sl in tempPPT.Slides where !slideNames.Contains(sl.Name) select sl;
                //foreach(PPT.Slide s in v)
                //{
                //    s.Delete();
                //}
                //tempPPT.Save();
                //tempPPT.Close();
                //gallery.Slides.InsertFromFile(tempFile, gallery.Slides.Count);
                #endregion

                PPT.Slides gSlides    = pptPresentation.Slides;
                int        startIndex = gSlides.Count + 1;
                foreach (PPT.Slide slide in srcSlides)
                {
                    slide.Copy();
                    gSlides.Paste();
                }
                List <IFileItem> newItems = new List <IFileItem>();
                newItems = fileIndex.UpdateIndex(pptPresentation, startIndex);

                return(newItems);
            }
            finally
            {
                if (pptPresentation != null)
                {
                    pptPresentation.Save();
                    pptPresentation.Close();
                }
                pptPresentation.ReleaseCOM();
                pptPresentation = null;

                pres.ReleaseCOM();
                pres = null;

                ppt.ReleaseCOM();
                ppt = null;
            }
        }
예제 #22
0
 public void Save()
 {
     TemplateSlide?.Delete();
     WorkingPPT?.Save();
 }