OBJ-C:打开受 MIcrosoft 密码保护的文档时出错
OBJ-C : Error in opening MIcrosoft Password Protected Doc
*我需要在Microsoft word、pdf和ppt doc中添加密码。为此,我集成了 'MicrosoftWord.h' 文件并使用了 SBApplication。
并使用下面的代码打开受密码保护的文档。
self.wordApp = [SBApplication applicationWithBundleIdentifier:@"com.microsoft.word"];
self.wordApp.delegate = self;
[self.wordApp 激活];
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];
}
但是在打开受密码保护的文档时出现以下错误。
无法打开 Error Domain=NSOSStatusErrorDomain Code=-1708 "errAEEventNotHandled: the AppleEvent was not handled by any handler " UserInfo={ErrorNumber=-1708}
请在以下两种情况下帮助我。
1.如何使用objective-c打开受密码保护的Microsoft word doc?
2. 如何使用 objective -c ?*
创建密码保护的 word 文档
我已经解决了,请阅读答案。
现在,我陷入了另一个问题。
我需要为 Microsoft Power Point、Microsoft Excel 和 Adobe Reader 创建 Header 文件。我在下面提到了 Stack Over Flow Link.
Scripting bridge and generate Microsoft Word header file
我使用
创建了 PowerPoint Header 文件
$ sdef /Applications/Microsoft\ Office\ 2011/Microsoft\ PowerPoint.app | sdp -fh --basename MicrosoftPowerPoint
但是在构建应用程序时出现错误。
错误:MicrosoftPowerPoint.h:3028:2:重新定义枚举器'MicrosoftPowerPoint4006ShapeRange'
任何人都请帮助我,创建 Header 文件后是否需要在应用程序中添加任何脚本或设置。我需要将此模块集成到我已集成 "MicroSoftWord.h".
的同一个 mac 应用程序中
提前致谢。
我已经用密码加密了word文档。下面是解决方法。
- (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]];
}
}
谢谢。
*我需要在Microsoft word、pdf和ppt doc中添加密码。为此,我集成了 'MicrosoftWord.h' 文件并使用了 SBApplication。 并使用下面的代码打开受密码保护的文档。 self.wordApp = [SBApplication applicationWithBundleIdentifier:@"com.microsoft.word"]; self.wordApp.delegate = self; [self.wordApp 激活];
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];
}
但是在打开受密码保护的文档时出现以下错误。 无法打开 Error Domain=NSOSStatusErrorDomain Code=-1708 "errAEEventNotHandled: the AppleEvent was not handled by any handler " UserInfo={ErrorNumber=-1708} 请在以下两种情况下帮助我。 1.如何使用objective-c打开受密码保护的Microsoft word doc? 2. 如何使用 objective -c ?*
创建密码保护的 word 文档我已经解决了,请阅读答案。
现在,我陷入了另一个问题。 我需要为 Microsoft Power Point、Microsoft Excel 和 Adobe Reader 创建 Header 文件。我在下面提到了 Stack Over Flow Link.
Scripting bridge and generate Microsoft Word header file
我使用
创建了 PowerPoint Header 文件 $ sdef /Applications/Microsoft\ Office\ 2011/Microsoft\ PowerPoint.app | sdp -fh --basename MicrosoftPowerPoint
但是在构建应用程序时出现错误。
错误:MicrosoftPowerPoint.h:3028:2:重新定义枚举器'MicrosoftPowerPoint4006ShapeRange'
任何人都请帮助我,创建 Header 文件后是否需要在应用程序中添加任何脚本或设置。我需要将此模块集成到我已集成 "MicroSoftWord.h".
的同一个 mac 应用程序中提前致谢。
我已经用密码加密了word文档。下面是解决方法。
- (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]];
}
}
谢谢。