无法在UIDocumentInteractionController / UIWebView中显示.xlsx格式

问题描述 投票:2回答:1

我一直在尝试从服务器下载不同的文件到我的swift应用程序并在UIDocumentInteractionController中显示。 CSV格式已成功下载并显示在UIDocumentInteractionController中。

.xlsx格式已下载但UIDocumentInteractionController / UIVewbView无法识别。

如何在swift中显示.xlsx中的UIDocumentInteractionController文件

ios excel swift uiwebview xlsx
1个回答
1
投票

下载文件后,您可以使用CoreXLSX 库来解析它。该库可以与CocoaPodsSwift Package Manager集成。之后你可以像这样使用它:

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)
    }
  }
}

这将打印给定Excel文件中的每个单元格,但如果需要,您还可以按引用过滤单元格和列。

© www.soinside.com 2019 - 2024. All rights reserved.