-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
how to get actual cell values? #21
Comments
The integer is an index into the list of strings in the ‘shared strings’ file. |
Where do I find the file ‘shared strings’? I could not see the real value of the cell and I do not see examples anywhere D: Can you create an example of how it would be used? |
This document gives an overview of the XLSX file content: http://download.microsoft.com/download/3/E/3/3E3435BD-AA68-4B32-B84D-B633F0D0F90D/SpreadsheetMLBasics.ppt |
I found the document on the microsoft page, and I already understand why the values are in that document, how do I access that file? In the parseWorksheetPaths property, only worksheets are listed. |
Hi all, as was noted here, if you're looking for string values stored in cells, those are quite frequently (but apparently not always) are stored in |
Hi Max - I think there's a wider decision for you to make: do you want this library to simply extract the data in XLSX files keeping the structure unchanged and leave it to users to do the matching and cross-referencing? Shared strings is not the only place where this is required - linking worksheets using rId is another, and formats is another. Or do you want to do these joins in the library and cache 'higher level' objects as you are suggesting above. It's up to you - if it was me I would keep this library low level, clean, and aligned to the XLSX structure - you or someone else can always build a 'logical level' library on top of it in future! |
Hey @FleetPhil, thanks for the suggestion. I agree, I'd prefer to maintain a library with narrow focus, so probably will leave the API as it is in PR #8 right now: I would still appreciate more feedback from everyone else reading this. Thanks for your input! |
Still needs a |
I would believe that the important thing is to define what kind of situations the API will be used for. Sincerely there is a very important lack when working with XLSX files in iOS, in my case for example I'm just looking to consult a file and convert it into arrays to send them to a server. There are several old libraries in Objective C, but their use is quite confusing and they do not even have support for CocoaPods. I would recommend initially giving support for a basic handling of these files, such as consulting and modifying cells in a basic way. |
As reported in #21, there's no obvious way to get values for some values. That's caused by the fact that some of the values are stored in a separate file, which is usually located at the path `sharedStrings.xml`. This can be parsed to a corresponding model type and then processed by users of `CoreXLSX` to get the string values. * Add SharedStrings model, general cleanup * Add link to Open XML SDK docs for SharedStrings * Fix rebase conflicts * Add public `parseSharedStrings` API with tests
#8 and #22 PRs has been merged today into |
0.4.0 was released today, hope you can try it and I look forward to your feedback. I'm leaving this issue open until we have some more detailed documentation and guides describing what's the best way to get cell values in all cases. |
Closing this as |
Hi @duodo2412, the value of the cell B4 in this case is not let cell = worksheet.cells(atColumns: [ColumnReference("B")!], rows: [4]) My undertstanding is that this will return an empty array |
Tks for the your answer .
|
Hey @duodo2412, you should check this function on the /// Parse and return an array of workbooks in this file.
/// Worksheet names can be read as properties on the `Workbook` model type.
public func parseWorkbooks() throws -> [Workbook] This returns an array of workbooks (usually there's just one), each of which contains an array of sheets with their ids and names. Please check the You could then use your own function instead of extension XLSXFile {
func parseWorksheetPathsAndNames(workbook: Workbook) throws -> [(name: String?, path: String)] {
return try parseDocumentPaths().map {
try parseDocumentRelationships(path: $0)
}.flatMap { (path, relationships) -> [(name: String?, path: String)] in
let worksheets = relationships.items.filter { $0.type == .worksheet }
guard !path.isRoot else { return worksheets.map { (name: nil, path: $0.target) } }
// .rels file has paths relative to its directory,
// storing that path in `pathPrefix`
let pathPrefix = path.components.dropLast().joined(separator: "/")
let sheetIDs = Dictionary(uniqueKeysWithValues: workbook.sheets.items.compactMap { sheet in
sheet.name.flatMap { (sheet.relationship, $0) }
})
return worksheets.map { (name: sheetIDs[$0.id], path: "\(pathPrefix)/\($0.target)") }
}
}
} I know this is a bit convoluted, but the CoreXLSX API represents the low-level internals of the XLSX format directly. I have plans to add more high-level functions to the library in the future, but I hope that |
Tks for your support. |
i see that cells contain some kind of indices instead of actual values (i.e. some kind of integer number instead of string)
how can i get actual value of a cell? probably there is some kind of reference table for it?
The text was updated successfully, but these errors were encountered: