Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function that returns formula for "definedName" #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
cmake_minimum_required(VERSION 3.2)

project(QtXlsxWriter)
add_definitions(-DQT_BUILD_XLSX_LIB)
set(BUILD_SHARED_LIBS TRUE)
set(CMAKE_AUTOMOC ON)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

file(
GLOB
QtXlsxWriter_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/xlsx/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/QtXlsxWriterTest_automoc.cpp
)

find_package(Qt5 5.5 REQUIRED Core Gui Test)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/xlsx/
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Gui_PRIVATE_INCLUDE_DIRS} )

add_library(QtXlsxWriter SHARED "${QtXlsxWriter_SOURCE_FILES}")

# automatically add C++11 support with GCC
if(NOT MSVC)
target_compile_features(QtXlsxWriter PRIVATE cxx_range_for)
endif()

set_target_properties(QtXlsxWriter PROPERTIES DEBUG_POSTFIX "d")
target_link_libraries(QtXlsxWriter ${Qt5Core_LIBRARIES})
target_link_libraries(QtXlsxWriter ${Qt5Gui_LIBRARIES})

if(BUILD_TESTING)
add_subdirectory(tests)
endif()

if(BUILD_EXAMPLES)
add_custom_command(TARGET QtXlsxWriter POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_directory $<CONFIGURATION> ${CMAKE_CURRENT_BINARY_DIR}/examples/xlsx/$<CONFIGURATION>)
add_subdirectory(examples/xlsx)
endif()

##
#
# QtxlsxwriterVersion.cmake creation
#
##
set(QtXlsxWriter_CONFIG_PATH ${CMAKE_INSTALL_PREFIX})
configure_file(QtXlsxWriterConfig.cmake.in QtXlsxWriterConfig.cmake @ONLY)

#####
#
# Installation configuration
#
#####
INSTALL(TARGETS QtXlsxWriter
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/QtXlsxWriterConfig.cmake DESTINATION lib/cmake/${PROJECT_NAME})

SET(INCLUDE_FILES
src/xlsx/xlsxabstractooxmlfile.h
src/xlsx/xlsxabstractsheet.h
src/xlsx/xlsxcell.h
src/xlsx/xlsxcellformula.h
src/xlsx/xlsxcellrange.h
src/xlsx/xlsxcellreference.h
src/xlsx/xlsxchart.h
src/xlsx/xlsxchartsheet.h
src/xlsx/xlsxconditionalformatting.h
src/xlsx/xlsxdatavalidation.h
src/xlsx/xlsxdocument.h
src/xlsx/xlsxformat.h
src/xlsx/xlsxglobal.h
src/xlsx/xlsxrichstring.h
src/xlsx/xlsxworkbook.h
src/xlsx/xlsxworksheet.h
)
INSTALL(FILES ${INCLUDE_FILES} DESTINATION include)

40 changes: 40 additions & 0 deletions QtXlsxWriterConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#########################################
#
# Cmake QtXlsxWriter configuration file
#
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# FIND_PACKAGE(QtXlsxWriter REQUIRED)
# TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${QtXlsxWriter_LIBS})
#
# This file will define the following variables:
#
# - QtXlsxWriter_BIN : The list of libraries to link against (.DLL, .SO).
# - QtXlsxWriter_LIBS : The list of libraries to link against (LIB, .A).
# - QtXlsxWriter_LIB_DIR : The directory(es) where lib files are. Calling LINK_DIRECTORIES
# with this path is NOT needed.
# - QtXlsxWriter_INCLUDE_DIRS : The QtXlsxWriter include directories (automatically added)
#
#########################################

if(CMAKE_VERSION VERSION_GREATER 2.6.2)
unset(QtXlsxWriter_CONFIG_PATH CACHE)
endif()

set(QtXlsxWriter_CONFIG_PATH "@QtXlsxWriter_CONFIG_PATH@")
set(QtXlsxWriter_FOUND TRUE CACHE BOOL "" FORCE)
set(QtXlsxWriter_LIBS QtXlsxWriter)
set(QtXlsxWriter_LIB_BIN ${QtXlsxWriter_CONFIG_PATH}/bin)
set(QtXlsxWriter_LIB_DIR ${QtXlsxWriter_CONFIG_PATH}/lib)
set(QtXlsxWriter_INCLUDE_DIRS ${QtXlsxWriter_CONFIG_PATH}/include)

include_directories(BEFORE ${QtXlsxWriter_INCLUDE_DIRS})

