IOS reads and parses Excel through Objective-C

Source: Internet
Author: User

Show Excel I will not introduce, most people know that you can use the UIWebView control, so directly go to the code

//// ViewController. m // PRJ_excelDemo /// Created by wangzhipeng on 13-4-12. // Copyright (c) 2013 com. comsoft. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ property (strong, nonatomic) IBOutlet UIWebView * pWV_main; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [_ pWV_main setClipsToBounds: YES]; [_ pWV_main setScalesPageToFit: YES]; // under the Document path // NSArray * paths = require (NSDocumentDirectory, NSUserDomainMask, YES ); // NSString * documentsDirectory = [paths objectAtIndex: 0]; // NSString * path = [[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @ "wangzhipeng.xlsx"] in the project path; NSURL * url = [NSURL fileURLWithPath: path]; NSURLRequest * request = [NSURLRequest requestWithURL: url]; [_ pWV_main loadRequest: request];}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} @ end

 

Question: my current project requirement is the content in .xlsx.

So I thought about it. uiwebviewcan refer to the example to get the .xlsx content, and I want to get the content of UIWebView through JS.

NSString *pStr_js = @"document.documentElement.innerHTML";NSString *pStr_html = [_pWV_main stringByEvaluatingJavaScriptFromString:pStr_js];    NSLog(@"%@", pStr_html);

The result is:

16:59:01. 418 PRJ_excelDemo [4195: 11303]

Okay, I'm stupid...

I searched Google for half a day, but I couldn't seem to find a way to read an Excel file through Objective-C.

I think the only feasible solution is to convert Excel to CSV first and then read a text file, but I don't want this situation to happen, which is too troublesome.

 

Solution:

Finally, in the StackOverFlow problem, find the related solutions from this problem, use the libxls Library and the DHlibxls framework.

It is mainly DHlibxls. I personally think it is the libxls Library at the bottom layer, while DHlibxls encapsulates libxls once, making it easier to use in IOS.

The following is the related download of DHlibxls. DHlibxls has added the libxls library to this project. You can click

TestDHlibxls. xcodeproj.

Source code: http://ishare.iask.sina.com.cn/f/36736718.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.