最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET中實現(xiàn)導出ppt文件數(shù)據(jù)的實例分享

 更新時間:2016年02月18日 17:12:04   作者:LEON D  
這篇文章主要介紹了ASP.NET中實現(xiàn)導出ppt文件數(shù)據(jù)的實例分享,實例代碼用C#語言編寫,利用.NET的庫實現(xiàn)起來還是比較簡潔的,需要的朋友可以參考下

 前一段時間因工作需要,需增加ppt數(shù)據(jù)的導出下載。發(fā)現(xiàn)網(wǎng)絡上這方面資料并不是很多,零零散散地找到一些相關的資料,經(jīng)過自己的試驗,終于完成相關功能。應博友要求,在此分享下我的經(jīng)驗,不好之處還望大家多多指出。

  在做之前,首先需要添加相關引用Microsoft.Office.Interop.PowerPoint.dll。

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

  操作PPT代碼如下:

復制代碼
 

    public void createPPT()
    {
      try
      {
        //ppt存儲路徑
        string path = string.Format("{0}/{1}.ppt", Server.MapPath("."), DateTime.Now.Ticks.ToString());
        //ppt引用的模版路徑
        string MyTemplateFile = "d:\\test.pot";
        PowerPoint.ApplicationClass MyApp;
        PowerPoint.Presentations MyPresSet;
        PowerPoint._Presentation MyPres;
        PowerPoint.Shape objShape;
        PowerPoint.Slides objSlides;
        PowerPoint._Slide MySlide;
        PowerPoint.TextRange objTextRng;
        PowerPoint.Table table = null;
        MyApp = new PowerPoint.ApplicationClass();
        //如果已存在,則刪除
        if (File.Exists((string)path))
        {
          File.Delete((string)path);
        }
        Object Nothing = Missing.Value;
        //套用模版
        MyPres = MyApp.Presentations.Open(MyTemplateFile, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
        MyPresSet = MyApp.Presentations;
        objSlides = MyPres.Slides;

        //創(chuàng)建第一張PPT ppLayoutTitle指定模板首頁
        MySlide = objSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle);
        //添加一行文字(left:10,top:110,width:700,height:400)
        objTextRng = MySlide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 110, 700, 400).TextFrame.TextRange;
        objTextRng.Text = " PPT";
        objTextRng.Font.Color.RGB = 0x66CCFF; //設置字的顏色
        objTextRng.Font.Size = 42; //字號
        
        //創(chuàng)建第二張PPT ppLayoutBlank指定無標題頁
        MySlide = objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutBlank);
        //插入圖片
        MySlide.Shapes.AddPicture("1.jpg", MsoTriState.msoFalse, MsoTriState.msoTrue, 110, 140, 500, 300);
        
        //創(chuàng)建第三張PPT ppLayoutTitleOnly指定僅有標題頁
        MySlide = objSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
        objTextRng = MySlide.Shapes[1].TextFrame.TextRange;
        objTextRng.Text = "目錄";
        objTextRng.Font.Size = 32;
        //插入圖片
        MySlide.Shapes.AddPicture("1.jpg", MsoTriState.msoFalse, MsoTriState.msoTrue, 110, 140, 500, 300);
        
        //創(chuàng)建第四張PPT
        MySlide = objSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank);
        //添加一個表格
        objShape = MySlide.Shapes.AddTable(3, 3, 105, 150, 400, 100);
        table = objShape.Table;
        for (int i = 1; i <= table.Rows.Count; i++)
        {
          for (int j = 1; j <= table.Columns.Count; j++)
          {
            table.Cell(i, j).Shape.TextFrame.TextRange.Font.Size = 12;
            table.Cell(i, j).Shape.TextFrame.TextRange.Text = string.Format("[{0},{1}]", i, j);
          }
        }
        
        
        //保存格式
        PowerPoint.PpSaveAsFileType format = PowerPoint.PpSaveAsFileType.ppSaveAsDefault;
        //內(nèi)容保存
        MyPres.SaveAs(path, format, Microsoft.Office.Core.MsoTriState.msoFalse);
        //關閉excelDoc文檔對象
        MyPres.Close();
        //關閉excelApp組件對象
        MyApp.Quit();
      }

相關文章

最新評論

乌拉特中旗| 青龙| 东至县| 铁力市| 上虞市| 邢台县| 陆川县| 洞头县| 武冈市| 泽普县| 金川县| 黄陵县| 图片| 呼玛县| 北辰区| 南京市| 石门县| 红河县| 平凉市| 玉树县| 娱乐| 桓仁| 中牟县| 无为县| 怀来县| 河北区| 通许县| 神木县| 岳池县| 宜阳县| 睢宁县| 衡南县| 湟源县| 中方县| 四平市| 绥德县| 抚宁县| 织金县| 石狮市| 宁陕县| 行唐县|