PowerPoint to JPEG convertor

最近做毕业设计答辩需要到一个比较好的模板,虽然我收集了数千个模板,但是PPT自动缩略图所得的效果太差,要查看PPT都需要自己手动打开,很麻烦,费事情。今天用C#写了一个小程序,实现了PowerPoint到JPEG的转换,可用于速查PPT、PPTX、POT的内容。简单方便实用。代码稍显混乱。
请在这之前安装OFFICE 2007。
PS:第一版程序忘了p.Close(),也就是关闭当前打开的幻灯片,导致最终内存占用达到1.5G,运行速度爆满,超级寒~~~

using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Windows.Forms;
using  System.IO;
using  Microsoft.Office.Core;
using  Microsoft.Office.Interop.PowerPoint;

namespace  PPT_to_JPEG
{
    
class  Program
    {
        [STAThread]
        
static   void  Main( string [] args)
        {
            ApplicationClass ac
= new  ApplicationClass();

            
string  srcRoot;
            
string  dstRoot;
            FolderBrowserDialog fbd 
=   new  FolderBrowserDialog();
            fbd.Description
= " Select root folder " ;
            
if (fbd.ShowDialog() != DialogResult.OK)  return ;
            srcRoot 
=  fbd.SelectedPath;
            fbd.Description
= " Select destination folder " ;
            fbd.ShowNewFolderButton 
=   true ;
            
if  (fbd.ShowDialog()  !=  DialogResult.OK)  return ;
            dstRoot 
=  fbd.SelectedPath;

            
string [] pptFiles  =  Directory.GetFiles(srcRoot,  " *.ppt " , SearchOption.AllDirectories);
            
string [] potFiles  =  Directory.GetFiles(srcRoot,  " *.pot " , SearchOption.AllDirectories);
            
string [] pptxFiles  =  Directory.GetFiles(srcRoot,  " *.pptx " , SearchOption.AllDirectories);
            Console.WriteLine(
" Find  "   +  (
                pptxFiles.GetUpperBound(
0 +   1   +
                potFiles.GetUpperBound(
0 +   1   +
                pptxFiles.GetUpperBound(
0 +   1 ) +   " Files " );

            
foreach ( string  ppt  in  pptFiles)
            {
                
string  dir = ppt.Substring(srcRoot.Length + 1 );
                
string  fullDir  =  Path.Combine(dstRoot, dir);
                fullDir 
=  fullDir.Substring( 0 , fullDir.Length  -   4 );
                Directory.CreateDirectory(fullDir);
                Console.WriteLine(
" Converting PPT Filedot.gif ( " +  fullDir + " ) " );
                Presentation p 
=  ac.Presentations.Open(ppt,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse);
                p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
                p.Close();
            }

            
foreach  ( string  pot  in  potFiles)
            {
                
string  dir  =  pot.Substring(srcRoot.Length + 1 );
                
string  fullDir  =  Path.Combine(dstRoot, dir);
                fullDir 
=  fullDir.Substring( 0 , fullDir.Length  -   4 );
                Directory.CreateDirectory(fullDir);
                Console.WriteLine(
" Converting POT Filedot.gif ( "   +  fullDir  +   " ) " );
                Presentation p 
=  ac.Presentations.Open(pot,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse);
                p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
                p.Close();
            }

            
foreach  ( string  pptx  in  pptxFiles)
            {
                
string  dir  =  pptx.Substring(srcRoot.Length + 1 );
                
string  fullDir  =  Path.Combine(dstRoot, Path.GetFileName(dir));
                fullDir 
=  fullDir.Substring( 0 , fullDir.Length  -   4 );
                Directory.CreateDirectory(fullDir);
                Console.WriteLine(
" Converting PPTX Filedot.gif ( "   +  fullDir  +   " ) " );
                Presentation p 
=  ac.Presentations.Open2007(pptx,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse,MsoTriState.msoFalse);
                p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
                p.Close();
            }

            Console.WriteLine(
" All done, press enter key to exit " );
            Console.ReadLine();
        }
    }
}




转载于:https://www.cnblogs.com/hesicong/archive/2007/06/10/778532.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值