溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ASP.NET中怎么導(dǎo)出ppt文件數(shù)據(jù)

發(fā)布時間:2021-07-15 16:20:47 來源:億速云 閱讀:121 作者:Leah 欄目:開發(fā)技術(shù)

本篇文章給大家分享的是有關(guān)ASP.NET中怎么導(dǎo)出ppt文件數(shù)據(jù),小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

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

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

  操作PPT代碼如下:

復(fù)制代碼
 

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; //設(shè)置字的顏色
        objTextRng.Font.Size = 42; //字號
        
        //創(chuàng)建第二張PPT ppLayoutBlank指定無標(biāo)題頁
        MySlide = objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutBlank);
        //插入圖片
        MySlide.Shapes.AddPicture("1.jpg", MsoTriState.msoFalse, MsoTriState.msoTrue, 110, 140, 500, 300);
        
        //創(chuàng)建第三張PPT ppLayoutTitleOnly指定僅有標(biāo)題頁
        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);
        //關(guān)閉excelDoc文檔對象
        MyPres.Close();
        //關(guān)閉excelApp組件對象
        MyApp.Quit();
      }

以上就是ASP.NET中怎么導(dǎo)出ppt文件數(shù)據(jù),小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI