问题描述
- 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保存到固定的目录下
解决方案
regsvr32 "x:pathxxx.dll"
解决方案二:
regsvr32后面要跟注册的com组件的名称。
你的ppt控件是否在机器上注册了