C++读取某个excel单元格,通过OpenXLSX实现 | 您所在的位置:网站首页 › c读取excel导入资料 › C++读取某个excel单元格,通过OpenXLSX实现 |
下载OpenXLSX
可以自己去GitHub下载,也可以下载我当前使用的版本,下载链接:OpenXLSA 文件提取 解压后,只需要OpenXLSX里的OpenXLSX文件,即不需要示例等,如下图把上述文件的文件夹拷贝到项目根目录下 配置工程我这里使用的是Clion,只需要配置CMakeLists.txt就行,将下面内容粘贴到你的CMakeLists.txt中 # Set the build output location to a common directory set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) add_subdirectory(OpenXLSX) target_link_libraries(word_tool_v1_0 OpenXLSX::OpenXLSX)我的工程看起来下面这样的,可根据你自己实际配置 cmake_minimum_required(VERSION 3.25) project(word_tool_v1_0) set(CMAKE_CXX_STANDARD 17) # Set the build output location to a common directory set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) add_subdirectory(OpenXLSX) add_executable(word_tool_v1_0 main.cpp) target_link_libraries(word_tool_v1_0 OpenXLSX::OpenXLSX) 读取 过程大致分为打开文件和读取指定单元格 假设我要读取的单元格数据是int类型那么代码如下所示 #pragma warning(push) #pragma warning(disable : 4244) #include #include #include #include #include #include #include #include #include using namespace std; using namespace OpenXLSX; int main() { cout |
CopyRight 2018-2019 实验室设备网 版权所有 |