简体   繁体   中英

How to open an excel file from within an iOS App

I want to open an Excel file from my app without needing an internet connection. Is this possible? If yes, how would I go about doing this?

I am able to open a file with an internet connection in the following way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM