Musadhikh Muhammed K
Musadhikh Muhammed K

Reputation: 415

Unable to show .xlsx formate in UIDocumentInteractionController / UIWebView

I have been trying to download different documents from server to my swift App and show in UIDocumentInteractionController. CSV formats are successfully downloaded and shown in UIDocumentInteractionController.

.xlsx formats are downloaded but not recognised by UIDocumentInteractionController/ UIVewbView.

How can I show a .xlsx file in UIDocumentInteractionController in swift

Upvotes: 2

Views: 544

Answers (1)

Matvii Hodovaniuk
Matvii Hodovaniuk

Reputation: 513

After you've downloaded the file you can use CoreXLSX library to parse it. The library can be integrated either with CocoaPods or Swift Package Manager. After that you can use it like this:

import CoreXLSX

guard let file = XLSXFile(filepath: "./file.xlsx") else {
  fatalError("XLSX file corrupted or does not exist")
}

for path in try file.parseWorksheetPaths() {
  let ws = try file.parseWorksheet(at: path)
  for row in ws.sheetData.rows {
    for c in row.cells {
      print(c)
    }
  }
}

This will print every cell in a given Excel file, but you can also filter cells and columns by their references if needed.

Upvotes: 1

Related Questions