2017-05-09 5 views
2

Ich konvertiere Excel-Datei in PDF mit Interop. und ich habe einen Arbeitscode.Excel zu pdf mit Interop

aber vor dem Speichern in pdf. Es wird ein Dialogfeld angezeigt, in dem der Benutzer aufgefordert wird, "Änderungen an der Datei zu speichern". Wie kann ich diese Eingabe vermeiden?

und wie kann ich das Excel schließen, wenn das Speichern durchgeführt wird? Danke

public string ExceltoPdf(string excelLocation, string outputLocation) 
     { 
      try 
      { 
       Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); 
       app.Visible = false; 
       Microsoft.Office.Interop.Excel.Workbook wkb = app.Workbooks.Open(excelLocation); 
       wkb.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, outputLocation); 

       wkb.Close(); 
       app.Quit(); 

       return outputLocation; 

      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.StackTrace); 
       throw ex; 
      } 
     } 

Antwort

2

Versuchen Zugabe

app.DisplayAlerts = False 

nach .Visible gesetzt.

1

Öffnen Sie Ihre Excel als ReadOnly

Microsoft.Office.Interop.Excel.Workbook wkb = app.Workbooks.Open(excelLocation, ReadOnly: true);