-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting Data From a specific Worksheet #124
Comments
Hi @Ethan-Chew, no worries, it's totally fine 🙂 Did you check the example code in |
Yep, it answers my question. file.parseWorksheet()? What do I put in the parentheses though.. |
let filepath = "./file.xlsx"
guard let file = XLSXFile(filepath: filepath) else {
fatalError("XLSX file at \(filepath) is corrupted or does not exist")
}
let wsName = "Sheet 1"
for wbk in try file.parseWorkbooks() {
guard let path = try file.parseWorksheetPathsAndNames(workbook: wbk)
.filter({ $0.name == wsName }).map({ $0.path })
else { continue }
let worksheet = try file.parseWorksheet(at: path)
for row in worksheet.data?.rows ?? [] {
for c in row.cells {
print(c)
}
}
} Would this snippet work in your case? |
In my case,
and
as path is a array and not a string |
Apologies, here's a snippet that should work, I should have used let filepath = "./file.xlsx"
guard let file = XLSXFile(filepath: filepath) else {
fatalError("XLSX file at \(filepath) is corrupted or does not exist")
}
let wsName = "Sheet 1"
for wbk in try file.parseWorkbooks() {
guard let path = try file.parseWorksheetPathsAndNames(workbook: wbk)
.first(where: { $0.name == wsName }).map({ $0.path })
else { continue }
let worksheet = try file.parseWorksheet(at: path)
for row in worksheet.data?.rows ?? [] {
for c in row.cells {
print(c)
}
}
} |
Thank you so much for your help! |
I am so sorry to ask so many questions...
May I know how I can get the data from a specific worksheet, rather than letting the code run through all worksheets? Thanks
The text was updated successfully, but these errors were encountered: