如何从iOS应用程序中打开Excel文件

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

我想从我的应用程序打开一个Excel文件,而无需连接互联网。这可能吗?如果是的话,我该怎么做呢?

我可以通过以下方式打开带有互联网连接的文件:

@objc static func openExcel() {
    let originalString = "http://s000.tinyupload.com/download.php?file_id=23290165129849240725&t=2329016512984924072514118"
    let encodedString = originalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
    let encodedURLString = "ms-excel:ofe|u|" + encodedString! + "|n|TestDoc.xlsx|a|App"

    if let url = NSURL(string: encodedURLString), UIApplication.shared.canOpenURL(url as URL) {
        UIApplication.shared.openURL(url as URL)
    } else if let itunesUrl = NSURL(string: "https://itunes.apple.com/us/app/microsoft-excel/id586683407?mt=8&uo=4"), UIApplication.shared.canOpenURL(itunesUrl as URL) {
        UIApplication.shared.openURL(itunesUrl as URL)
    }
}
ios swift uidocumentinteraction uidocumentinteractioncontroller
1个回答
-1
投票
let originalString = "http://s000.tinyupload.com/download.php?file_id=23290165129849240725&t=2329016512984924072514118"
let encodedString = originalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
let encodedURLString = "ms-excel:ofe|u|" + encodedString! + "|n|TestDoc.xlsx|a|App"

if let url = NSURL(string: encodedURLString), UIApplication.shared.canOpenURL(url as URL) {
    UIApplication.shared.openURL(url as URL)
} else if let itunesUrl = NSURL(string: "https://itunes.apple.com/us/app/microsoft-excel/id586683407?mt=8&uo=4"), UIApplication.shared.canOpenURL(itunesUrl as URL) {
    UIApplication.shared.openURL(itunesUrl as URL)
}
© www.soinside.com 2019 - 2024. All rights reserved.