link_directories( ${LINK_DIRECTORIES} ${QtXlsxWriter_LIB_DIR} )

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args( QtXlsxWriter DEFAULT_MSG
QtXlsxWriter_LIBS QtXlsxWriter_INCLUDE_DIRS)

mark_as_advanced(FORCE QtXlsxWriter_LIBS QtXlsxWriter_LIB_DIR QtXlsxWriter_INCLUDE_DIRS)
50 changes: 50 additions & 0 deletions examples/xlsx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
find_package(Qt5 5.5 REQUIRED Core Gui Test Widgets)

set(EXAMPLES
calendar
chart
chartsheet
conditionalformatting
datavalidation
definename
demo
documentproperty
extractdata
formulas
hello
hyperlinks
image
mergecells
numberformat
richtext
rowcolumn
style
worksheetoperations
xlsxwidget)

# Compile each defined example
foreach(example IN ITEMS ${EXAMPLES})
if(DEBUG)
message("Create example '${example}'")
endif()
file( GLOB TEST_SRC ${example}/*.cpp)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../src/xlsx/
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${QtXlsxWriter_PRIVATE_SOURCE_FILES}
${CMAKE_CURRENT_BINARY_DIR} # .moc files
)

remove_definitions(-DQT_BUILD_XLSX_LIB)

add_executable(${example} ${TEST_SRC} )

target_link_libraries(${example} ${Qt5Widgets_LIBRARIES})
target_link_libraries(${example} ${Qt5Core_LIBRARIES})
target_link_libraries(${example} ${Qt5Gui_LIBRARIES})
target_link_libraries(${example} ${Qt5Test_LIBRARIES})
target_link_libraries(${example} QtXlsxWriter)

endforeach(example)
7 changes: 7 additions & 0 deletions src/xlsx/xlsxdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,13 @@ bool Document::defineName(const QString &name, const QString &formula, const QSt
return d->workbook->defineName(name, formula, comment, scope);
}

QString Document::getFormulaByDefineName(const QString &definedName, const QString &scope)
{
Q_D(Document);

return d->workbook->getFormulaByDefineName(definedName, scope);
}

/*!
Return the range that contains cell data.
*/
Expand Down
1 change: 1 addition & 0 deletions src/xlsx/xlsxdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class Q_XLSX_EXPORT Document : public QObject
Cell *cellAt(int row, int col) const;

bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString());
QString getFormulaByDefineName(const QString &definedName, const QString &scope=QString());

CellRange dimension() const;

Expand Down
4 changes: 2 additions & 2 deletions src/xlsx/xlsxformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,8 @@ bool Format::hasProtectionData() const
if (!d)
return false;

if (hasProperty(FormatPrivate::P_Protection_Hidden
|| FormatPrivate::P_Protection_Locked)) {
if (hasProperty(FormatPrivate::P_Protection_Hidden)
|| hasProperty(FormatPrivate::P_Protection_Locked)) {
return true;
}
return false;
Expand Down
25 changes: 25 additions & 0 deletions src/xlsx/xlsxworkbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ bool Workbook::defineName(const QString &name, const QString &formula, const QSt
return true;
}

QString Workbook::getFormulaByDefineName(const QString &definedName, const QString &scope)
{
Q_D(Workbook);

int id=-1;
if (!scope.isEmpty()) {
for (int i=0; i<d->sheets.size(); ++i) {
if (d->sheets[i]->sheetName() == scope) {
id = d->sheets[i]->sheetId();
break;
}
}
}

foreach (XlsxDefineNameData definedNameData, d->definedNamesList) {
if (definedNameData.name == definedName and definedNameData.sheetId == id)
return definedNameData.formula;
}
return "";
}

AbstractSheet *Workbook::addSheet(const QString &name, AbstractSheet::SheetType type)
{
Q_D(Workbook);
Expand Down Expand Up @@ -228,6 +249,10 @@ AbstractSheet *Workbook::insertSheet(int index, const QString &name, AbstractShe
{
Q_D(Workbook);
QString sheetName = createSafeSheetName(name);
if(index > d->last_sheet_id){
//User tries to insert, where no sheet has gone before.
return 0;
}
if (!sheetName.isEmpty()) {
//If user given an already in-used name, we should not continue any more!
if (d->sheetNames.contains(sheetName))
Expand Down
1 change: 1 addition & 0 deletions src/xlsx/xlsxworkbook.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Q_XLSX_EXPORT Workbook : public AbstractOOXmlFile

// void addChart();
bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString());
QString getFormulaByDefineName(const QString &definedName, const QString &scope=QString());
bool isDate1904() const;
void setDate1904(bool date1904);
bool isStringsToNumbersEnabled() const;
Expand Down
4 changes: 4 additions & 0 deletions src/xlsx/xlsxzipreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ ZipReader::~ZipReader()

void ZipReader::init()
{
#if QT_VERSION >= 0x050600
QVector<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();
#else
QList<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();
#endif
foreach (const QZipReader::FileInfo &fi, allFiles) {
if (fi.isFile)
m_filePaths.append(fi.filePath);
Expand Down
3 changes: 3 additions & 0 deletions src/xlsx/xlsxzipreader_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include "xlsxglobal.h"
#include <QScopedPointer>
#include <QStringList>
#if QT_VERSION >= 0x050600
#include <QVector>
#endif
class QZipReader;
class QIODevice;

Expand Down
63 changes: 63 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# create a test-enabled library before creating tests
# themselves (export more functions than regular DLL)
#

# Create a fake private/ include folder
# in the compilation tree to allow the
# #include "private/..." instruction to
# work
set(
QtXlsxWriter_PRIVATE_SOURCE_FILES
${CMAKE_CURRENT_BINARY_DIR}/include)

if(DEBUG)
message("Private include directory : ${QtXlsxWriter_PRIVATE_SOURCE_FILES}")
endif()
file(MAKE_DIRECTORY "${QtXlsxWriter_PRIVATE_SOURCE_FILES}/private")

# Copy all private includes in the created folder
file(GLOB private_includes ${CMAKE_CURRENT_SOURCE_DIR}/../src/xlsx/*_p.h)
foreach(private_include ${private_includes})
if(DEBUG)
message("Copying private include : ${private_include}")
endif()
file(COPY ${private_include} DESTINATION ${QtXlsxWriter_PRIVATE_SOURCE_FILES}/private)
endforeach()

set(CMAKE_AUTOMOC ON)

file(
GLOB
QtXlsxWriterTest_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/../src/xlsx/*.cpp
${CMAKE_CURRENT_BINARY_DIR}/QtXlsxWriter_automoc.cpp
)

include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
)

add_definitions(-DQT_BUILD_XLSX_LIB)
add_definitions(-DXLSX_TEST)
add_library(QtXlsxWriterTest SHARED "${QtXlsxWriterTest_SOURCE_FILES}")

# automatically add C++11 support with GCC
if(NOT MSVC)
target_compile_features(QtXlsxWriterTest PRIVATE cxx_range_for)
endif()


set_target_properties(QtXlsxWriterTest PROPERTIES DEBUG_POSTFIX "d")

target_link_libraries(QtXlsxWriterTest ${Qt5Core_LIBRARIES})
target_link_libraries(QtXlsxWriterTest ${Qt5Gui_LIBRARIES})

add_custom_command(TARGET QtXlsxWriterTest POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_directory $<CONFIGURATION> auto/$<CONFIGURATION>)

add_subdirectory(auto)
51 changes: 51 additions & 0 deletions tests/auto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
set(TESTS
cellreference
document
format
propsapp
propscore
relationships
richstring
sharedstrings
styles
utility
worksheet
xlsxconditionalformatting
zipreader)

enable_testing()

# Compile each defined test and
# declare it for ctest tool
foreach(test IN ITEMS ${TESTS})
if(DEBUG)
message("configure test '${test}'")
endif()
file( GLOB TEST_SRC ${test}/*.cpp)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../src/xlsx/
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${QtXlsxWriter_PRIVATE_SOURCE_FILES}
${CMAKE_CURRENT_BINARY_DIR} # .moc files
)

add_definitions(-DXLSX_TEST)
remove_definitions(-DQT_BUILD_XLSX_LIB)

add_executable(${test}_testDriver ${TEST_SRC} )

# automatically add C++11 support with GCC
if(NOT MSVC)
target_compile_features(${test}_testDriver PRIVATE cxx_range_for)
endif()


target_link_libraries(${test}_testDriver ${Qt5Core_LIBRARIES})
target_link_libraries(${test}_testDriver ${Qt5Gui_LIBRARIES})
target_link_libraries(${test}_testDriver ${Qt5Test_LIBRARIES})
target_link_libraries(${test}_testDriver QtXlsxWriterTest)

add_test(NAME ${test} COMMAND ${test}_testDriver)

endforeach(test)