原創|使用教程|編輯:李顯亮|2020-03-16 11:45:03.693|閱讀 1139 次
概述:Spire.Presentation for .NET是專業的 PowerPoint? 組件,使用該組件,開發者可以在 .NET 平臺上對 PowerPoint? 文檔進行生成、讀取、寫入、修改、轉換和打印等操作,本文介紹了Spire.Presentation 常見的技術問題。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.Presentation for .NET是專業的 PowerPoint® 組件,使用該組件,開發者可以在 .NET 平臺上對 PowerPoint® 文檔進行生成、讀取、寫入、修改、轉換和打印等操作。
Spire.Presentation for .NET支持 PPT、PPS、PPTX、PPSX 格式的 PowerPoint® 文檔,支持的主要功能有寫入文本、插入圖片、添加圖形、表格、動畫效果、音頻和視頻等元素到幻燈片。Spire.Presentation 也支持將幻燈片轉換為 EMF、JPG、TIFF、PDF、XPS、SVG、HTML 格式文件。
點擊下載Spire.Presentation for .NET
1. 問:如何給PowerPoint文檔添加密碼保護?
答:請使用Encrypt方法給文檔加密。全部代碼:
Presentation presentation = new Presentation(); presentation.LoadFromFile("sample.pptx"); presentation.Encrypt("test"); presentation.SaveToFile("encrypt.pptx", FileFormat.Pptx2010);
2. 問:如何轉換PowerPoint文件到PDF?
答:只需要加載文件,然后保存成PDF即可。全部代碼:
Presentation presentation = new Presentation(); //加載文件 presentation.LoadFromFile("ppt.ppt"); //把文件保存成PDF presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
3. 問:如何將幻燈片保存成圖片?
答:請使用SaveAsImage方法將幻燈片保存到Image中,然后將Image對象保存成圖片。全部代碼:
Presentation ppt = new Presentation(); ppt.LoadFromFile(@"F:\testing\Sample.pptx"); for (int i = 0; i < ppt.Slides.Count; i++) { //將幻燈片保存到Image中 Image image = ppt.Slides[i].SaveAsImage(); String fileName = String.Format("5614-img-{0}.png", i); //將image保存成文件 image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); }
4. 問:如何設置文本框中文本的對齊方式?
答:請使用Alignment設置文本的對齊方式。全部代碼:
Presentation presentation = new Presentation(); //添加一個shape IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 400)); //設置shape里面第一段的對齊方式為左對齊 shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left; shape.Fill.FillType = FillFormatType.None; //添加文本 shape.TextFrame.Text = "Demo about Alignment"; presentation.SaveToFile("alignment.pptx", FileFormat.Pptx2010);
5. 問:如何提取PowerPoint中的文本?
答:請您使用TextParagraph的Text屬性。全部代碼:
StringBuilder sb = new StringBuilder(); for (int i = 0; i < ppt.Slides.Count;i++ ) { for (int j = 0; j < ppt.Slides[i].Shapes.Count;j++ ) { if (ppt.Slides[i].Shapes[j] is IAutoShape) { IAutoShape shape=ppt.Slides[i].Shapes[j] as IAutoShape; if (shape.TextFrame != null) { foreach (TextParagraph tp in shape.TextFrame.Paragraphs) { sb.Append(tp.Text + Environment.NewLine); } } } } }
6. 問:如何用圖片填充形狀?
答:請使用PictureShape的Url屬性。全部代碼:
Presentation ppt = new Presentation(); IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200)); string picUrl = @"C:\Users\Administrator\Desktop\image.jpg"; shape.Fill.FillType = FillFormatType.Picture; shape.Fill.PictureFill.Picture.Url = picUrl; shape.Fill.PictureFill.FillType = PictureFillType.Stretch; shape.ShapeStyle.LineColor.Color = Color.Transparent; ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);還想要更多嗎?您可以點擊閱讀【2019 · E-iceblue最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時,我們很高興為您提供查詢和咨詢。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn