troldal / OpenXLSX

A C++ library for reading, writing, creating and modifying Microsoft Excel® (.xlsx) files.
BSD 3-Clause "New" or "Revised" License
1.32k stars 312 forks source link

Python support totally broken #153

Open WangZhihua1998 opened 2 years ago

WangZhihua1998 commented 2 years ago

My build environments: cmake 3.23.0 msvc 19.29.30141

I build and installed OpenXLSX (64 bit), and when I tried to build OpenXLSX python bindings, it told me that the compiler cannot find headers. This My CMakeList.txt

cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(OpenXLSX.Python)

find_package(OpenXLSX COMPONENTS OpenXLSX REQUIRED)
if (OpenXLSX_FOUND)
message("OpenXLSX_FOUND")
else()
message("OpenXLSX_NOT_FOUND")
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    set(PYBIND11_CPP_STANDARD /std:c++17)
else()
    set(PYBIND11_CPP_STANDARD -std=c++1z)
endif()

add_subdirectory(pybind11)

set(PYOPENXLSX_SOURCES
    ${CMAKE_CURRENT_LIST_DIR}/pyOpenXLSX.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLCell.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLCellRange.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLCellReference.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLCellValue.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLColor.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLColumn.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLDocument.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLRow.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLSheet.cpp
    ${CMAKE_CURRENT_LIST_DIR}/pyXLWorkbook.cpp
    )

pybind11_add_module(pyOpenXLSX ${PYOPENXLSX_SOURCES})

# ===== Target using static library ===== #
target_link_libraries(pyOpenXLSX PRIVATE OpenXLSX::OpenXLSX)
#target_compile_definitions(pyOpenXLSX PRIVATE OPENXLSX_STATIC_DEFINE)
set_target_properties(pyOpenXLSX PROPERTIES OUTPUT_NAME OpenXLSX)

get_property(pyOpenXLSXSuffix TARGET pyOpenXLSX PROPERTY SUFFIX)
add_custom_command(TARGET pyOpenXLSX POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyOpenXLSX>
                   ${CMAKE_CURRENT_LIST_DIR}/../examples/OpenXLSX${pyOpenXLSXSuffix}
                   )

To solve this problem, I changed #include<XL****.hpp> to #include . This time the compiler was able to find headers, but the build still faild. It complained that error C2039: "getValue": is not a member of "OpenXLSX::XLCell" blah blah blah.

It seem that the python binding is outdated and may need some updates.

SimantoR commented 1 year ago

I actually have a solution made using setup.py and pyproject.toml which seems to be working as well. If @troldal is willing to accept that in, it might be helpful since the support is broken anyway at the moment.