mirror of
https://github.com/troldal/OpenXLSX.git
synced 2025-05-09 02:11:09 +08:00
Continued development of Python interface.
This commit is contained in:
parent
cf22cb0b7b
commit
02b2d5ec51
8
.gitignore
vendored
8
.gitignore
vendored
@ -7,4 +7,10 @@
|
||||
|
||||
# Visual Studio
|
||||
.vs/
|
||||
out/
|
||||
out/
|
||||
|
||||
# other
|
||||
*.so
|
||||
*.dylib
|
||||
*.a
|
||||
*.xlsx
|
@ -150,6 +150,12 @@ namespace OpenXLSX
|
||||
*/
|
||||
void set(const std::string& hexCode);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @return
|
||||
*/
|
||||
uint8_t alpha() const;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @return
|
||||
|
@ -115,6 +115,14 @@ void XLColor::set(const std::string& hexCode)
|
||||
m_blue = static_cast<uint8_t>(stoul(blue, nullptr, 16));
|
||||
}
|
||||
|
||||
/**
|
||||
* @details
|
||||
*/
|
||||
uint8_t XLColor::alpha() const
|
||||
{
|
||||
return m_alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* @details
|
||||
*/
|
||||
|
@ -10,7 +10,10 @@ set(PYOPENXLSX_SOURCES
|
||||
${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
|
||||
)
|
||||
@ -22,4 +25,10 @@ target_link_libraries(pyOpenXLSX PRIVATE OpenXLSX-static)
|
||||
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}
|
||||
)
|
||||
|
||||
|
||||
|
13
python/examples/Demo1.py
Normal file
13
python/examples/Demo1.py
Normal file
@ -0,0 +1,13 @@
|
||||
import OpenXLSX
|
||||
|
||||
doc = OpenXLSX.XLDocument()
|
||||
doc.create('Demo1.xlsx')
|
||||
wks = doc.workbook().worksheet('Sheet1')
|
||||
|
||||
wks.cell(OpenXLSX.XLCellReference('A1')).value().setFloat(3.14159)
|
||||
wks.cell(OpenXLSX.XLCellReference('B1')).value().setInteger(42)
|
||||
wks.cell(OpenXLSX.XLCellReference('C1')).value().setString(' Hello OpenXLSX! ')
|
||||
wks.cell(OpenXLSX.XLCellReference('D1')).value().setBoolean(True)
|
||||
wks.cell(OpenXLSX.XLCellReference('E1')).value().setString(wks.cell(OpenXLSX.XLCellReference('C1')).value().getString())
|
||||
|
||||
doc.save()
|
@ -6,28 +6,35 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void init_XLCell(py::module &m);
|
||||
void init_XLCellRange(py::module &m);
|
||||
void init_XLCellReference(py::module &m);
|
||||
void init_XLCellValue(py::module &m);
|
||||
void init_XLChartsheet(py::module &m);
|
||||
void init_XLDocument(py::module &m);
|
||||
void init_XLProperty(py::module &m);
|
||||
void init_XLSheet(py::module &m);
|
||||
void init_XLSheetState(py::module &m);
|
||||
void init_XLSheetType(py::module &m);
|
||||
void init_XLValueType(py::module &m);
|
||||
void init_XLWorkbook(py::module &m);
|
||||
void init_XLWorksheet(py::module &m);
|
||||
void init_XLCell(py::module& m);
|
||||
void init_XLCellRange(py::module& m);
|
||||
void init_XLCellReference(py::module& m);
|
||||
void init_XLCellValue(py::module& m);
|
||||
void init_XLChartsheet(py::module& m);
|
||||
void init_XLColor(py::module& m);
|
||||
void init_XLColumn(py::module& m);
|
||||
void init_XLDocument(py::module& m);
|
||||
void init_XLProperty(py::module& m);
|
||||
void init_XLRow(py::module& m);
|
||||
void init_XLSheet(py::module& m);
|
||||
void init_XLSheetState(py::module& m);
|
||||
void init_XLSheetType(py::module& m);
|
||||
void init_XLValueType(py::module& m);
|
||||
void init_XLWorkbook(py::module& m);
|
||||
void init_XLWorksheet(py::module& m);
|
||||
|
||||
PYBIND11_MODULE(OpenXLSX, m) {
|
||||
PYBIND11_MODULE(OpenXLSX, m)
|
||||
{
|
||||
init_XLCell(m);
|
||||
init_XLCellRange(m);
|
||||
init_XLCellReference(m);
|
||||
init_XLCellValue(m);
|
||||
init_XLChartsheet(m);
|
||||
init_XLColor(m);
|
||||
init_XLColumn(m);
|
||||
init_XLDocument(m);
|
||||
init_XLProperty(m);
|
||||
init_XLRow(m);
|
||||
init_XLSheet(m);
|
||||
init_XLSheetState(m);
|
||||
init_XLSheetType(m);
|
||||
|
26
python/pyXLColor.cpp
Normal file
26
python/pyXLColor.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Kenneth Balslev on 14/08/2020.
|
||||
//
|
||||
|
||||
#include <XLColor.hpp>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace OpenXLSX;
|
||||
|
||||
void init_XLColor(py::module& m)
|
||||
{
|
||||
py::class_<XLColor>(m, "XLColor")
|
||||
.def(py::init<>())
|
||||
.def(py::init<uint8_t, uint8_t, uint8_t, uint8_t>())
|
||||
.def(py::init<uint8_t, uint8_t, uint8_t>())
|
||||
.def(py::init<const std::string&>())
|
||||
.def("set", py::overload_cast<uint8_t, uint8_t, uint8_t, uint8_t>(&XLColor::set))
|
||||
.def("set", py::overload_cast<uint8_t, uint8_t, uint8_t>(&XLColor::set))
|
||||
.def("set", py::overload_cast<const std::string&>(&XLColor::set))
|
||||
.def("red", &XLColor::alpha)
|
||||
.def("red", &XLColor::red)
|
||||
.def("green", &XLColor::green)
|
||||
.def("blue", &XLColor::blue)
|
||||
.def("blue", &XLColor::hex);
|
||||
}
|
18
python/pyXLColumn.cpp
Normal file
18
python/pyXLColumn.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by Kenneth Balslev on 14/08/2020.
|
||||
//
|
||||
|
||||
#include <XLColumn.hpp>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace OpenXLSX;
|
||||
|
||||
void init_XLColumn(py::module& m)
|
||||
{
|
||||
py::class_<XLColumn>(m, "XLColumn")
|
||||
.def("width", &XLColumn::width)
|
||||
.def("setWidth", &XLColumn::setWidth)
|
||||
.def("isHidden", &XLColumn::isHidden)
|
||||
.def("setHidden", &XLColumn::setHidden);
|
||||
}
|
22
python/pyXLRow.cpp
Normal file
22
python/pyXLRow.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by Kenneth Balslev on 14/08/2020.
|
||||
//
|
||||
|
||||
#include <XLRow.hpp>
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace OpenXLSX;
|
||||
|
||||
void init_XLRow(py::module& m)
|
||||
{
|
||||
py::class_<XLRow>(m, "XLRow")
|
||||
.def("height", &XLRow::height)
|
||||
.def("setHeight", &XLRow::setHeight)
|
||||
.def("descent", &XLRow::descent)
|
||||
.def("setDescent", &XLRow::setDescent)
|
||||
.def("isHidden", &XLRow::isHidden)
|
||||
.def("setHidden", &XLRow::setHidden)
|
||||
.def("rowNumber", &XLRow::rowNumber)
|
||||
.def("cellCount", &XLRow::cellCount);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user