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 an empty cell? #118

Closed
Ethan-Chew opened this issue Jul 4, 2020 · 4 comments
Closed

Printing an empty cell? #118

Ethan-Chew opened this issue Jul 4, 2020 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@Ethan-Chew
Copy link

Is there a way to print an empty cell? After doing,
let test = worksheet.cells(atRows: [2]) .compactMap { $0.stringValue(sharedStrings) }
Empty cells don't return as "" but as nil, also removing it as Compact Map was used.

Thanks for the help

@MaxDesiatov MaxDesiatov added the question Further information is requested label Jul 9, 2020
@MaxDesiatov
Copy link
Collaborator

Hi @Ethan-Chew, there's a difference here between an empty cell and absence of a cell. If you'd like to know whether a cell contains a shared string value in this worksheet, you'll have to use map in this specific case. You can also read cell's value to get its inline value. Otherwise, if a cell is not present in worksheet's data?.rows arrays, then it's not present in the worksheet. Does that resolve your issue?

@Ethan-Chew
Copy link
Author

In my case, it is an empty cell, however, after running Compact Map, it returns as nil instead of "". I grabbed the whole row, and there is 1 empty cell, however, for that cell itself, it returns as nil.

@MaxDesiatov
Copy link
Collaborator

I underestand that, but unfortunately the only way for us to distinguish an empty string in a cell "" and absence of the cell is to look into what's stored in the file. If you spreadsheet editor or exporter (Excel most of the time) displays the cell as empty, but doesn't write it to the file, I don't think there's anything we can do in the library. The information about the cell containing an empty string is lost if that cell wasn't written to the file in the first place. 😞

@Ethan-Chew
Copy link
Author

Ah.. Ok. I have found a temporary solution for anyone who reads this.. Just replace all empty cells with some string like "Empty Cell"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants