swift读取xlsx使用的是CoreXLSX
项目的Podfile如下
platform :ios, '12.0'
use_frameworks!
target 'exceltest' do
pod 'ZIPFoundation' ,'~> 0.9'
pod 'XMLCoder', '~> 0.11.1'
pod 'CoreXLSX', '~> 0.14.1'
end
运行pod install获取文件
项目中读取文件
ViewController
guard let path = Bundle.main.path(
forResource: "test2",
ofType: "xlsx"
) else {
print("Bundle......")
return
}
guard let file = XLSXFile(filepath: path) else {
print("XLSXFile......")
return
}
for path in try file.parseWorksheetPaths() {
let ws = try file.parseWorksheet(at: path)
var indexRow = 0
for row in ws.data?.rows ?? []