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