2016-03-23 8 views
0

* Ich muss ein Passwort in Microsoft Word, PDF und PPT doc hinzufügen. Dafür habe ich 'MicrosoftWord.h' Datei integriert und SBApplication verwendet. Und unten Code verwendet, um das passwortgeschützte Dokument zu öffnen. self.wordApp = [SBApplication applicationWithBundleIdentifier: @ "com.microsoft.word"]; self.wordApp.delegate = self; [self.wordApp aktivieren];OBJ-C: Fehler beim Öffnen von MIcrosoft Password Protected Doc

if ([self.wordApp isRunning]) { 
    MicrosoftWordDocument *activeDocument = [self.wordApp activeDocument]; 

    [activeDocument openFileName:FilePath 
       confirmConversions:NO 
         readOnly:NO 
       addToRecentFiles:NO 
       passwordDocument:@"" 
       passwordTemplate:@"" 
          Revert:NO 
        writePassword:@"1" 
      writePasswordTemplate:@"" 
        fileConverter:MicrosoftWordE162OpenFormatDocument97]; 
} 

Aber es gibt mir unten Fehler beim Öffnen passwortgeschützte doc. Fehlerdomain kann nicht geöffnet werden = NSOSStatusErrorDomain Code = -1708 "errAEEventNotHandled: das AppleEvent wurde von keinem Handler verarbeitet" UserInfo = {ErrorNumber = -1708} Bitte helfen Sie mir in zwei Fällen. 1. Wie öffnet man passwortgeschütztes Microsoft Word Doc mit objective-c? 2. Wie erstellt man passwortgeschütztes Worddoc mit dem Ziel -c? *

Ich habe das gelöst, Bitte lesen Sie die Antwort.

Jetzt bin ich bei einem anderen Problem fest. Alles, was ich brauche, um Header-Datei für Microsoft Power Point, Microsoft Excel und Adobe Reader zu erstellen. Ich habe unten auf Stack Over Flow Link verwiesen.

Scripting bridge and generate Microsoft Word header file

Ich habe Powerpoint-Header-Datei

$ sdef /Applications/Microsoft\ Office\ 2011/Microsoft\ PowerPoint.app | sdp -fh --basename MicrosoftPowerPoint 

mit erstellt Aber es wird mir eine Fehlermeldung zu geben, während die App zu bauen.

ERROR: MicrosoftPowerPoint.h: 3028: 2: Neudefinition der Enumerator 'MicrosoftPowerPoint4006ShapeRange'

Jeder mir bitte helfen, nach dem Erstellen Header-Datei macht es erfordert jedes Skript oder Einstellungen in der App hinzuzufügen. Ich muss dieses Modul in die gleiche Mac-App integrieren, in die ich "MicroSoftWord.h" integriert habe.

Vielen Dank im Voraus.

Antwort

0

Ich habe Word Doc mit Passwort verschlüsselt. Unten ist die Lösung.

- (IBAction)openWordDoc:(id)sender{ 

NSOpenPanel *openDlg = [NSOpenPanel openPanel]; 
[openDlg setCanChooseFiles:YES]; 
[openDlg setCanChooseDirectories:NO]; 
[openDlg setAllowsMultipleSelection:NO]; 
[openDlg beginSheetModalForWindow:self.window completionHandler:^(NSInteger result){ 
    if (result == 1) { 
     NSMutableString *fileUrl = [[NSMutableString alloc] initWithString:[[openDlg URL] description]] ; 
     NSRange range = [fileUrl rangeOfString:@"file://"]; 
     NSString *filePath = [fileUrl stringByReplacingCharactersInRange:range withString:@"file://localhost"]; 
     [self openWordDocument:filePath]; 

    } 
}]; 

} 

- (void) openWordDocument:(NSString *)FilePath{ 
NSLog(@"file Path =%@",FilePath); 
self.wordApp = [SBApplication applicationWithBundleIdentifier:@"com.microsoft.word"]; 
self.wordApp.delegate = self; 
[self.wordApp activate]; 

if ([self.wordApp isRunning]) { 
    MicrosoftWordDocument *activeDocument = [self.wordApp activeDocument]; 


    [activeDocument openFileName:FilePath 
       confirmConversions:NO 
         readOnly:NO 
       addToRecentFiles:NO 
       passwordDocument:@"1" 
       passwordTemplate:@"" 
          Revert:NO 
        writePassword:@"" 
      writePasswordTemplate:@"" 
        fileConverter:MicrosoftWordE162OpenFormatDocument97]; 
    activeDocument.password= @"1"; 

    [activeDocument protectProtectionType:MicrosoftWordE234NoDocumentProtection noReset:NO password:@"1" useIrm:NO enforceStyleLocks:YES] ; 

     [activeDocument saveAsFileName:FilePath fileFormat:activeDocument.saveFormat lockComments:FALSE password:@"1" addToRecentFiles:NO writePassword:@"" readOnlyRecommended:YES embedTruetypeFonts:NO saveNativePictureFormat:NO saveFormsData:NO textEncoding:NO insertLineBreaks:FALSE allowSubstitutions:NO lineEndingType:MicrosoftWordE311LineEndingCrLf HTMLDisplayOnlyOutput:NO maintainCompatibility:NO]; 

    [activeDocument closeSaving:YES savingIn:[NSURL URLWithString:FilePath]]; 

} 

} 

Danke.