Error description:
Failed to recover factory COM component classes with CLSID {91493441-5A91-11CF-8700-00AA0060263B} due to the following error: 80010001 The call was rejected by the call. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).
I've tried the solution on several links:
Basically what I do in the code is to create a PowerPoint via MVC and return the file to download.
MessageFilter.Register();
Application powerPointApplication = new Application();
//powerPointApplication.Visible = MsoTriState.msoFalse;
var pptPresentation = powerPointApplication.Presentations.Add(MsoTriState.msoFalse);
Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout =
pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
//Step5.Insert a slide by calling the Add method on the Presentation.Slides collection, and add some texts to the slide.
var index = 1;
var oSlides = pptPresentation.Slides;
if (model.Configuration.Ratio == "4:3")
{
pptPresentation.PageSetup.SlideSize = PpSlideSizeType.ppSlideSizeOnScreen;
}
foreach (var slide in model.Slides)
{
var oSlide = oSlides.AddSlide(index, customLayout);
oSlide.FollowMasterBackground = MsoTriState.msoFalse;
//oSlide.Background.Fill.BackColor.RGB = Convert.ToInt32(ExtractHex(model.Configuration.Background), 16);
oSlide.Background.Fill.BackColor.RGB = ColorTranslator.ToOle(HexToColor(model.Configuration.Background));
//content
var oShape = oSlide.Shapes[2];
//oShape.LockAspectRatio = MsoTriState.msoTriStateToggle;
var oTxtFrame = oShape.TextFrame;
var oTxtRange = oTxtFrame.TextRange;
oTxtRange.Text = FormatText(slide);
//oTxtRange.Font.Size = model.Configuration.FontSize;
oTxtRange.Font.Color.RGB = ColorTranslator.ToOle(HexToColor(model.Configuration.Forecolor));
oTxtRange.Font.Size = GetFontSize(slide);
if (model.Configuration.Font != null)
{
oTxtRange.Font.Name = model.Configuration.Font;
}
//oTxtRange.Font.Bold = MsoTriState.msoTrue;
oShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentCentered;
oTxtFrame.HorizontalAnchor = MsoHorizontalAnchor.msoAnchorCenter;
//oTxtFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle;
var format = oTxtRange.Paragraphs().ParagraphFormat;
format.Bullet.Type = PpBulletType.ppBulletNone;
//format.Alignment = PpParagraphAlignment.ppAlignCenter;
index++;
}
//Step6.Save the presentation as a pptx file and close it.
model.Name = "presentation.ppt";
string fileFullPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\" + model.Name;
pptPresentation.SaveAs(fileFullPath, PpSaveAsFileType.ppSaveAsOpenXMLPresentation, MsoTriState.msoTriStateMixed);
pptPresentation.Close();
powerPointApplication.Quit();
MessageFilter.Revoke();
return File(fileFullPath, "application/vnd.ms-powerpoint", model.Name);