Powerpoint could not open file

I am developing a C # program that creates a PowerPoint presentation. However, I ran into a problem with the following instruction:

Presentation pres = pres_set.Open(path,
  Microsoft.Office.Core.MsoTriState.msoFalse,
  Microsoft.Office.Core.MsoTriState.msoTrue,
  Microsoft.Office.Core.MsoTriState.msoTrue);

This instruction only works sometimes. If this is not the case, it throws an exception with the message "PowerPoint cannot open the file." When I manually open the template file, close it and run the function again, most of the time it will execute correctly.

I used the Microsoft PowerPoint 14.0 and Microsoft Powerpoint 12.0 libraries, but both have the same problem.

Is there any way to avoid this strange problem?

+3
source share
8 answers

The answer is much simpler: Powerpoint is expecting an existing file.

, , PowerPoint PowerPoint.exe Program.exe.

- open-method:

// Start Powerpoint
var powerpointApp = new Microsoft.Office.Interop.PowerPoint.Application();
// Get a fileInfo object to generate the full path
FileInfo fileInfo = new FileInfo(@"RelativeDir\YourPresentation.pptx");
// Use the full path
powerpointApp.Presentations.Open(fileInfo.FullName, MsoTriState.msoTrue, WithWindow: MsoTriState.msoFalse);
+5

TriState, ?

Object oMiss = System.Reflection.Missing.Value; 
Presentation pres = pres_set.Open(ref path, ref oMiss, ref oMiss, ref oMiss); 
+1

PowerPoint. , Presentations.Open , PowerPoint.

PowerPointApplication.Visible = MsoTriState.msoTrue PowerPoint, , , .

, Open msoFalse, , PowerPoint , .

Presentations.Open(inputFileName, 
                   MsoTriState.msoFalse, 
                   MsoTriState.msoTrue,
                   MsoTriState.msoFalse);

MSDN KB Open.

+1

PowerPoint, , Visual Basic for Applications (VBA) Office, :

http://www.debugging.com/bug/22261

-, PowerPoint, Excel Word.

, , VBA, .

, !

+1
        ProcessStartInfo ten_ct = new ProcessStartInfo();
        ten_ct.FileName = "POWERPNT.EXE";
        ten_ct.Arguments = @"D:\project\GiaoAn\GiaoAn\MyPpt.pptx";
        Process.Start(ten_ct);
+1

Excel, . , . , .

,

1) Power Point , ( 5 ), .

2) , ( , , , ) ). , ( - , , ).

0
source

Try the following:

Presentation pres = pres_set.Open(path, 
  Microsoft.Office.Core.MsoTriState.msoFalse, 
  Microsoft.Office.Core.MsoTriState.msoTrue, 
  Microsoft.Office.Core.MsoTriState.msoFalse);
0
source

I solve this problem using:

        var app = new PP.Application();
        PP.Presentation pres = null;
        try
        {
            Process.Start(inputFile);
            var presCol = app.Presentations;
            // Waiting for loading
            Thread.Sleep(2000);
            pres = presCol[inputFile];
            // Your code there
            // ...............
        }
        catch (System.Exception ex)
        {
            Log.Error(ex.Message);
            throw;
        }
        finally
        {
            if (pres != null)
            {
                pres.Close();
            }
            if (app != null)
            {
                app.Quit();
            }
            pres = null;
            app = null;
        }
-2
source

Source: https://habr.com/ru/post/1728825/


All Articles