0

I have tried with this:

 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); 

But str prints (null). The file is present in Document Directory.

So, how should I do it?

2
  • 1
    NSString cant read docx files. I guess you wil have to write a docx reader, docx are some kind of archive with XML files which you could parse. Commented Jul 27, 2012 at 10:58
  • what kind of docx reader ? you have any link/code for it ? Commented Jul 27, 2012 at 11:09

2 Answers 2

4

You can use this free library to render the docx document. They also offer and SDK for native editing, but it's paid. Have a look: 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]]; 

}

Sign up to request clarification or add additional context in comments.

2 Comments

Why did you turn down my answer. I provided a link to a free SDK that offers the possibility to load and read .docx files which is the problem trying to be solved on this post. This attitude make wonder why the hell should I share stuff here or try to help out someone.
You are right! the library you provided was really helpful for me thanks a lot.
0

Try this :

- (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); } 

4 Comments

Its UIWebView, I want to read text of .docx file & display it in UITextView. I already tried with above solution. But I need editable text which is loaded from docx file, so I cant use UIWebView. Is there any solution which can read docx file & then I can display it in UITextView ?
You can set received string to textview and can change too.I tried it.
How you have read docx file from documents directory. I am trying this from morning. Can you please put some code (to read contents from docx file) here ?
yourFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"file.docx"]];

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.