主要功能代码长这样:
csharp
using System;
using System.Collections.Generic;
using System.Text;
using *.IO;
using PPT = Microsoft.Office.Interop.PowerPoint;
using System.Reflection;
namespace WritePptDemo
{
class Program
{
static void Main(string args)
{
string path; // 文件路径变量
PPT.Application pptApp; // PPT应用变量
PPT.Presentation pptDoc; // PPT文档变量
PPT.Presentation pptDoctmp;
path = @C:MyPPT.ppt; // 指定路径
pptApp = new PPT.ApplicationClass(); // 初始化APP
// 如果文件已经存在,直接删掉
if (File.Exists(path))
{
File.Delete(path);
}
// COM操作,用Missing.Value代替空值
object Nothing = Missing.Value;
pptDoc = pptApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
pptDoc.Slides.Add(1, PPT.PpSlideLayout.ppLayoutText);
string text = 示例文本;
// 遍历每一张幻灯片
foreach (PPT.Slide slide in pptDoc.Slides)
{
// 遍历每个形状
foreach (PPT.Shape shape in slide.Shapes)
{
// 插入文本
shape.TextFrame.TextRange.InsertAfter(text);
}
}
// 保存格式设置(下面那段没写完,应该是PpSaveAsFileType)
PPT.PpSaveAsFileType format = PPT.PpSaveAsFileType.
代码整得差不多就这样,后面保存那块好像没贴全,估计是 `.ppSaveAsPresentation` 或者 `.ppSaveAsDefault` 这种。用的是Office互操作,记得加引用~
csharp
using System;
using System.Collections.Generic;
using System.Text;
using *.IO;
using PPT = Microsoft.Office.Interop.PowerPoint;
using System.Reflection;
namespace WritePptDemo
{
class Program
{
static void Main(string args)
{
string path; // 文件路径变量
PPT.Application pptApp; // PPT应用变量
PPT.Presentation pptDoc; // PPT文档变量
PPT.Presentation pptDoctmp;
path = @C:MyPPT.ppt; // 指定路径
pptApp = new PPT.ApplicationClass(); // 初始化APP
// 如果文件已经存在,直接删掉
if (File.Exists(path))
{
File.Delete(path);
}
// COM操作,用Missing.Value代替空值
object Nothing = Missing.Value;
pptDoc = pptApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
pptDoc.Slides.Add(1, PPT.PpSlideLayout.ppLayoutText);
string text = 示例文本;
// 遍历每一张幻灯片
foreach (PPT.Slide slide in pptDoc.Slides)
{
// 遍历每个形状
foreach (PPT.Shape shape in slide.Shapes)
{
// 插入文本
shape.TextFrame.TextRange.InsertAfter(text);
}
}
// 保存格式设置(下面那段没写完,应该是PpSaveAsFileType)
PPT.PpSaveAsFileType format = PPT.PpSaveAsFileType.
代码整得差不多就这样,后面保存那块好像没贴全,估计是 `.ppSaveAsPresentation` 或者 `.ppSaveAsDefault` 这种。用的是Office互操作,记得加引用~