C++ Excel库使用记录

1 xlnt

xlnt:地址 xlnt: xlnt是一个现代的C ++库,用于处理内存中的电子表格,并按照ECMA 376第4版的说明从XLSX文件读取/写入

要求标准 C++14,由于公司项目环境为qt +vs2010,环境版本太低不支持,因此未使用,期间查询时,发现网上评价可观,手册和使用教程也教容易找到,以后条件满足时使用。

2 xlslib

xlslib:xlsLib download | SourceForge.net

2.1 动态链接库项目 xlslib_dll的编译

编译,会出现sheet_notes的错误。sheet_notes 非法重定义,或构造函数不能返回类型。

这个错误的原因是,结构体sheet_notes的类型名称和变量命令相同了。由于C/C++中,结构体可以有构造函数,所以,这两个名称是不能相同的。编译器会将成员变量当成是构造函数,从而报错。

解决办法是,修改其中一个的名字,只要两个不相同就ok。由于成员变量sheet_notes被用到只有3次,而结构体被用到很多次。于是,修改成员变量。

xlslib在window下编译方法_第3张图片

再编译,还会提示一个 function_property 的错误

这是由于使用了大括号初始化成员,导致编译错误

修改为如下代码:

xlslib在window下编译方法_第4张图片

再编译,修改以上两处错误后,在由于项目在“生成事件” --> "后期生成事件"的命令行参数中添加了 以下指令,导致编译错误;

echo $(SolutionDir)bin/Win32_MSVC2010.$(Configuration)\createDLL -M$(Platform) -n$(OutDir)$(ProjectName).map -l$(IntDir) -i$(OutDir)$(ProjectName).lib -W$(SolutionDir)obj/$(ProjectName)_$(Platform)_MSVC2010.$(Configuration)\
$(SolutionDir)bin/Win32_MSVC2010.$(Configuration)\createDLL -M$(Platform) -n$(OutDir)$(ProjectName).map -l$(IntDir) -i$(OutDir)$(ProjectName).lib -W$(SolutionDir)obj/$(ProjectName)_$(Platform)_MSVC2010.$(Configuration)\

删掉上面指令,就可以生成成功,但是由于未导出信息,在使用动态库文件时,会出现链接错误,暂未找到解决方案,也许可以自己添加导出声明;

2.2 静态链接库 xlslib_lib

此版本的此项目加载不成功,在输出窗口看到有个文件“formula.cpp”有两个,删除其中一个后加载成功,修改了动态链接库中的代码问题后,编译成功,经简单测试,可以使用。

3 SPLib 此库不支持读取Excel 

地址:GitHub - zhangf911/SPLib: Cross-Platform C++ Library for Creating Excel, Office 2007 xml Excel and Open Document Spreadsheet

此项目依赖ZLib,在网上找到windows 版本的库文件,导出了lib文件后生成了splib的库,还未测试使用,

由于此库不支持单元格合并,因此未使用;

最终采用2方案

4 libxl

libxl:C++ Excel Library to read/write xls/xlsx files - LibXL

5 QXlsx

QXlsx:GitHub - QtExcel/QXlsx: Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsx.

这是曾经做过的一个项目时写的一个动态,用c++来操作Excel,包括以下功能: //===================================mainly function============================ //FuncName: xls_create //function: create excel server //return value: return 1 if success, otherwise 0 _export bool xls_create(); //FuncName: xls_new_file/xls_new_file2 //function: create an excel file (from a template) //parameter: strTemplate ->excel template file name,eg: "template.xlt" or "d:\teplate.xls" // strFileName ->the file name used to save excel file as,eg: "Temp.xls" // openfile ->1: open excel file after writen it,otherwize don't open it //return value: return the excel fileID which created from template, between 1 and 256 if success, or zero otherwise _export int xls_new_file(char* szTemplate, char* szFileName, int openfile); _export int xls_new_file2(char* szFileName, int openfile); //FuncName: xls_open_file //function: Open an exist excel file //parameter:the file name will to be opened //return value: return the fileID, if open file success,otherwize return 0 _export int xls_open_file(char* szFileName); //FuncName: xls_write_xxx //function: write a double value to xls file //parameter: fileID ->the excel file ID which we will write the value into,between 1 and 256 // sheetID ->the sheet index of the excel file which we will write the value into,between 1 and 256 // crow ->the row index which we will write the value into, not less 1 // ccol ->the column index which we will write the value into, not less 1 // value ->the double value which we will write into excel //Note: if you want to input enter key in excel file,you may use \n in your str //return value: return 1 if success, otherwise 0 _export int xls_write_str(int fileID, int sheetID, int crow, int ccol, char* value); _export int xls_write_dbl(int fileID, int sheetID, int crow, int ccol, double value); _export int xls_write_int(int fileID, int sheetID, int crow, int
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值