renebigot / XlsxReaderWriter

XlsxReaderWriter is an Objective-C library for iPhone / iPad and Mac. It parses and writes MS Excel XLSX files.
MIT License
437 stars 119 forks source link

Error Domain=NSCocoaErrorDomain Code=260 #106

Open EvGeniyLell opened 4 years ago

EvGeniyLell commented 4 years ago

I'm always having trouble with open xls on mac

Error Domain=NSCocoaErrorDomain Code=260 "The file “[Content_Types].xml” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/evgeniyilyin/Library/Containers/EvG.PBTool/Data/Library/Caches/fr.brae.spreadsheetdocument/111.xls/[Content_Types].xml, NSUnderlyingError=0x600000cc5e30 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2019-12-11 01:09:15.093513+0200 PBTool[49912:9928113] Error while loading content of file .rels.

Error Domain=NSCocoaErrorDomain Code=260 "The file “.rels” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/evgeniyilyin/Library/Containers/EvG.PBTool/Data/Library/Caches/fr.brae.spreadsheetdocument/111.xls/_rels/.rels, NSUnderlyingError=0x600000cda0a0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file /Users/evgeniyilyin/Work/EvG/PBTool/PBTool/FileConverter.swift, line 83
2019-12-11 01:09:16.330339+0200 PBTool[49912:9928113] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file /Users/evgeniyilyin/Work/EvG/PBTool/PBTool/FileConverter.swift, line 83

I try open original file and I try export it original file from Microsoft Exel again to xls and new xlsx but i cannot open any way

   @IBAction func testAction(_ sender: Any?) {

        selectFile() { (selectedFileUrl) in
            print(selectedFileUrl?.path)
            if let url = selectedFileUrl {
                let a = url.startAccessingSecurityScopedResource()
                let r = FileConverter.test(url.absoluteString)
                print(r)
            }
        }
    }

    func selectFile(complete: ((URL?)->Void)?) {
        let dialog = NSOpenPanel();

        dialog.title                   = "Choose a .xls file";
        dialog.showsResizeIndicator    = true;
        dialog.showsHiddenFiles        = false;
        dialog.canChooseDirectories    = true;
        dialog.canCreateDirectories    = true;
        dialog.allowsMultipleSelection = false;
        dialog.allowedFileTypes        = ["xls","xlsx"];

        let result = dialog.runModal()
        switch result {
        case .OK: // Pathname of the file
            complete?(dialog.url)
        default:
            complete?(nil)
        }
    }

where FileConverter.test it is

        guard
            let odp = BRAOfficeDocumentPackage.open(path),
            let ws = odp.workbook.worksheets.first as? BRAWorksheet // <<< - crash
            else { return nil }