版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qin_shi/article/details/82772668
需求
项目中需要把数据写入Excel表格中。
引入流程
- 下载Excel的开发包 http://www.libxl.com/download.html
- 把下载的LibXL.framework文件放入xcode工程中
- 修改xcode的配置信息
BitCode为No,Other Linker Flages 追加-lstdc++ - 桥接文件引入头文件
#import <LibXL/libxl.h>
初步实现
let book = xlCreateXMLBookCA()
let sheet = xlBookAddSheetA(book, "sheet1", nil)
let boldFormat = FormatHandle.init(bitPattern: 0)
//生成第一行第一列的数据,命名为“id”
xlSheetWriteStrA(sheet, 1, 0, "id", boldFormat)
。。。。。。。
//获取保存路径
let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let jsonPath = (docDir as NSString).appendingPathComponent("Letters.xlsx")
print("excel::: \(jsonPath)")
//保存表格
xlBookSaveA(book, jsonPath.cString(using: .utf8))
xlBookReleaseA(book)
这个开发库是收费的,生成的项目里会第一行会追加一行数据