0

我试过这个:

  BOOL success; 
  NSFileManager *fileManager = [NSFileManager defaultManager]; 
  NSError *error; 
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                     NSUserDomainMask, YES); 
  NSString *documentsDirectory = [paths objectAtIndex:0]; 


  NSString *writableDBPath = [documentsDirectory 
                              stringByAppendingPathComponent:@"FT1.docx"]; 
  success = [fileManager fileExistsAtPath:writableDBPath];
  NSLog(@"writableDBPath : %@", writableDBPath);

  NSString *str = [NSString stringWithContentsOfFile:writableDBPath 
                            encoding:NSUTF8StringEncoding error:&error];
  NSLog(@"My Data From File : %@",str);

str打印(null)。该文件存在于文档目录中。

那么,我该怎么做呢?

4

2 回答 2

4

您可以使用这个免费库来呈现 docx 文档。他们还提供用于本地编辑的 SDK,但它是付费的。看看:http ://www.mswordsdk.com

-(void)presentWordViewController:(NSString *)path {
if (nil==self.wordViewController) {
    self.wordViewController=[[WordViewController alloc] initWithNibName:nil bundle:nil];
    UIBarButtonItem *fixedSpace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fixedSpace.width=80;
    self.wordViewController.titleBar.items=[NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self.wordViewController action:@selector(dismissWordViewController)] ,
                                            fixedSpace,
                                            [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                            self.wordViewController.pageInfoBarButtonItem,
                                            [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                            [[UIBarButtonItem alloc] initWithTitle:@"PDF" style:UIBarButtonItemStyleBordered target:self action:@selector(pdfQuickLook:)],
                                            nil];
}

if (nil==self.modalNavigationConroller) {
    self.modalNavigationConroller=[[UINavigationController alloc]initWithRootViewController:self.wordViewController];
    [self presentViewController:self.modalNavigationConroller animated:YES completion:nil];
} else {
    if (nil==self.modalNavigationConroller.presentingViewController) {
        [self presentViewController:self.wordViewController.navigationController animated:YES completion:nil];
    }
}
[self.wordViewController loadDocument:[WordViewControllerDocument documentWithURL:[NSURL fileURLWithPath:path] andTitle:nil]];

}

于 2014-07-18T08:18:10.827 回答
0

尝试这个 :

- (void)viewDidLoad
{
 webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [webView setDelegate:self];
    NSURL *url = [NSURL fileURLWithPath:yourFilePath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSString *document = [theWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerText"];
    NSLog(@"%@",document);
}
于 2012-07-27T11:26:56.123 回答