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 ?? [] {
var indexColunm = 0
for cell in row.cells {
let cellStr = cell
if let cellValue = cellStr.value {
print(" indexRow = \(indexRow) indexColunm = \(indexColunm) cellValue = \(cellValue)")
}
indexColunm = indexColunm + 1
}
indexRow = indexRow + 1
}
}