iOS 读取Excel 等文件

本文介绍了两种在iOS应用中预览Excel文件的方法:一是使用UIDocumentInteractionController,设置代理并实现相关方法;二是利用QLPreviewController,设置数据源并展示预览。这两种方式都能方便地让用户在iPhone上查看Excel文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法一:使用QuickLook.freamwork

    UIDocumentInteractionController *document = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:@"/Users/a502333921/Desktop/ブック2.xlsx"]];

    document.delegate = self;

    NSLog(@"%d",[document presentPreviewAnimated:YES]);


- (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController*)controller

{

    return self;

}

- (UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller

{

    return self.view;

}

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller

{

    returnself.view.frame;

}

//点击预览窗口的“Done”(完成)按钮时调用


- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController*)_controller

{

}

此方法弹框显示文件  也可以通过其他软件打开文档



方法2:

    QLPreviewController *previewoCntroller = [[QLPreviewController alloc] init];

    previewoCntroller.dataSource = self;

    [self presentViewController:previewoCntroller animated:YES completion:nil];


- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller

{

   return1;

}

- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index

{

    return [NSURLfileURLWithPath:@"/Users/a502333921/Desktop/ブック2.xlsx"];

}


方法三
UIWebView

方法四:
通过DHxls框架
https://github.com/dhoerl/DHlibxls


问题:
当你加载Excel时候,可能会出现部分气泡中内容不显示等情况,请重新保存为xls格式文档!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值