I am developing a project to learn how to parse JSON. I am trying to parse JSON to a struct. I am trying to do it using the code that come
For me, the issue with "The data couldn’t be read because it isn’t in the correct format." was something to do with the specific XLSX file I was trying to use. I created a new XLSX file in Excel, and added it to my project and that worked! Then I just pasted the data I needed from the file that was giving me the error into the newly created XLSX file and it parsed!
static func load() {
guard let filePath = Bundle.main.path(forResource: "test", ofType: "xlsx", inDirectory: nil) else {
fatalError("XLSX file not exist")
}
let file = XLSXFile(filepath: filePath)
do {
let parseBooks = try? file?.parseWorkbooks()
for eachBook in parseBooks! {
for (name, path) in try file!.parseWorksheetPathsAndNames(workbook: eachBook) {
let worksheet = try file!.parseWorksheet(at: path)
let sharedStrings = try file!.parseSharedStrings()
print(sharedStrings)
}
}
} catch {
print("Error: \(error.localizedDescription)")
}
}