我正在尝试从 MS Word 文档(.doc、.docx、.docs)中读取文本。从昨天开始我一直在搜索,但还没有找到任何解决方案。请任何人告诉我我该怎么办?我已经尝试过 UIWebview 从 javascript 获取文本,但效果不佳。
- (NSString *)textFromWordDocument:(NSString *)path {
UIWebView *theWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[theWebView loadRequest:request ];
NSString *document = [theWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerText"];
[theWebView release];
return document;
}
如果有人能告诉我我应该做什么或去哪里看看,那对我来说真的很有帮助谢谢
最佳答案
您加载 UIWebView 然后立即尝试访问 dom,它可能还没有准备好。
不要调用 stringByEvaluatingJavaScriptFromString: 直到 UIWebViewDelegate didFinishLoad: 被调用。
关于iphone - IOS 从 MS Word 中读取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10831976/