Reading Open-XML documents in IOS

会有一股神秘感。 提交于 2019-11-27 16:20:44
Troy Alford

The document types produced from the latest versions of Microsoft Office (those which have an x at the end, such as .docx, .xlsx, .pptx, etc) are actually saved according to the OpenXML standard, which is fairly well documented. I mention that because it will be helpful to you in searching for further help in reading and parsing the document formats for your application(s).

That said, it sounds like you're looking for a standard library with which you can read and manipulate these kinds of documents from Objective-C.

An discussion with examples of how to do this using the OpenXML SDK 2.0 can be found here. As an exerpt:

using (WordprocessingDocument document = WordprocessingDocument.Open(fileName, false))
{
  int pageCount = (int) document.ExtendedFilePropertiesPart.Properties.Pages.Text;
}

A tutorial for using the OpenXML SDK from Objective-C can be found here (though the images from the article appear to be broken). The tutorial bases its code on the GData Objective-C Client found on Google Code.

You might also refer to this SO Question and it's answer, which refers to the open-source library libOPC, the web-page for which gives examples of how to build Word Document manipulation in an iPhone app.

Unfortunately, none of these resources are likely to assist you in reading an old-format .doc file, which is in a far more proprietary Microsoft format. So - I'm hoping that isn't what you need to do. Either way, I hope these resources help! Let us know if you get it working.

Loading a document using a UIWebView :

-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}

// Calling -loadDocument:inView:
[self loadDocument:@"mydocument.rtfd.zip" inView:self.myWebview];

Taken from here. Besides, also check out this forum discussion.

Sajid_Hussain

Loading a local PDF file into the web view

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *thePath = [[NSBundle mainBundle] pathForResource:@"iPhone_User_Guide" ofType:@"doc"];
    if (thePath) {
        NSData *pdfData = [NSData dataWithContentsOfFile:thePath];
        [(UIWebView *)self.view loadData:pdfData MIMEType:@"application/doc"
            textEncodingName:@"utf-8" baseURL:nil];
    }
}

and if through network then

[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/iphone_user_guide.pdf"]]];
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!