As a Beginner in swift/ios development I am currently trying to install this library https://github.com/renebigot/XlsxReaderWriter in my swift code I followed the steps indicated there for linking a bridging header to swift however BRAOfficeDocumentPackage is still an undeclared type. Is there something not clear or missing in the instructions?
Here's my attempt at a solution. I had the same problem and determinted that it was due to the bridging header not being read, and being silently skipped.
I solved it this way: wherever I had added "Release" settings, I added the same "Debug" settings.
My steps and demo project are here: https://github.com/joelparkerhenderson/demo_swift_excel_xlsx_reader_writer
I am copying my README.md here so it's searchable here.
XlsxReaderWriter is an Objective-C library that works with Excel OpenXml files (XLSX).
Create a new project.
Get the repository:
git clone --depth=1 https://github.com/renebigot/XlsxReaderWriter.git
We put the repository in the same folder as our demo project's xcodeproject:
Demo Swift Xsls Reader Writer/XlsxReaderWriter
Add XlsxReaderWriter.xcodeproj to your project.
Add dependency:
Link binaries:
libXlsxReaderWriter.a
.libz.tbd
. This is more current than what the official doc says, which is to add the older version named libz.dylib
.Linking:
-all_load
Search Paths:
$(SRCROOT)/XlsxReaderWriter/
not $(SRCROOT)/XlsxReaderWriter/XlsxReaderWriter/
.Bridging Header:
Bridge.h
#import "XlsxReaderWriter-swift-bridge.h"
Add the bridge:
Bridge.h
Verify:
Create an Excel file by using your own Excel software, or any Excel-compatible software.
DemoWorkbook.xlsx
and save it in the repository.Edit ViewController.swift
:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let documentPath: String = NSBundle.mainBundle().pathForResource("DemoWorkbook", ofType: "xlsx")!
let spreadsheet: BRAOfficeDocumentPackage = BRAOfficeDocumentPackage.open(documentPath)
let worksheet: BRAWorksheet = spreadsheet.workbook.worksheets[0] as! BRAWorksheet
let string: String = worksheet.cellForCellReference("A1").stringValue()
print(string) // The Xcode console should now show the word "Alpha"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Verify:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With