Yang_Jenny 2015-02-24 09:23 采纳率: 50%
浏览 2898

c#开发Powerpoint总是出现不能注册问题

最近在开发一个c#的程序,需要利用c#窗口程序自动创建一个ppt文档,查了一些资料后写了下面的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PPT = Microsoft.Office.Interop.PowerPoint;
using Graph = Microsoft.Office.Interop.Graph;
using Microsoft.Office.Core;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;

namespace CreatePPT
{
public partial class Form1 : Form
{
PPT.Application objApp = null;
PPT.Presentations objPresSet = null;
PPT.Presentation objPres;
PPT.Slides objSlides = null;
PPT._Slide objSlide = null;
PPT.Shapes objShapes = null;
PPT.Shape objShape = null;

    public Form1()
    {
        InitializeComponent();
    }

    private void CreateButton_Click(object sender, EventArgs e)
    {
        string path;
        path = @"C:\MyPPT.pptx";
        objApp = new PPT.Application();
        objPres = new PPT.Presentation();

        if(File.Exists((string)path))
        {
            File.Delete((string)path);
        }

        Object Nothing = Missing.Value;

        objApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
        PPT.PpSaveAsFileType format = PPT.PpSaveAsFileType.ppSaveAsDefault;

        objPres.SaveAs(path, format, Microsoft.Office.Core.MsoTriState.msoFalse);

        objPres.Close();

        objApp.Quit();

    }

}

}

但在objPres = new PPT.Presentation();
这行总是出现类不能注册的错误

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {91493444-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

运行cmd只有,输入了regsvr32,但又出现了 “To register a module, you must provide a binary name”的错误。

到底要怎么解决呢?想法是希望在没有模板的情况下自动生成一个ppt保存到固定的目录下

  • 写回答

2条回答 默认 最新

  • oyljerry 2015-02-24 14:47
    关注

    regsvr32后面要跟注册的com组件的名称。
    你的ppt控件是否在机器上注册了

    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)