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

i try to write into cell and i expect the sheet to make calculations and read result from another cell #105

Closed mabdelatief closed 5 years ago

mabdelatief commented 5 years ago

i have a spread sheet that does some complex calculations and its working perfectly with Numbers on macOS, i imported it into my project and im trying to write to a cell and it works, but when i read the expected result from another cell after calculations are done, its not changed, its the same as before, apparently the calculations are not made, what can i do ?
here is my full code ` class ViewController: UIViewController {

let path: String = Bundle.main.path(forResource: "BCS", ofType: "xlsx")!

// Open the spreadsheet, get the first sheet, first worksheet, and first cell A1.
// This is solely demo code to show basics; your actual code would do much more here.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    change {
     let path: String = Bundle.main.path(forResource: "BCS", ofType: "xlsx")!
        let spreadsheet: BRAOfficeDocumentPackage = BRAOfficeDocumentPackage.open(path)
       // let sheet: BRASheet = spreadsheet.workbook.sheets[0] as! BRASheet
        let worksheet: BRAWorksheet = spreadsheet.workbook.worksheets[2] as! BRAWorksheet
        let cell: BRACell = worksheet.cell(forCellReference: "D20") 
        let cell2: BRACell = worksheet.cell(forCellReference: "E7")  

        print(cell.stringValue())  // prints the hard coded value instead of the expected calculated result 
        print(cell2.stringValue())   // prints the inserted value "8000"

    }

}

func change(completion: () -> Void) {
    let path: String = Bundle.main.path(forResource: "BCS", ofType: "xlsx")!
    let spreadsheet: BRAOfficeDocumentPackage = BRAOfficeDocumentPackage.open(path)
    let sheet: BRASheet = spreadsheet.workbook.sheets[0] as! BRASheet
    let worksheet: BRAWorksheet = spreadsheet.workbook.worksheets[2] as! BRAWorksheet

    worksheet.cell(forCellReference: "E7", shouldCreate: true).setStringValue("8000")

    spreadsheet.save()

    completion()
}

} `