Skip to content
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

Printing Strings in a Column #116

Closed
Ethan-Chew opened this issue Jun 25, 2020 · 8 comments
Closed

Printing Strings in a Column #116

Ethan-Chew opened this issue Jun 25, 2020 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@Ethan-Chew
Copy link

Ethan-Chew commented Jun 25, 2020

Hi there, I am new to CoreXLSX. When I print the data in column C as in the Readme.md, this error occurs.

'keyNotFound(CodingKeys(stringValue: "sz", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "si", intValue: nil), XMLKey(stringValue: "374", intValue: 374), XMLKey(stringValue: "374", intValue: 374), CodingKeys(stringValue: "r", intValue: nil), XMLKey(stringValue: "1", intValue: 1), XMLKey(stringValue: "1", intValue: 1), CodingKeys(stringValue: "rPr", intValue: nil), CodingKeys(stringValue: "sz", intValue: nil)], debugDescription: "No attribute or element found for key CodingKeys(stringValue: "sz", intValue: nil) ("sz").", underlyingError: nil)): file /Users/My Macbook/Documents/Programs:Codes/Data Collection Test/Data Collection Test/ViewController.swift, line 46
2020-06-25 18:55:21.956351+0800 Pocket Science Framework Test[32426:2275624] Fatal error: keyNotFound(CodingKeys(stringValue: "sz", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "si", intValue: nil), XMLKey(stringValue: "374", intValue: 374), XMLKey(stringValue: "374", intValue: 374), CodingKeys(stringValue: "r", intValue: nil), XMLKey(stringValue: "1", intValue: 1), XMLKey(stringValue: "1", intValue: 1), CodingKeys(stringValue: "rPr", intValue: nil), CodingKeys(stringValue: "sz", intValue: nil)], debugDescription: "No attribute or element found for key CodingKeys(stringValue: "sz", intValue: nil) ("sz").", underlyingError: nil)): file /Users/My Macbook/Documents/Programs:Codes/Data Collection Test/Data Collection Test/ViewController.swift, line 46'

I have attached my code

do {
            let filepath = "/Users/My Macbook/Documents/Programs:Codes/Data Collection Test/Data Collection Test/data.xlsx"
            guard let file = XLSXFile(filepath: filepath) else {
              fatalError("XLSX file at \(filepath) is corrupted or does not exist")
            }
            for wbk in try file.parseWorkbooks() {
              for (name, path) in try file.parseWorksheetPathsAndNames(workbook: wbk) {
                if let worksheetName = name {
                  print("This worksheet has a name: \(worksheetName)")
                }
                let sharedStrings = try file.parseSharedStrings()
                let worksheet = try file.parseWorksheet(at: path)
                
                let columnCStrings = worksheet.cells(atColumns: [ColumnReference("C")!])
                .compactMap { $0.stringValue(sharedStrings) }
                
                print(columnCStrings)
                
                for row in worksheet.data?.rows ?? [] {
                  for c in row.cells {
                    print(c)
                  }
                }
              }
            }
        } catch {
            fatalError("\(error)")
        }
@MaxDesiatov MaxDesiatov self-assigned this Jun 25, 2020
@MaxDesiatov MaxDesiatov added the bug Something isn't working label Jun 25, 2020
@MaxDesiatov
Copy link
Collaborator

Hi @Ethan-Chew, thanks for reporting the issue. It should be fixed in the new 0.12.0 version. Does updating to it resolve the issue for you?

@MaxDesiatov
Copy link
Collaborator

Hi @Ethan-Chew, I saw your previous comment, but I'm still not sure of the outcome. If the issue is still reproducible for you, would you be able to send the file that causes the issue to [email protected] if possible, or attach here if you can share it publicly? Otherwise, if the issue is resolved, do you think that I can close it here?

Thanks.

@Ethan-Chew
Copy link
Author

My current issue is the code telling me that the file does not exist while it does..

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Jun 30, 2020

I'm sorry, it's very hard to diagnose the issue without more details. What's the error message that you are seeing? Is this reproducible with just this single file or any file?

@Ethan-Chew
Copy link
Author

I have attached the file

Error message:
Fatal error: XLSX file at ./data.xlsx is corrupted or does not exist: file /Users/My Macbook/Documents/Programs:Codes/Data Collection Test/Data Collection Test/ViewController.swift

Data Collection Test.zip

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Jun 30, 2020

Thank you for supplying those. The file path you use is incorrect, you should specify the full path like this:

let filepath = Bundle.main.path(forResource: "data", ofType: "xlsx")!

Also, you will have to pull CoreXLSX 0.12.0 with pod update, it looks like you still have version 0.11 in your project.

After applying those changes, does CoreXLSX work for you then?

@Ethan-Chew
Copy link
Author

Thank you so much for helping, it is working now!

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Jun 30, 2020

No problem, happy that you've chosen CoreXLSX! Plase let me know if you see any other issues 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants