我正在尝试使用 UIWebview 显示 MS office 文件(word、powerpoint、excel) 一些文件有宏启用 UIWebview 无法显示这些文件知道为什么会发生这种情况吗?有没有办法让 UIWebview 呈现这些文件?
注意:如果我可以显示足够的文件内容,我不希望宏工作。
我知道这是旧的,但我今天遇到了它。看起来 UIWebView 不会直接打开启用宏的 Office 文件。例如,以下代码失败 -
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
上面的代码仅适用于启用宏的 Office 文件 - 它适用于 .docx、.pptx、.rtf、.pdf、.txt 等文件。但是,如果我们将文件拉入 NSData,然后将 mime 类型显式提供给 UIWebView,则该文件将打开。下面的代码将打开这些启用宏的 Office 文件 -
// this will open a .pptm file - replace mime type as necessary for other macro-enabled file types
NSData* fileData = [NSData dataWithContentsOfFile:filePath];
[webView loadData:fileData MIMEType:@"application/vnd.ms-powerpoint.presentation.macroEnabled.12" textEncodingName:nil baseURL:nil];
使用 .pptm、.ppsm、.potm、.docm、.xlsm 进行测试