国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:29:54
字體:
供稿:網(wǎng)友
這篇文章主要介紹了ASP.NET中實(shí)現(xiàn)導(dǎo)出ppt文件數(shù)據(jù)的實(shí)例分享,實(shí)例代碼用C#語言編寫,利用.NET的庫實(shí)現(xiàn)起來還是比較簡潔的,需要的朋友可以參考下
 

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

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

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

  操作PPT代碼如下:

復(fù)制代碼
 

    public void createPPT()    {      try      {        //ppt存儲(chǔ)路徑        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);        //添加一個(gè)表格        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();      }
 


注:相關(guān)教程知識(shí)閱讀請移步到ASP.NET教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 蒙城县| 城固县| 伽师县| 武穴市| 牡丹江市| 安图县| 宁陵县| 武山县| 醴陵市| 金溪县| 聊城市| 贡嘎县| 呼图壁县| 房产| 苏州市| 新绛县| 临潭县| 金阳县| 宁阳县| 湘西| 淮北市| 平利县| 金华市| 北京市| 抚顺市| 平江县| 昌乐县| 应城市| 纳雍县| 林芝县| 射洪县| 四会市| 苍梧县| 阿瓦提县| 沁阳市| 桓台县| 商水县| 分宜县| 武冈市| 泰兴市| 馆陶县|