├── .github └── workflows │ └── xlsxio.yml ├── .gitignore ├── .travis.yml ├── CMake ├── FindLibZip.cmake └── FindMinizip.cmake ├── CMakeLists.txt ├── Changelog.txt ├── LICENSE.txt ├── Makefile ├── README.md ├── build ├── _cmake_build_.sh ├── _test2_.cbp ├── _test_.cbp ├── example_xlsxio_read.cbp ├── example_xlsxio_read.depend ├── example_xlsxio_read_advanced.cbp ├── example_xlsxio_read_advanced.depend ├── example_xlsxio_read_cpp.cbp ├── example_xlsxio_read_cpp.depend ├── example_xlsxio_read_wchar.cbp ├── example_xlsxio_read_wchar.depend ├── example_xlsxio_write.cbp ├── example_xlsxio_write.depend ├── example_xlsxio_write_cpp.cbp ├── example_xlsxio_write_cpp.depend ├── example_xlsxio_write_getversion.cbp ├── example_xlsxio_write_getversion.depend ├── libxlsxio_read.cbp ├── libxlsxio_read.depend ├── libxlsxio_read_minizip_shared.cbp ├── libxlsxio_read_minizip_shared.depend ├── libxlsxio_read_shared.cbp ├── libxlsxio_read_shared.depend ├── libxlsxio_read_wchar.cbp ├── libxlsxio_read_wchar.depend ├── libxlsxio_read_wchar_shared.cbp ├── libxlsxio_read_wchar_shared.depend ├── libxlsxio_write.cbp ├── libxlsxio_write.depend ├── libxlsxio_write_minizip_shared.cbp ├── libxlsxio_write_minizip_shared.depend ├── libxlsxio_write_shared.cbp ├── libxlsxio_write_shared.depend ├── libxlsxio_write_wchar.cbp ├── libxlsxio_write_wchar.depend ├── libxlsxio_write_wchar_shared.cbp ├── libxlsxio_write_wchar_shared.depend ├── test1.cbp ├── test2.cbp ├── test2.workspace ├── test3.cbp ├── test3.workspace ├── xlsxio.workspace ├── xlsxio_csv2xlsx.cbp ├── xlsxio_csv2xlsx.depend ├── xlsxio_read.cbp ├── xlsxio_write.cbp ├── xlsxio_xlsx2csv.cbp └── xlsxio_xlsx2csv.depend ├── buildbin.sh ├── doc └── Doxyfile ├── examples ├── example_xlsxio_read.c ├── example_xlsxio_read_advanced.c ├── example_xlsxio_read_cpp.cpp ├── example_xlsxio_write.c ├── example_xlsxio_write_cpp.cpp └── example_xlsxio_write_getversion.c ├── include ├── xlsxio_read.h ├── xlsxio_version.h └── xlsxio_write.h ├── lib ├── xlsxio_private.h ├── xlsxio_read.c ├── xlsxio_read_sharedstrings.c ├── xlsxio_read_sharedstrings.h └── xlsxio_write.c ├── src ├── xlsxio_csv2xlsx.c ├── xlsxio_read_main.c ├── xlsxio_write_main.c └── xlsxio_xlsx2csv.c ├── template.pc.in ├── templateConfig.cmake.in └── templateConfigVersion.cmake.in /.github/workflows/xlsxio.yml: -------------------------------------------------------------------------------- 1 | name: GitHub-CI for xlsxio 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | fail-fast: false # if a job fails don't abort other jobs 13 | matrix: 14 | config: 15 | - { 16 | name: "Windows 64-bit (gcc)", 17 | os: windows-latest, 18 | shell: "msys2 {0}", 19 | msystem: MINGW64, 20 | arch: x86_64, 21 | cc: x86_64-w64-mingw32-gcc.exe, 22 | cxx: x86_64-w64-mingw32-g++.exe, 23 | makeargs: "WITH_LIBZIP=1" 24 | } 25 | - { 26 | name: "Windows 32-bit (gcc)", 27 | os: windows-latest, 28 | shell: "msys2 {0}", 29 | msystem: MINGW32, 30 | arch: i686, 31 | cc: i686-w64-mingw32-gcc.exe, 32 | cxx: i686-w64-mingw32-g++.exe, 33 | makeargs: "WITH_LIBZIP=1" 34 | } 35 | - { 36 | name: "Ubuntu Linux (clang)", 37 | os: ubuntu-latest, 38 | shell: bash, 39 | arch: x86_64, 40 | cc: clang, 41 | cxx: clang++, 42 | makeargs: "WIDE=1" 43 | } 44 | - { 45 | name: "macOS (clang)", 46 | os: macos-latest, 47 | shell: bash, 48 | arch: x86_64, 49 | cc: clang, 50 | cxx: clang++, 51 | makeargs: "" 52 | } 53 | name: ${{ matrix.config.name }} 54 | runs-on: ${{ matrix.config.os }} 55 | defaults: 56 | run: 57 | shell: ${{ matrix.config.shell }} 58 | env: 59 | CC: ${{ matrix.config.cc }} 60 | CXX: ${{ matrix.config.cxx }} 61 | 62 | steps: 63 | - if: matrix.config.os == 'windows-latest' 64 | name: Install build dependencies (Windows/MSYS) 65 | uses: msys2/setup-msys2@v2 66 | with: 67 | update: false 68 | msystem: ${{ matrix.config.msystem }} 69 | install: >- 70 | git 71 | make 72 | zip 73 | mingw-w64-${{ matrix.config.arch }}-toolchain 74 | mingw-w64-${{ matrix.config.arch }}-ninja 75 | mingw-w64-${{ matrix.config.arch }}-cmake 76 | mingw-w64-${{ matrix.config.arch }}-expat 77 | mingw-w64-${{ matrix.config.arch }}-minizip-git 78 | mingw-w64-${{ matrix.config.arch }}-libzip 79 | - if: matrix.config.os == 'ubuntu-latest' 80 | name: Install build dependencies (Linux) 81 | run: | 82 | sudo apt-get install \ 83 | zip \ 84 | cmake \ 85 | ninja-build \ 86 | libexpat1-dev \ 87 | libminizip-dev \ 88 | libzip-dev 89 | - if: matrix.config.os == 'macos-latest' 90 | name: Install build dependencies (macOS) 91 | run: | 92 | brew install \ 93 | zip \ 94 | ninja \ 95 | expat \ 96 | minizip \ 97 | libzip 98 | find /opt/homebrew/ -name unzip.h 99 | - uses: actions/checkout@v1 100 | - name: Build 101 | run: | 102 | PKG_CONFIG_PATH=$PWD/deps/lib/pkgconfig:/usr/local/opt/libarchive/lib/pkgconfig:$PKG_CONFIG_PATH \ 103 | make install \ 104 | PREFIX=$PWD/release \ 105 | ${{ matrix.config.makeargs }} \ 106 | CFLAGS="-O3 -I$PWD/deps/include -I/usr/local/opt/libarchive/include -I/opt/homebrew/Cellar/minizip/1.3.1/include" \ 107 | LDFLAGS="-L$PWD/deps/lib -L/usr/local/opt/libarchive/lib -L/opt/homebrew/Cellar/minizip/1.3.1/lib" 108 | #- if: matrix.config.os == 'windows-latest' 109 | # name: Build package 110 | # run: | 111 | # PKG_CONFIG_PATH=$PWD/deps/lib/pkgconfig:/usr/local/opt/libarchive/lib/pkgconfig:$PKG_CONFIG_PATH \ 112 | # make binarypackage \ 113 | # STATIC=1 \ 114 | # CFLAGS="-I$PWD/deps/include -I/usr/local/opt/libarchive/include" \ 115 | # LDFLAGS="-L$PWD/deps/lib -L/usr/local/opt/libarchive/lib" 116 | # mv xlsxio-*.zip xlsxio-${{ matrix.config.arch }}.zip 117 | #- if: matrix.config.os == 'windows-latest' 118 | # name: Upload package 119 | # uses: actions/upload-artifact@v1 120 | # with: 121 | # path: ./release 122 | # name: xlsxio-${{ matrix.config.arch }}.zip 123 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .svn/ 4 | *.xlsx 5 | *.csv 6 | *.zip 7 | *.7z 8 | *.xz 9 | *.layout 10 | *.depend 11 | *.URL 12 | *.a 13 | *.so 14 | *.bak 15 | version 16 | obj/ 17 | bin/ 18 | doc/ 19 | CMakeFiles/ 20 | cmake-build-debug 21 | /Makefile 22 | example_xlsxio_read 23 | example_xlsxio_read_advanced 24 | example_xlsxio_write 25 | example_xlsxio_write_getversion 26 | xlsxio_csv2xlsx 27 | xlsxio_xlsx2csv 28 | example.xlsx* 29 | build_win/ 30 | DELETEME/ 31 | xlsxio_f/ 32 | ODS/ 33 | issues/ 34 | community/ 35 | build/*.csv 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | jobs: 3 | include: 4 | - name: "Linux GCC" 5 | os: linux 6 | compiler: gcc 7 | - name: "Linux Clang" 8 | os: linux 9 | compiler: clang 10 | - name: "Mac OS X Clang" 11 | os: osx 12 | compiler: clang 13 | 14 | addons: 15 | apt: 16 | packages: 17 | - libexpat1-dev 18 | - libminizip-dev 19 | homebrew: 20 | packages: 21 | - expat 22 | - minizip 23 | # - minizip2 24 | update: true 25 | 26 | script: 27 | # - make install CC=$CC PREFIX=$(pwd)/build_result 28 | - mkdir -p buildall build_result 29 | - cd buildall 30 | - cmake -Wno-dev -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/../build_result -DCMAKE_BUILD_TYPE:STRING=Release -DWITH_LIBZIP:BOOL=OFF .. 31 | - cd .. 32 | - make -Cbuildall install/strip 33 | -------------------------------------------------------------------------------- /CMake/FindLibZip.cmake: -------------------------------------------------------------------------------- 1 | FIND_PACKAGE(ZLIB) 2 | 3 | IF(LIBZIP_DIR) 4 | FIND_PATH(LIBZIP_INCLUDE_DIR_zh NAMES zip.h NO_DEFAULT_PATH PATHS ${LIBZIP_DIR}/include ${LIBZIP_DIR}) 5 | FIND_PATH(LIBZIP_INCLUDE_DIR_zch NAMES zipconf.h NO_DEFAULT_PATH PATHS ${LIBZIP_DIR}/lib/libzip/include ${LIBZIP_DIR}/include ${LIBZIP_DIR}) 6 | FIND_LIBRARY(LIBZIP_LIBRARY NAMES zip NO_DEFAULT_PATH PATHS ${LIBZIP_DIR}/lib ${LIBZIP_DIR}) 7 | ELSE() 8 | FIND_PATH(LIBZIP_INCLUDE_DIR_zh NAMES zip.h PATHS /include /usr/include /usr/local/include /opt/local/include) 9 | FIND_PATH(LIBZIP_INCLUDE_DIR_zch NAMES zipconf.h PATHS /lib/libzip/include /usr/lib/libzip/include /usr/local/lib/libzip/include /opt/local/lib/libzip/include /include /usr/include /usr/local/include /opt/local/include) 10 | FIND_LIBRARY(LIBZIP_LIBRARY NAMES zip) 11 | ENDIF() 12 | 13 | IF (LIBZIP_INCLUDE_DIR_zh AND LIBZIP_INCLUDE_DIR_zch AND LIBZIP_LIBRARY) 14 | SET(LIBZIP_INCLUDE_DIRS "${LIBZIP_INCLUDE_DIR_zh};${LIBZIP_INCLUDE_DIR_zch};${ZLIB_INCLUDE_DIRS}") 15 | SET(LIBZIP_LIBRARIES ${LIBZIP_LIBRARY} ${ZLIB_LIBRARIES}) 16 | SET(LIBZIP_FOUND true) 17 | ENDIF() 18 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibZip DEFAULT_MSG LIBZIP_LIBRARIES LIBZIP_INCLUDE_DIRS) 19 | -------------------------------------------------------------------------------- /CMake/FindMinizip.cmake: -------------------------------------------------------------------------------- 1 | FIND_PACKAGE(ZLIB) 2 | 3 | IF(MINIZIP_DIR) 4 | FIND_PATH(MINIZIP_INCLUDE_DIR_zh NAMES minizip/zip.h NO_DEFAULT_PATH PATHS ${MINIZIP_DIR}/include ${MINIZIP_DIR}) 5 | FIND_PATH(MINIZIP_INCLUDE_DIR_unzh NAMES minizip/unzip.h NO_DEFAULT_PATH PATHS ${MINIZIP_DIR}/include ${MINIZIP_DIR}) 6 | FIND_LIBRARY(MINIZIP_LIBRARY NAMES minizip NO_DEFAULT_PATH PATHS ${MINIZIP_DIR}/lib ${MINIZIP_DIR}) 7 | ELSE() 8 | FIND_PATH(MINIZIP_INCLUDE_DIR_zh NAMES minizip/zip.h PATHS /include /usr/include /usr/local/include /opt/local/include) 9 | FIND_PATH(MINIZIP_INCLUDE_DIR_unzh NAMES minizip/unzip.h PATHS /include /usr/include /usr/local/include /opt/local/include) 10 | FIND_LIBRARY(MINIZIP_LIBRARY NAMES minizip) 11 | ENDIF() 12 | 13 | IF (MINIZIP_INCLUDE_DIR_unzh AND MINIZIP_INCLUDE_DIR_zh AND MINIZIP_LIBRARY) 14 | SET(MINIZIP_INCLUDE_DIRS "${MINIZIP_INCLUDE_DIR_unzh};${MINIZIP_INCLUDE_DIR_zh};${ZLIB_INCLUDE_DIRS}") 15 | SET(MINIZIP_LIBRARIES ${MINIZIP_LIBRARY} ${ZLIB_LIBRARIES}) 16 | SET(MINIZIP_FOUND true) 17 | ENDIF() 18 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Minizip DEFAULT_MSG MINIZIP_LIBRARIES MINIZIP_INCLUDE_DIRS) 19 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # parameters: 2 | # PREFIX= Path were install places files (defaults to /usr/local) 3 | # WITH_LIBZIP=1 Use libzip instead of minizip 4 | # WIDE=1 Also build UTF-16 library (xlsxio_readw) - experimental, only tested on Windows 5 | # STATICDLL=1 Build a static DLL (= doesn't depend on any other DLLs) - only supported on Windows 6 | 7 | ifeq ($(OS),) 8 | OS = $(shell uname -s) 9 | endif 10 | PREFIX = /usr/local 11 | CC = gcc 12 | CPP = g++ 13 | AR = ar 14 | LIBPREFIX = lib 15 | LIBEXT = .a 16 | ifeq ($(OS),Windows_NT) 17 | BINEXT = .exe 18 | SOEXT = .dll 19 | else ifeq ($(OS),Darwin) 20 | BINEXT = 21 | SOEXT = .dylib 22 | else 23 | BINEXT = 24 | SOEXT = .so 25 | endif 26 | INCS = -Iinclude -Ilib 27 | CFLAGS = -O3 28 | override CFLAGS += $(INCS) 29 | STATIC_CFLAGS = -DBUILD_XLSXIO_STATIC 30 | SHARED_CFLAGS = -DBUILD_XLSXIO_DLL 31 | LIBS = 32 | LDFLAGS = 33 | ifeq ($(OS),Darwin) 34 | override CFLAGS += -I/opt/local/include -I/opt/local/lib/libzip/include 35 | override LDFLAGS += -L/opt/local/lib 36 | #override CFLAGS += -arch i386 -arch x86_64 37 | #override LDFLAGS += -arch i386 -arch x86_64 38 | STRIPFLAG = 39 | else 40 | STRIPFLAG = -s 41 | endif 42 | MKDIR = mkdir -p 43 | RM = rm -f 44 | RMDIR = rm -rf 45 | CP = cp -f 46 | CPDIR = cp -rf 47 | DOXYGEN := $(shell which doxygen) 48 | 49 | OSALIAS := $(OS) 50 | ifeq ($(OS),Windows_NT) 51 | ifneq (,$(findstring x86_64,$(shell gcc --version))) 52 | OSALIAS := win64 53 | else 54 | OSALIAS := win32 55 | endif 56 | endif 57 | 58 | ifdef WITH_LIBZIP 59 | ZIPLIB_LDFLAGS = -lzip 60 | ZIPLIB_DEPS_LDFLAGS = -Wl,--as-needed -lz -lbz2 -lcrypto -lgdi32 61 | override CFLAGS += -DUSE_LIBZIP 62 | else 63 | ZIPLIB_LDFLAGS = -lminizip 64 | ZIPLIB_DEPS_LDFLAGS = -Wl,--as-needed -lz 65 | override CFLAGS += -DUSE_MINIZIP 66 | endif 67 | 68 | XLSXIOREAD_OBJ = lib/xlsxio_read.o lib/xlsxio_read_sharedstrings.o 69 | XLSXIOREAD_LDFLAGS = $(ZIPLIB_LDFLAGS) -lexpat 70 | XLSXIOREADW_LDFLAGS = $(ZIPLIB_LDFLAGS) -lexpatw 71 | XLSXIOREAD_SHARED_LDFLAGS = 72 | XLSXIOWRITE_OBJ = lib/xlsxio_write.o 73 | XLSXIOWRITE_LDFLAGS = $(ZIPLIB_LDFLAGS) 74 | XLSXIOWRITE_SHARED_LDFLAGS = 75 | ifneq ($(OS),Windows_NT) 76 | override SHARED_CFLAGS += -fPIC 77 | endif 78 | ifeq ($(OS),Windows_NT) 79 | XLSXIOREAD_SHARED_LDFLAGS += -Wl,--out-implib,$@$(LIBEXT) -Wl,--compat-implib -Wl,--output-def,$(@:%.dll=%.def) 80 | XLSXIOWRITE_SHARED_LDFLAGS += -Wl,--out-implib,$@$(LIBEXT) -Wl,--compat-implib -Wl,--output-def,$(@:%.dll=%.def) 81 | else ifeq ($(OS),Darwin) 82 | else 83 | XLSXIOWRITE_LDFLAGS += -pthread 84 | endif 85 | ifeq ($(OS),Darwin) 86 | OS_LINK_FLAGS = -dynamiclib -o $@ 87 | else 88 | OS_LINK_FLAGS = -shared -Wl,-soname,$@ $(STRIPFLAG) 89 | endif 90 | 91 | ifdef STATICDLL 92 | ifeq ($(OS),Windows_NT) 93 | # lines below to compile Windows DLLs with no dependencies 94 | ifdef WITH_LIBZIP 95 | override CFLAGS += -DZIP_STATIC 96 | endif 97 | XLSXIOREAD_LDFLAGS += -static $(ZIPLIB_DEPS_LDFLAGS) 98 | XLSXIOREADW_LDFLAGS += -static $(ZIPLIB_DEPS_LDFLAGS) 99 | XLSXIOWRITE_LDFLAGS += -static $(ZIPLIB_DEPS_LDFLAGS) 100 | endif 101 | endif 102 | 103 | LIBLIST = xlsxio_read xlsxio_write 104 | TOOLS_BIN = xlsxio_xlsx2csv$(BINEXT) xlsxio_csv2xlsx$(BINEXT) 105 | EXAMPLES_BIN = example_xlsxio_write_getversion$(BINEXT) example_xlsxio_write$(BINEXT) example_xlsxio_read$(BINEXT) example_xlsxio_read_advanced$(BINEXT) 106 | 107 | ifdef WIDE 108 | CFLAGS_W = $(CFLAGS) -DXML_UNICODE 109 | LIBLIST += xlsxio_readw 110 | EXAMPLES_BIN += example_xlsxio_readw$(BINEXT) 111 | endif 112 | 113 | COMMON_PACKAGE_FILES = README.md LICENSE.txt Changelog.txt 114 | SOURCE_PACKAGE_FILES = $(COMMON_PACKAGE_FILES) Makefile CMakeLists.txt CMake/ *.in doc/Doxyfile include/*.h lib/*.c lib/*.h src/*.c examples/*.c build/*.cbp 115 | 116 | default: all 117 | 118 | all: static-lib shared-lib tools 119 | 120 | %.o: %.c 121 | $(CC) -c -o $@ $< $(CFLAGS) 122 | 123 | %.static.o: %.c 124 | $(CC) -c -o $@ $< $(STATIC_CFLAGS) $(CFLAGS) 125 | 126 | %.shared.o: %.c 127 | $(CC) -c -o $@ $< $(SHARED_CFLAGS) $(CFLAGS) 128 | 129 | static-lib: $(LIBLIST:%=$(LIBPREFIX)%$(LIBEXT)) 130 | 131 | shared-lib: $(LIBLIST:%=$(LIBPREFIX)%$(SOEXT)) 132 | 133 | $(LIBPREFIX)xlsxio_read$(LIBEXT): $(XLSXIOREAD_OBJ:%.o=%.static.o) 134 | $(AR) cr $@ $^ 135 | 136 | $(LIBPREFIX)xlsxio_read$(SOEXT): $(XLSXIOREAD_OBJ:%.o=%.shared.o) 137 | $(CC) -o $@ $(OS_LINK_FLAGS) $^ $(XLSXIOREAD_SHARED_LDFLAGS) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS) $(LIBS) 138 | 139 | $(LIBPREFIX)xlsxio_write$(LIBEXT): $(XLSXIOWRITE_OBJ:%.o=%.static.o) 140 | $(AR) cr $@ $^ 141 | 142 | $(LIBPREFIX)xlsxio_write$(SOEXT): $(XLSXIOWRITE_OBJ:%.o=%.shared.o) 143 | $(CC) -o $@ $(OS_LINK_FLAGS) $^ $(XLSXIOWRITE_SHARED_LDFLAGS) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS) $(LIBS) 144 | 145 | ifdef WIDE 146 | %.wstatic.o: %.c 147 | $(CC) -c -o $@ $< $(STATIC_CFLAGS) $(CFLAGS_W) 148 | 149 | %.wshared.o: %.c 150 | $(CC) -c -o $@ $< $(SHARED_CFLAGS) $(CFLAGS_W) 151 | 152 | $(LIBPREFIX)xlsxio_readw$(LIBEXT): $(XLSXIOREAD_OBJ:%.o=%.wstatic.o) 153 | $(AR) cr $@ $^ 154 | 155 | $(LIBPREFIX)xlsxio_readw$(SOEXT): $(XLSXIOREAD_OBJ:%.o=%.wshared.o) 156 | $(CC) -o $@ $(OS_LINK_FLAGS) $^ $(XLSXIOREAD_SHARED_LDFLAGS) $(XLSXIOREADW_LDFLAGS) $(LIBS) 157 | endif 158 | 159 | examples: $(EXAMPLES_BIN) 160 | 161 | example_xlsxio_write_getversion$(BINEXT): examples/example_xlsxio_write_getversion.static.o $(LIBPREFIX)xlsxio_write$(LIBEXT) 162 | $(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_write$(LIBEXT) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS) 163 | 164 | example_xlsxio_write$(BINEXT): examples/example_xlsxio_write.static.o $(LIBPREFIX)xlsxio_write$(LIBEXT) 165 | $(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_write$(LIBEXT) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS) 166 | 167 | example_xlsxio_read$(BINEXT): examples/example_xlsxio_read.static.o $(LIBPREFIX)xlsxio_read$(LIBEXT) 168 | $(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_read$(LIBEXT) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS) 169 | 170 | example_xlsxio_read_advanced$(BINEXT): examples/example_xlsxio_read_advanced.static.o $(LIBPREFIX)xlsxio_read$(LIBEXT) 171 | $(CC) -o $@ examples/$(@:%$(BINEXT)=%.static.o) $(LIBPREFIX)xlsxio_read$(LIBEXT) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS) 172 | 173 | ifdef WIDE 174 | example_xlsxio_readw$(BINEXT): examples/example_xlsxio_read.wstatic.o $(LIBPREFIX)xlsxio_readw$(LIBEXT) 175 | $(CC) -o $@ examples/$(@:%w$(BINEXT)=%.wstatic.o) $(LIBPREFIX)xlsxio_readw$(LIBEXT) $(XLSXIOREADW_LDFLAGS) $(LDFLAGS) 176 | endif 177 | 178 | tools: $(TOOLS_BIN) 179 | 180 | xlsxio_xlsx2csv$(BINEXT): src/xlsxio_xlsx2csv.static.o $(LIBPREFIX)xlsxio_read$(LIBEXT) 181 | $(CC) -o $@ $< $(LIBPREFIX)xlsxio_read$(LIBEXT) $(XLSXIOREAD_LDFLAGS) $(LDFLAGS) 182 | 183 | xlsxio_csv2xlsx$(BINEXT): src/xlsxio_csv2xlsx.static.o $(LIBPREFIX)xlsxio_write$(LIBEXT) 184 | $(CC) -o $@ $< $(LIBPREFIX)xlsxio_write$(LIBEXT) $(XLSXIOWRITE_LDFLAGS) $(LDFLAGS) 185 | 186 | .PHONY: doc 187 | doc: 188 | ifdef DOXYGEN 189 | $(DOXYGEN) doc/Doxyfile 190 | endif 191 | 192 | install: all doc 193 | $(MKDIR) $(PREFIX)/include $(PREFIX)/lib $(PREFIX)/bin 194 | $(CP) include/*.h $(PREFIX)/include/ 195 | $(CP) *$(LIBEXT) $(PREFIX)/lib/ 196 | ifeq ($(OS),Windows_NT) 197 | $(CP) *.def $(PREFIX)/lib/ 198 | $(CP) *$(SOEXT) $(PREFIX)/bin/ 199 | else 200 | $(CP) *$(SOEXT) $(PREFIX)/lib/ 201 | endif 202 | $(CP) $(TOOLS_BIN) $(PREFIX)/bin/ 203 | ifdef DOXYGEN 204 | $(CPDIR) doc/man $(PREFIX)/ 205 | $(MKDIR) $(PREFIX)/share/xlsxio 206 | $(CPDIR) doc/html $(PREFIX)/share/xlsxio/ 207 | endif 208 | 209 | .PHONY: version 210 | version: 211 | sed -ne "s/^#define\s*XLSXIO_VERSION_[A-Z]*\s*\([0-9]*\)\s*$$/\1./p" include/xlsxio_version.h | tr -d "\n" | sed -e "s/\.$$//" > version 212 | 213 | .PHONY: package 214 | package: version 215 | tar cfJ xlsxio-$(shell cat version).tar.xz --transform="s?^?xlsxio-$(shell cat version)/?" $(SOURCE_PACKAGE_FILES) 216 | 217 | .PHONY: package 218 | binarypackage: version 219 | $(MAKE) PREFIX=binpkg_$(OSALIAS)_temp install STATICDLL=1 WIDE=1 220 | ifneq ($(OS),Windows_NT) 221 | tar cfJ "xlsxio-$(shell cat version)-$(OSALIAS).tar.xz" --transform="s?^binpkg_$(OSALIAS)_temp/??" $(COMMON_PACKAGE_FILES) binpkg_$(OSALIAS)_temp/* 222 | else 223 | rm -f xlsxio-$(shell cat version)-$(OSALIAS).zip 224 | cp -f $(COMMON_PACKAGE_FILES) binpkg_$(OSALIAS)_temp/ 225 | cd binpkg_$(OSALIAS)_temp && zip -r -9 "../xlsxio-$(shell cat version)-binary-$(OSALIAS).zip" $(COMMON_PACKAGE_FILES) * && cd .. 226 | endif 227 | rm -rf binpkg_$(OSALIAS)_temp 228 | 229 | .PHONY: clean 230 | clean: 231 | $(RM) lib/*.o examples/*.o src/*.o *$(LIBEXT) *$(SOEXT) $(TOOLS_BIN) $(EXAMPLES_BIN) version xlsxio-*.tar.xz doc/doxygen_sqlite3.db 232 | ifeq ($(OS),Windows_NT) 233 | $(RM) *.def 234 | endif 235 | $(RMDIR) doc/html doc/man 236 | 237 | -------------------------------------------------------------------------------- /build/_cmake_build_.sh: -------------------------------------------------------------------------------- 1 | #/bin sh 2 | if [ -z "$WINDIR" ]; then 3 | OSARCH=$(uname -s)_$(uname -m) 4 | EXEEXT= 5 | CMAKEMAKEFILETYPE=Unix 6 | else 7 | OSARCH=win$( if [ "$(uname -m)" == "x86_64" ]; then echo 64; else echo 32; fi) 8 | EXEEXT=.exe 9 | CMAKEMAKEFILETYPE=MSYS 10 | fi 11 | BUILDDIR=$(realpath $(dirname $0)/_build_$OSARCH) 12 | BASEDIR=$(realpath $(dirname $0)/..) 13 | VERSION=$(sed -ne "s/^#define\s*XLSXIO_VERSION_[A-Z]*\s*\([0-9]*\)\s*$/\1./p" $(dirname $0)/../include/xlsxio_version.h | tr -d "\n" | sed -e "s/\.$//") 14 | ZIPFILE=$(realpath $(dirname $0)/xlsxio-$VERSION-$OSARCH.zip) 15 | 16 | mkdir -p "$BUILDDIR" 17 | mkdir -p "$BUILDDIR"/CMakeFiles/CMakeTmp/CMakeFiles 18 | cd "$BUILDDIR" 19 | #mkdir -p CMakeFiles/CMakeTmp/CMakeFiles 20 | #touch CMakeFiles/CMakeTmp/CMakeFiles/cmake.check_cache 21 | echo Configuring... && 22 | cmake$EXEEXT -G"$CMAKEMAKEFILETYPE Makefiles" -DCMAKE_INSTALL_PREFIX:PATH="_package_" -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_STATIC:BOOL=ON -DBUILD_SHARED:BOOL=ON -DWITH_LIBZIP:BOOL=OFF -DWITH_WIDE:BOOL=ON -DBUILD_DOCUMENTATION:BOOL=OFF ../.. && 23 | if [ "$CMAKEMAKEFILETYPE" = "MSYS" ]; then 24 | # build statically linked DLL on Windows 25 | sed -i -e "s/\.dll\.a/.a -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++/" CMakeFiles/xlsxio_write_SHARED.dir/linklibs.rsp && 26 | sed -i -e "s/^C_DEFINES\s*=.*-DBUILD_XLSXIO_DLL/& -DSTATIC/" CMakeFiles/xlsxio_write_SHARED.dir/flags.make 27 | sed -i -e "s/\.dll\.a/.a -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++/" CMakeFiles/xlsxio_read_SHARED.dir/linklibs.rsp && 28 | sed -i -e "s/^C_DEFINES\s*=.*-DBUILD_XLSXIO_DLL/& -DSTATIC/" CMakeFiles/xlsxio_read_SHARED.dir/flags.make 29 | sed -i -e "s/\.dll\.a/.a -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++/" CMakeFiles/xlsxio_readw_SHARED.dir/linklibs.rsp && 30 | sed -i -e "s/^C_DEFINES\s*=.*-DBUILD_XLSXIO_DLL/& -DSTATIC/" CMakeFiles/xlsxio_readw_SHARED.dir/flags.make 31 | fi && 32 | echo Building... && 33 | make install/strip VERBOSE=1 && 34 | echo Making binary package: $ZIPFILE... && 35 | #pushd $BUILDDIR/_package_ &> /dev/null && 36 | cd _package_ && 37 | cp -f $BASEDIR/LICENSE.txt $BASEDIR/Changelog.txt $BASEDIR/*.md . && 38 | rm -f $ZIPFILE && 39 | zip -r -9 $ZIPFILE * && 40 | #popd &> /dev/null && 41 | cd .. && 42 | echo OK 43 | 44 | -------------------------------------------------------------------------------- /build/_test2_.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 108 | 109 | -------------------------------------------------------------------------------- /build/_test_.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 108 | 109 | -------------------------------------------------------------------------------- /build/example_xlsxio_read.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 106 | 107 | -------------------------------------------------------------------------------- /build/example_xlsxio_read.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1645054981 source:\\server\users\brecht\sources\cpp\xlsxio\examples\example_xlsxio_read.c 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | "xlsxio_read.h" 14 | 15 | 1609254789 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 16 | 17 | 18 | 19 | 20 | 21 | 1521232544 source:z:\xlsxio\examples\example_xlsxio_read.c 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | "xlsxio_read.h" 33 | 34 | 1609251189 z:\xlsxio\include\xlsxio_read.h 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /build/example_xlsxio_read_advanced.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 105 | 106 | -------------------------------------------------------------------------------- /build/example_xlsxio_read_advanced.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | -------------------------------------------------------------------------------- /build/example_xlsxio_read_cpp.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 102 | 103 | -------------------------------------------------------------------------------- /build/example_xlsxio_read_cpp.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1460837137 source:z:\xlsxio\examples\example_xlsxio_read_cpp.cpp 3 | 4 | 5 | 6 | 7 | "xlsxio_read.h" 8 | 9 | 1460837043 z:\xlsxio\include\xlsxio_read.h 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /build/example_xlsxio_read_wchar.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 106 | 107 | -------------------------------------------------------------------------------- /build/example_xlsxio_read_wchar.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1645051381 source:z:\xlsxio\examples\example_xlsxio_read.c 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | "xlsxio_read.h" 14 | 15 | 1609251189 z:\xlsxio\include\xlsxio_read.h 16 | 17 | 18 | 19 | 20 | 21 | 1645054981 source:\\server\users\brecht\sources\cpp\xlsxio\examples\example_xlsxio_read.c 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | "xlsxio_read.h" 33 | 34 | 1609254789 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /build/example_xlsxio_write.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 104 | 105 | -------------------------------------------------------------------------------- /build/example_xlsxio_write.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1462431682 source:\\server\users\brecht\sources\cpp\xlsxio\examples\example_xlsxio_write.c 3 | 4 | 5 | 6 | "xlsxio_write.h" 7 | 8 | 1583781545 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_write.h 9 | 10 | 11 | 12 | 13 | 1462431682 source:z:\xlsxio\examples\example_xlsxio_write.c 14 | 15 | 16 | 17 | "xlsxio_write.h" 18 | 19 | 1583781545 z:\xlsxio\include\xlsxio_write.h 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /build/example_xlsxio_write_cpp.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 102 | 103 | -------------------------------------------------------------------------------- /build/example_xlsxio_write_cpp.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1458508677 source:z:\xlsxio\examples\example_xlsxio_write_cpp.cpp 3 | 4 | 5 | "xlsxio_write.h" 6 | 7 | 1458418704 z:\xlsxio\include\xlsxio_write.h 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /build/example_xlsxio_write_getversion.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 104 | 105 | -------------------------------------------------------------------------------- /build/example_xlsxio_write_getversion.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1460400767 source:\\server\users\brecht\sources\cpp\xlsxio\examples\example_xlsxio_write_getversion.c 3 | 4 | "xlsxio_write.h" 5 | "xlsxio_version.h" 6 | 7 | 1583781545 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_write.h 8 | 9 | 10 | 11 | 12 | 1583783094 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 13 | 14 | -------------------------------------------------------------------------------- /build/libxlsxio_read.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 116 | 117 | -------------------------------------------------------------------------------- /build/libxlsxio_read.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | -------------------------------------------------------------------------------- /build/libxlsxio_read_minizip_shared.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 125 | 126 | -------------------------------------------------------------------------------- /build/libxlsxio_read_minizip_shared.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1685461505 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read.c 3 | "xlsxio_private.h" 4 | "xlsxio_read_sharedstrings.h" 5 | "xlsxio_read.h" 6 | "xlsxio_version.h" 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 1521234538 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_private.h 19 | 20 | 21 | 1522321419 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.h 22 | 23 | 24 | 25 | 1609254789 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 26 | 27 | 28 | 29 | 30 | 31 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 32 | 33 | 1522321402 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.c 34 | "xlsxio_private.h" 35 | "xlsxio_read_sharedstrings.h" 36 | 37 | 38 | 39 | 1691055322 source:z:\xlsxio\lib\xlsxio_read.c 40 | "xlsxio_private.h" 41 | "xlsxio_read_sharedstrings.h" 42 | "xlsxio_read.h" 43 | "xlsxio_version.h" 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 1521234538 z:\xlsxio\lib\xlsxio_private.h 56 | 57 | 58 | 1522321419 z:\xlsxio\lib\xlsxio_read_sharedstrings.h 59 | 60 | 61 | 62 | 1609254789 z:\xlsxio\include\xlsxio_read.h 63 | 64 | 65 | 66 | 67 | 68 | 1711657534 z:\xlsxio\include\xlsxio_version.h 69 | 70 | 1522321402 source:z:\xlsxio\lib\xlsxio_read_sharedstrings.c 71 | "xlsxio_private.h" 72 | "xlsxio_read_sharedstrings.h" 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /build/libxlsxio_read_shared.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 122 | 123 | -------------------------------------------------------------------------------- /build/libxlsxio_read_shared.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1685461505 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read.c 3 | "xlsxio_private.h" 4 | "xlsxio_read_sharedstrings.h" 5 | "xlsxio_read.h" 6 | "xlsxio_version.h" 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 1521234538 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_private.h 19 | 20 | 21 | 1522321419 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.h 22 | 23 | 24 | 25 | 1609254789 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 26 | 27 | 28 | 29 | 30 | 31 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 32 | 33 | 1522321402 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.c 34 | "xlsxio_private.h" 35 | "xlsxio_read_sharedstrings.h" 36 | 37 | 38 | 39 | 1522317802 source:z:\xlsxio\lib\xlsxio_read_sharedstrings.c 40 | "xlsxio_private.h" 41 | "xlsxio_read_sharedstrings.h" 42 | 43 | 44 | 45 | 1521230938 z:\xlsxio\lib\xlsxio_private.h 46 | 47 | 48 | 1522317819 z:\xlsxio\lib\xlsxio_read_sharedstrings.h 49 | 50 | 51 | 52 | 1691051722 source:z:\xlsxio\lib\xlsxio_read.c 53 | "xlsxio_private.h" 54 | "xlsxio_read_sharedstrings.h" 55 | "xlsxio_read.h" 56 | "xlsxio_version.h" 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 1609251189 z:\xlsxio\include\xlsxio_read.h 69 | 70 | 71 | 72 | 73 | 74 | 1685458080 z:\xlsxio\include\xlsxio_version.h 75 | 76 | -------------------------------------------------------------------------------- /build/libxlsxio_read_wchar.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 117 | 118 | -------------------------------------------------------------------------------- /build/libxlsxio_read_wchar.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1685461505 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read.c 3 | "xlsxio_private.h" 4 | "xlsxio_read_sharedstrings.h" 5 | "xlsxio_read.h" 6 | "xlsxio_version.h" 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 1521234538 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_private.h 19 | 20 | 21 | 1522321419 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.h 22 | 23 | 24 | 25 | 1609254789 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 26 | 27 | 28 | 29 | 30 | 31 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 32 | 33 | 1522321402 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.c 34 | "xlsxio_private.h" 35 | "xlsxio_read_sharedstrings.h" 36 | 37 | 38 | 39 | 1691051722 source:z:\xlsxio\lib\xlsxio_read.c 40 | "xlsxio_private.h" 41 | "xlsxio_read_sharedstrings.h" 42 | "xlsxio_read.h" 43 | "xlsxio_version.h" 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 1521230938 z:\xlsxio\lib\xlsxio_private.h 56 | 57 | 58 | 1522317819 z:\xlsxio\lib\xlsxio_read_sharedstrings.h 59 | 60 | 61 | 62 | 1609251189 z:\xlsxio\include\xlsxio_read.h 63 | 64 | 65 | 66 | 67 | 68 | 1685458080 z:\xlsxio\include\xlsxio_version.h 69 | 70 | 1522317802 source:z:\xlsxio\lib\xlsxio_read_sharedstrings.c 71 | "xlsxio_private.h" 72 | "xlsxio_read_sharedstrings.h" 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /build/libxlsxio_read_wchar_shared.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 123 | 124 | -------------------------------------------------------------------------------- /build/libxlsxio_read_wchar_shared.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1685461505 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read.c 3 | "xlsxio_private.h" 4 | "xlsxio_read_sharedstrings.h" 5 | "xlsxio_read.h" 6 | "xlsxio_version.h" 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 1521234538 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_private.h 19 | 20 | 21 | 1522321419 \\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.h 22 | 23 | 24 | 25 | 1609254789 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 26 | 27 | 28 | 29 | 30 | 31 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 32 | 33 | 1522321402 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_read_sharedstrings.c 34 | "xlsxio_private.h" 35 | "xlsxio_read_sharedstrings.h" 36 | 37 | 38 | 39 | 1691051722 source:z:\xlsxio\lib\xlsxio_read.c 40 | "xlsxio_private.h" 41 | "xlsxio_read_sharedstrings.h" 42 | "xlsxio_read.h" 43 | "xlsxio_version.h" 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 1521230938 z:\xlsxio\lib\xlsxio_private.h 56 | 57 | 58 | 1522317819 z:\xlsxio\lib\xlsxio_read_sharedstrings.h 59 | 60 | 61 | 62 | 1609251189 z:\xlsxio\include\xlsxio_read.h 63 | 64 | 65 | 66 | 67 | 68 | 1685458080 z:\xlsxio\include\xlsxio_version.h 69 | 70 | 1522317802 source:z:\xlsxio\lib\xlsxio_read_sharedstrings.c 71 | "xlsxio_private.h" 72 | "xlsxio_read_sharedstrings.h" 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /build/libxlsxio_write.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 122 | 123 | -------------------------------------------------------------------------------- /build/libxlsxio_write.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | -------------------------------------------------------------------------------- /build/libxlsxio_write_minizip_shared.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 118 | 119 | -------------------------------------------------------------------------------- /build/libxlsxio_write_minizip_shared.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1667387741 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_write.c 3 | "xlsxio_write.h" 4 | "xlsxio_version.h" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1583785145 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_write.h 20 | 21 | 22 | 23 | 24 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 25 | 26 | 1691051673 source:z:\xlsxio\lib\xlsxio_write.c 27 | "xlsxio_write.h" 28 | "xlsxio_version.h" 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 1583781545 z:\xlsxio\include\xlsxio_write.h 44 | 45 | 46 | 47 | 48 | 1685458080 z:\xlsxio\include\xlsxio_version.h 49 | 50 | -------------------------------------------------------------------------------- /build/libxlsxio_write_shared.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 117 | 118 | -------------------------------------------------------------------------------- /build/libxlsxio_write_shared.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1667387741 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_write.c 3 | "xlsxio_write.h" 4 | "xlsxio_version.h" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1583785145 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_write.h 20 | 21 | 22 | 23 | 24 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 25 | 26 | 1691051673 source:z:\xlsxio\lib\xlsxio_write.c 27 | "xlsxio_write.h" 28 | "xlsxio_version.h" 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 1583781545 z:\xlsxio\include\xlsxio_write.h 44 | 45 | 46 | 47 | 48 | 1685458080 z:\xlsxio\include\xlsxio_version.h 49 | 50 | -------------------------------------------------------------------------------- /build/libxlsxio_write_wchar.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 123 | 124 | -------------------------------------------------------------------------------- /build/libxlsxio_write_wchar.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1667387741 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_write.c 3 | "xlsxio_write.h" 4 | "xlsxio_version.h" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1583785145 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_write.h 20 | 21 | 22 | 23 | 24 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 25 | 26 | 1691051673 source:z:\xlsxio\lib\xlsxio_write.c 27 | "xlsxio_write.h" 28 | "xlsxio_version.h" 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 1583781545 z:\xlsxio\include\xlsxio_write.h 44 | 45 | 46 | 47 | 48 | 1685458080 z:\xlsxio\include\xlsxio_version.h 49 | 50 | -------------------------------------------------------------------------------- /build/libxlsxio_write_wchar_shared.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 118 | 119 | -------------------------------------------------------------------------------- /build/libxlsxio_write_wchar_shared.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1667387741 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_write.c 3 | "xlsxio_write.h" 4 | "xlsxio_version.h" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1583785145 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_write.h 20 | 21 | 22 | 23 | 24 | 1685461680 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 25 | 26 | 1691051673 source:z:\xlsxio\lib\xlsxio_write.c 27 | "xlsxio_write.h" 28 | "xlsxio_version.h" 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 1583781545 z:\xlsxio\include\xlsxio_write.h 44 | 45 | 46 | 47 | 48 | 1685458080 z:\xlsxio\include\xlsxio_version.h 49 | 50 | -------------------------------------------------------------------------------- /build/test1.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 110 | 111 | -------------------------------------------------------------------------------- /build/test2.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 100 | 101 | -------------------------------------------------------------------------------- /build/test2.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /build/test3.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 100 | 101 | -------------------------------------------------------------------------------- /build/test3.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /build/xlsxio.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /build/xlsxio_csv2xlsx.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 110 | 111 | -------------------------------------------------------------------------------- /build/xlsxio_csv2xlsx.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | -------------------------------------------------------------------------------- /build/xlsxio_read.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 103 | 104 | -------------------------------------------------------------------------------- /build/xlsxio_write.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 102 | 103 | -------------------------------------------------------------------------------- /build/xlsxio_xlsx2csv.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 106 | 107 | -------------------------------------------------------------------------------- /build/xlsxio_xlsx2csv.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1548002755 source:\\server\users\brecht\sources\cpp\xlsxio\src\xlsxio_xlsx2csv.c 3 | 4 | 5 | 6 | 7 | "xlsxio_read.h" 8 | "xlsxio_version.h" 9 | 10 | 1521131524 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_read.h 11 | 12 | 13 | 14 | 15 | 16 | 1544956328 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h 17 | 18 | 1716653912 source:z:\xlsxio\src\xlsxio_xlsx2csv.c 19 | 20 | 21 | 22 | 23 | "xlsxio_read.h" 24 | "xlsxio_version.h" 25 | 26 | 1609254789 z:\xlsxio\include\xlsxio_read.h 27 | 28 | 29 | 30 | 31 | 32 | 1711657534 z:\xlsxio\include\xlsxio_version.h 33 | 34 | -------------------------------------------------------------------------------- /buildbin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | CC=gcc 3 | CXX=g++ 4 | 5 | # determine target platform 6 | TARGET= 7 | if ( uname -s | grep -qi "MINGW\|MSYS" ); then 8 | if ( gcc --version | grep -q x86_64 ); then 9 | TARGET=win64 10 | else 11 | TARGET=win32 12 | fi 13 | fi 14 | if [ "$TARGET" = "" ]; then 15 | echo "Unsupported platform, currently only MinGW on Windows is supported" 16 | exit 1; 17 | fi 18 | 19 | VERSION=$(sed -ne "s/^#define\s*XLSXIO_VERSION_[A-Z]*\s*\([0-9]*\)\s*$/\1./p" include/xlsxio_version.h | tr -d "\n" | sed -e "s/\.$//") 20 | BUILDDST=build_$TARGET 21 | ZIPFILE=xlsxio-$VERSION-binary-$TARGET.zip 22 | #CFLAGS="-DUSE_LIBZIP" 23 | #LDFLAGS="-lzip -lz" 24 | CFLAGS="-DUSE_MINIZIP" 25 | LDFLAGS="-lminizip -lz" 26 | 27 | rm -f $ZIPFILE &> /dev/null 28 | mkdir -p $BUILDDST && 29 | $CC -mdll -static -o$BUILDDST/xlsxio_read.dll -Wl,--out-implib,$BUILDDST/libxlsxio_read.a -DBUILD_XLSXIO_DLL -DBUILD_XLSXIO_STATIC_DLL -Iinclude lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c $CFLAGS $LDFLAGS -lexpat && 30 | $CC -mdll -static -o$BUILDDST/xlsxio_write.dll -Wl,--out-implib,$BUILDDST/libxlsxio_write.a -DBUILD_XLSXIO_DLL -DBUILD_XLSXIO_STATIC_DLL -Iinclude lib/xlsxio_write.c $CFLAGS $LDFLAGS && 31 | $CC -mconsole -s -o$BUILDDST/xlsxio_xlsx2csv.exe src/xlsxio_xlsx2csv.c -Iinclude $BUILDDST/libxlsxio_read.a && 32 | $CC -mconsole -s -o$BUILDDST/xlsxio_csv2xlsx.exe src/xlsxio_csv2xlsx.c -Iinclude $BUILDDST/libxlsxio_write.a && 33 | zip -qj $ZIPFILE LICENSE.txt Changelog.txt README.md include/* $BUILDDST/* && 34 | echo Created $ZIPFILE && 35 | rm -rf $BUILDDST 36 | -------------------------------------------------------------------------------- /doc/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "XLSX I/O" 2 | OUTPUT_DIRECTORY = doc 3 | INPUT = 4 | EXTRACT_ALL = NO 5 | EXTRACT_PRIVATE = NO 6 | EXTRACT_STATIC = NO 7 | FILE_PATTERNS = README.md xlsxio*.h 8 | EXCLUDE = lib/xlsxio_read_sharedstrings.h 9 | USE_MDFILE_AS_MAINPAGE = README.md 10 | RECURSIVE = YES 11 | GENERATE_MAN = YES 12 | GENERATE_HTML = YES 13 | GENERATE_LATEX = NO 14 | #GENERATE_LATEX = YES 15 | #USE_PDFLATEX = YES 16 | #PDF_HYPERLINKS = YES 17 | SORT_MEMBER_DOCS = NO 18 | EXCLUDE_SYMBOLS = DLL_EXPORT_XLSXIO 19 | -------------------------------------------------------------------------------- /examples/example_xlsxio_read.c: -------------------------------------------------------------------------------- 1 | //#define PROCESS_FROM_MEMORY 2 | #define PROCESS_FROM_FILEHANDLE 3 | /***************************************************************************** 4 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | *****************************************************************************/ 24 | 25 | /** 26 | * @file example_xlsxio_read.c 27 | * @brief XLSX I/O example illustrating how to read from an .xlsx file. 28 | * @author Brecht Sanders 29 | * 30 | * This example reads data from an .xslx file using the simple method. 31 | */ 32 | 33 | //#define PROCESS_FROM_MEMORY 34 | 35 | #include 36 | #include 37 | #include 38 | #if _WIN32 39 | #include 40 | #else 41 | #define O_BINARY 0 42 | #endif 43 | #ifdef PROCESS_FROM_MEMORY 44 | #include 45 | #include 46 | #include 47 | #endif 48 | #ifdef PROCESS_FROM_FILEHANDLE 49 | //#include 50 | #include 51 | #include 52 | #include 53 | #endif 54 | #include "xlsxio_read.h" 55 | 56 | #if !defined(XML_UNICODE_WCHAR_T) && !defined(XML_UNICODE) 57 | //UTF-8 version 58 | #define X(s) s 59 | #define XML_Char_printf printf 60 | #else 61 | //UTF-16 version 62 | #define X(s) L##s 63 | #define XML_Char_printf wprintf 64 | #endif 65 | 66 | const char* filename = "example.xlsx"; 67 | 68 | int main (int argc, char* argv[]) 69 | { 70 | #ifdef _WIN32 71 | //switch Windows console to UTF-8 72 | SetConsoleOutputCP(CP_UTF8); 73 | #endif 74 | 75 | if (argc > 1) 76 | filename = argv[1]; 77 | 78 | xlsxioreader xlsxioread; 79 | 80 | XML_Char_printf(X("XLSX I/O library version %s\n"), xlsxioread_get_version_string()); 81 | 82 | #if defined(PROCESS_FROM_MEMORY) 83 | { 84 | //load file in memory 85 | int filehandle; 86 | char* buf = NULL; 87 | size_t buflen = 0; 88 | if ((filehandle = open(filename, O_RDONLY | O_BINARY)) != -1) { 89 | struct stat fileinfo; 90 | if (fstat(filehandle, &fileinfo) == 0) { 91 | if ((buf = malloc(fileinfo.st_size)) != NULL) { 92 | if (fileinfo.st_size > 0 && read(filehandle, buf, fileinfo.st_size) == fileinfo.st_size) { 93 | buflen = fileinfo.st_size; 94 | } 95 | } 96 | } 97 | close(filehandle); 98 | } 99 | if (!buf || buflen == 0) { 100 | fprintf(stderr, "Error loading .xlsx file\n"); 101 | return 1; 102 | } 103 | if ((xlsxioread = xlsxioread_open_memory(buf, buflen, 1)) == NULL) { 104 | fprintf(stderr, "Error processing .xlsx data\n"); 105 | return 1; 106 | } 107 | } 108 | #elif defined(PROCESS_FROM_FILEHANDLE) 109 | //open .xlsx file for reading 110 | int filehandle; 111 | if ((filehandle = open(filename, O_RDONLY | O_BINARY, 0)) == -1) { 112 | fprintf(stderr, "Error opening .xlsx file\n"); 113 | return 1; 114 | } 115 | if ((xlsxioread = xlsxioread_open_filehandle(filehandle)) == NULL) { 116 | fprintf(stderr, "Error reading .xlsx file\n"); 117 | return 1; 118 | } 119 | #else 120 | //open .xlsx file for reading 121 | if ((xlsxioread = xlsxioread_open(filename)) == NULL) { 122 | fprintf(stderr, "Error opening .xlsx file\n"); 123 | return 1; 124 | } 125 | #endif 126 | 127 | //list available sheets 128 | xlsxioreadersheetlist sheetlist; 129 | const XLSXIOCHAR* sheetname; 130 | printf("Available sheets:\n"); 131 | if ((sheetlist = xlsxioread_sheetlist_open(xlsxioread)) != NULL) { 132 | while ((sheetname = xlsxioread_sheetlist_next(sheetlist)) != NULL) { 133 | XML_Char_printf(X(" - %s\n"), sheetname); 134 | } 135 | xlsxioread_sheetlist_close(sheetlist); 136 | } 137 | 138 | //read values from first sheet 139 | XLSXIOCHAR* value; 140 | printf("Contents of first sheet:\n"); 141 | xlsxioreadersheet sheet = xlsxioread_sheet_open(xlsxioread, NULL, XLSXIOREAD_SKIP_EMPTY_ROWS); 142 | while (xlsxioread_sheet_next_row(sheet)) { 143 | while ((value = xlsxioread_sheet_next_cell(sheet)) != NULL) { 144 | XML_Char_printf(X("%s\t"), value); 145 | xlsxioread_free(value); 146 | } 147 | printf("\n"); 148 | } 149 | xlsxioread_sheet_close(sheet); 150 | 151 | //clean up 152 | xlsxioread_close(xlsxioread); 153 | return 0; 154 | } 155 | -------------------------------------------------------------------------------- /examples/example_xlsxio_read_advanced.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | /** 24 | * @file example_xlsxio_read_advanced.c 25 | * @brief XLSX I/O example illustrating how to read from an .xlsx file. 26 | * @author Brecht Sanders 27 | * 28 | * This example reads data from an .xslx file using the callback method. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "xlsxio_read.h" 35 | 36 | const char* filename = "example.xlsx"; 37 | 38 | //callback data structure for listing sheets 39 | struct xlsx_list_sheets_data { 40 | char* firstsheet; 41 | }; 42 | 43 | //callback function for listing sheets 44 | int xlsx_list_sheets_callback (const char* name, void* callbackdata) 45 | { 46 | struct xlsx_list_sheets_data* data = (struct xlsx_list_sheets_data*)callbackdata; 47 | if (!data->firstsheet) 48 | data->firstsheet = strdup(name); 49 | printf(" - %s\n", name); 50 | return 0; 51 | } 52 | 53 | //callback function for end of row 54 | int sheet_row_callback (size_t row, size_t maxcol, void* callbackdata) 55 | { 56 | printf("\n"); 57 | return 0; 58 | } 59 | 60 | //callback function for cell data 61 | int sheet_cell_callback (size_t row, size_t col, const XLSXIOCHAR* value, void* callbackdata) 62 | { 63 | if (col > 1) 64 | printf("\t"); 65 | if (value) 66 | printf("%s", value); 67 | return 0; 68 | } 69 | 70 | int main (int argc, char* argv[]) 71 | { 72 | xlsxioreader xlsxioread; 73 | //open .xlsx file for reading 74 | if ((xlsxioread = xlsxioread_open(filename)) == NULL) { 75 | fprintf(stderr, "Error opening .xlsx file\n"); 76 | return 1; 77 | } 78 | //list available sheets 79 | struct xlsx_list_sheets_data sheetdata; 80 | sheetdata.firstsheet = NULL; 81 | printf("Available sheets:\n"); 82 | xlsxioread_list_sheets(xlsxioread, xlsx_list_sheets_callback, &sheetdata); 83 | 84 | //read data 85 | xlsxioread_process(xlsxioread, sheetdata.firstsheet, XLSXIOREAD_SKIP_EMPTY_ROWS, sheet_cell_callback, sheet_row_callback, NULL); 86 | 87 | //clean up 88 | free(sheetdata.firstsheet); 89 | xlsxioread_close(xlsxioread); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /examples/example_xlsxio_read_cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "xlsxio_read.h" 6 | 7 | /*! \class XLSXIOReader 8 | * \brief class for reading data from an .xlsx file 9 | *\details C++ wrapper for xlsxioread_ functions. 10 | */ 11 | class XLSXIOReader 12 | { 13 | private: 14 | xlsxioreader handle; 15 | public: 16 | 17 | /*! \brief XLSXIOReader constructor, opens .xlsx file 18 | * \param filename path of .xlsx file to open 19 | * \sa xlsxioread_open() 20 | */ 21 | XLSXIOReader (const char* filename); 22 | 23 | /*! \brief XLSXIOReader destructor, closes .xlsx file 24 | * \sa xlsxioread_close() 25 | */ 26 | ~XLSXIOReader (); 27 | 28 | /*! \brief opens 29 | * \param sheetname worksheet name (NULL for first sheet) 30 | * \param flags XLSXIOREAD_SKIP_ flag(s) to determine how data is processed 31 | * \return XLSXIOReaderSheet object or NULL in case of error 32 | * \sa xlsxioread_sheet_open() 33 | */ 34 | class XLSXIOReaderSheet* OpenSheet (const char* sheetname, unsigned int flags); 35 | }; 36 | 37 | 38 | 39 | /*! \class XLSXIOReaderSheet 40 | * \brief class for reading data from a sheet in an .xlsx file 41 | *\details C++ wrapper for xlsxioread_sheet_ functions. 42 | */ 43 | class XLSXIOReaderSheet 44 | { 45 | friend class XLSXIOReader; 46 | private: 47 | xlsxioreadersheet sheethandle; 48 | XLSXIOReaderSheet (xlsxioreadersheet sheet); 49 | XLSXIOReaderSheet (xlsxioreader xlsxhandle, const char* sheetname, unsigned int flags); 50 | public: 51 | 52 | /*! \brief XLSXIOReaderSheet, closes sheet 53 | * \sa xlsxioread_sheet_close() 54 | */ 55 | ~XLSXIOReaderSheet (); 56 | 57 | /*! \brief start reading the next row of data 58 | * \sa xlsxioread_sheet_next_row() 59 | * \sa GetNextCell() 60 | */ 61 | bool GetNextRow (); 62 | 63 | /*! \brief read the next column cell 64 | * \return value (caller must free the result) or NULL if no more cells are available in the current row 65 | * \sa xlsxioread_sheet_next_cell() 66 | * \sa GetNextRow() 67 | */ 68 | char* GetNextCell (); 69 | 70 | /*! \brief read the next column cell as a dynamically allocated string value 71 | * \param value reference where value will be stored (caller must free the result) 72 | * \return true if cell data was available, otherwise false 73 | * \sa xlsxioread_sheet_next_cell_string() 74 | * \sa GetNextRow() 75 | */ 76 | bool GetNextCellString (char*& value); 77 | 78 | /*! \brief read the next column cell as a string value 79 | * \param value reference where value will be stored 80 | * \return true if cell data was available, otherwise false 81 | * \sa xlsxioread_sheet_next_cell_string() 82 | * \sa GetNextRow() 83 | */ 84 | bool GetNextCellString (std::string& value); 85 | 86 | /*! \brief read the next column cell as an integer value 87 | * \param value reference where value will be stored 88 | * \return true if cell data was available, otherwise false 89 | * \sa xlsxioread_sheet_next_cell_int() 90 | * \sa GetNextRow() 91 | */ 92 | bool GetNextCellInt (int64_t& value); 93 | 94 | /*! \brief read the next column cell as a floating point value 95 | * \param value reference where value will be stored 96 | * \return true if cell data was available, otherwise false 97 | * \sa xlsxioread_sheet_next_cell_float() 98 | * \sa GetNextRow() 99 | */ 100 | bool GetNextCellFloat (double& value); 101 | 102 | /*! \brief read the next column cell as a date/time value 103 | * \param value reference where value will be stored 104 | * \return true if cell data was available, otherwise false 105 | * \sa xlsxioread_sheet_next_cell_datetime() 106 | * \sa GetNextRow() 107 | */ 108 | bool GetNextCellDateTime (time_t& value); 109 | 110 | /*! \brief extraction operators 111 | * \sa GetNextCellString() 112 | * \name operator>> 113 | * \{ 114 | */ 115 | XLSXIOReaderSheet& operator >> (char*& value); 116 | XLSXIOReaderSheet& operator >> (std::string& value); 117 | XLSXIOReaderSheet& operator >> (int64_t& value); 118 | XLSXIOReaderSheet& operator >> (double& value); 119 | //inline XLSXIOReaderSheet& operator >> (time_t& value); 120 | /*! @} */ 121 | }; 122 | 123 | 124 | 125 | inline XLSXIOReader::XLSXIOReader (const char* filename) 126 | { 127 | handle = xlsxioread_open(filename); 128 | } 129 | 130 | inline XLSXIOReader::~XLSXIOReader () 131 | { 132 | xlsxioread_close(handle); 133 | } 134 | 135 | inline class XLSXIOReaderSheet* XLSXIOReader::OpenSheet (const char* sheetname, unsigned int flags) 136 | { 137 | xlsxioreadersheet sheethandle; 138 | if ((sheethandle = xlsxioread_sheet_open(handle, sheetname, flags)) == NULL) 139 | return NULL; 140 | return new XLSXIOReaderSheet(sheethandle); 141 | } 142 | 143 | 144 | 145 | inline XLSXIOReaderSheet::XLSXIOReaderSheet (xlsxioreadersheet sheet) 146 | : sheethandle(sheet) 147 | { 148 | } 149 | 150 | inline XLSXIOReaderSheet::~XLSXIOReaderSheet () 151 | { 152 | xlsxioread_sheet_close(sheethandle); 153 | } 154 | 155 | inline bool XLSXIOReaderSheet::GetNextRow () 156 | { 157 | return (xlsxioread_sheet_next_row(sheethandle) != 0); 158 | } 159 | 160 | inline char* XLSXIOReaderSheet::GetNextCell () 161 | { 162 | return xlsxioread_sheet_next_cell(sheethandle); 163 | } 164 | 165 | inline bool XLSXIOReaderSheet::GetNextCellString (char*& value) 166 | { 167 | if (!xlsxioread_sheet_next_cell_string(sheethandle, &value)) { 168 | value = NULL; 169 | return false; 170 | } 171 | return true; 172 | } 173 | 174 | inline bool XLSXIOReaderSheet::GetNextCellString (std::string& value) 175 | { 176 | char* result; 177 | if (!xlsxioread_sheet_next_cell_string(sheethandle, &result)) { 178 | value.clear(); 179 | return false; 180 | } 181 | value.assign(result); 182 | free(result); 183 | return true; 184 | } 185 | 186 | inline bool XLSXIOReaderSheet::GetNextCellInt (int64_t& value) 187 | { 188 | if (!xlsxioread_sheet_next_cell_int(sheethandle, &value)) { 189 | value = 0; 190 | return false; 191 | } 192 | return true; 193 | } 194 | 195 | inline bool XLSXIOReaderSheet::GetNextCellFloat (double& value) 196 | { 197 | if (!xlsxioread_sheet_next_cell_float(sheethandle, &value)) { 198 | value = 0; 199 | return false; 200 | } 201 | return true; 202 | } 203 | 204 | inline bool XLSXIOReaderSheet::GetNextCellDateTime (time_t& value) 205 | { 206 | if (!xlsxioread_sheet_next_cell_datetime(sheethandle, &value)) { 207 | value = 0; 208 | return false; 209 | } 210 | return true; 211 | } 212 | 213 | XLSXIOReaderSheet& XLSXIOReaderSheet::operator >> (char*& value) 214 | { 215 | GetNextCellString(value); 216 | return *this; 217 | } 218 | 219 | XLSXIOReaderSheet& XLSXIOReaderSheet::operator >> (std::string& value) 220 | { 221 | GetNextCellString(value); 222 | return *this; 223 | } 224 | 225 | XLSXIOReaderSheet& XLSXIOReaderSheet::operator >> (int64_t& value) 226 | { 227 | GetNextCellInt(value); 228 | return *this; 229 | } 230 | 231 | XLSXIOReaderSheet& XLSXIOReaderSheet::operator >> (double& value) 232 | { 233 | GetNextCellFloat(value); 234 | return *this; 235 | } 236 | 237 | /* 238 | XLSXIOReaderSheet& XLSXIOReaderSheet::operator >> (time_t& value) 239 | { 240 | GetNextCellDateTime(value); 241 | return *this; 242 | } 243 | */ 244 | 245 | 246 | 247 | const char* filename = "example.xlsx"; 248 | 249 | int main (int argc, char* argv[]) 250 | { 251 | XLSXIOReader* xlsxfile = new XLSXIOReader(filename); 252 | XLSXIOReaderSheet* xlsxsheet = xlsxfile->OpenSheet(NULL, XLSXIOREAD_SKIP_EMPTY_ROWS); 253 | if (xlsxsheet) { 254 | std::string value; 255 | while (xlsxsheet->GetNextRow()) { 256 | /* 257 | while (xlsxsheet->GetNextCellString(value)) { 258 | printf("%s\t", value.c_str()); 259 | } 260 | */ 261 | std::string s; 262 | *xlsxsheet >> s; 263 | printf("%s\t", s.c_str()); 264 | char* n; 265 | *xlsxsheet >> n; 266 | printf("%s\t", n); 267 | free(n); 268 | int64_t i; 269 | *xlsxsheet >> i; 270 | //printf("%" PRIi64 "\t", i); 271 | printf("%li\t", (long)i); 272 | *xlsxsheet >> i; 273 | //printf("%" PRIi64 "\t", i); 274 | printf("%li\t", (long)i); 275 | double d; 276 | *xlsxsheet >> d; 277 | printf("%.6G\t", d); 278 | printf("\n"); 279 | } 280 | delete xlsxsheet; 281 | } 282 | delete xlsxfile; 283 | return 0; 284 | } 285 | -------------------------------------------------------------------------------- /examples/example_xlsxio_write.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | /** 24 | * @file example_xlsxio_write.c 25 | * @brief XLSX I/O example illustrating how to write to an .xlsx file. 26 | * @author Brecht Sanders 27 | * 28 | * This example writes column headers and cells of different types to an .xslx file. 29 | */ 30 | 31 | #include 32 | #include 33 | #ifndef _WIN32 34 | #include 35 | #endif 36 | #include "xlsxio_write.h" 37 | 38 | const char* filename = "example.xlsx"; 39 | 40 | int main (int argc, char* argv[]) 41 | { 42 | xlsxiowriter handle; 43 | //open .xlsx file for writing (will overwrite if it already exists) 44 | if ((handle = xlsxiowrite_open(filename, "MySheet")) == NULL) { 45 | fprintf(stderr, "Error creating .xlsx file\n"); 46 | return 1; 47 | } 48 | //set row height 49 | xlsxiowrite_set_row_height(handle, 1); 50 | //how many rows to buffer to detect column widths 51 | xlsxiowrite_set_detection_rows(handle, 10); 52 | //write column names 53 | xlsxiowrite_add_column(handle, "Col1", 0); 54 | xlsxiowrite_add_column(handle, "Col2", 21); 55 | xlsxiowrite_add_column(handle, "Col3", 0); 56 | xlsxiowrite_add_column(handle, "Col4", 2); 57 | xlsxiowrite_add_column(handle, "Col5", 0); 58 | xlsxiowrite_add_column(handle, "Col6", 0); 59 | xlsxiowrite_add_column(handle, "Col7", 0); 60 | xlsxiowrite_next_row(handle); 61 | //write data 62 | int i; 63 | for (i = 0; i < 1000; i++) { 64 | xlsxiowrite_add_cell_string(handle, "Test"); 65 | xlsxiowrite_add_cell_string(handle, "A b c d e f\nnew line"); 66 | xlsxiowrite_add_cell_string(handle, "&% \"'"); 67 | xlsxiowrite_add_cell_string(handle, NULL); 68 | xlsxiowrite_add_cell_int(handle, i); 69 | xlsxiowrite_add_cell_datetime(handle, time(NULL)); 70 | xlsxiowrite_add_cell_float(handle, 3.1415926); 71 | xlsxiowrite_next_row(handle); 72 | } 73 | //close .xlsx file 74 | xlsxiowrite_close(handle); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /examples/example_xlsxio_write_cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "xlsxio_write.h" 5 | 6 | /*! \class XLSXIOWriter 7 | * \brief class for writing data to an .xlsx file 8 | *\details C++ wrapper for xlsxiowrite_ functions. 9 | */ 10 | class XLSXIOWriter 11 | { 12 | private: 13 | xlsxiowriter handle; 14 | public: 15 | 16 | /*! \brief XLSXIOWriter constructor, creates and opens .xlsx file 17 | * \param filename path of .xlsx file to open 18 | * \param sheetname name of worksheet 19 | * \param detectionrows number of rows to buffer in memory, zero for none, defaults to 5 20 | * \sa xlsxiowrite_open() 21 | */ 22 | XLSXIOWriter (const char* filename, const char* sheetname = NULL, size_t detectionrows = 5); 23 | 24 | /*! \brief XLSXIOWriter destructor, closes .xlsx file 25 | * \sa xlsxiowrite_close() 26 | */ 27 | ~XLSXIOWriter (); 28 | 29 | /*! \brief specify the row height to use for the current and next rows 30 | * \param height row height (in text lines), zero for unspecified 31 | * Must be called before the first call to any Add method of the current row 32 | * \sa xlsxiowrite_set_row_height() 33 | */ 34 | void SetRowHeight (size_t height = 0); 35 | 36 | /*! \brief add a column cell 37 | * \param name column name 38 | * \param width column width (in characters) 39 | * Only one row of column names is supported or none. 40 | * Call for each column, and finish column row by calling NextRow(). 41 | * Must be called before any NextRow() or the AddCell methods. 42 | * \sa NextRow() 43 | */ 44 | void AddColumn (const char* name, int width = 0); 45 | 46 | /*! \brief add a cell with string data 47 | * \param value string value 48 | * \sa NextRow() 49 | */ 50 | void AddCellString (const char* value); 51 | 52 | /*! \brief add a cell with integer data 53 | * \param value integer value 54 | * \sa NextRow() 55 | */ 56 | void AddCellInt (long long value); 57 | 58 | /*! \brief add a cell with floating point data 59 | * \param value floating point value 60 | * \sa NextRow() 61 | */ 62 | void AddCellFloat (double value); 63 | 64 | /*! \brief add a cell with date and time data 65 | * \param value date and time value 66 | * \sa NextRow() 67 | */ 68 | void AddCellDateTime (time_t value); 69 | 70 | /*! \brief insertion operators 71 | * \sa AddCellString() 72 | * \name operator<< 73 | * \{ 74 | */ 75 | XLSXIOWriter& operator << (const char* value); 76 | XLSXIOWriter& operator << (const std::string& value); 77 | XLSXIOWriter& operator << (int64_t value); 78 | XLSXIOWriter& operator << (double value); 79 | //XLSXIOWriter& operator << (time_t value); 80 | /*! @} */ 81 | 82 | /*! \brief mark the end of a row (next cell will start on a new row) 83 | * \sa xlsxiowrite_next_row() 84 | * \sa AddCellString() 85 | */ 86 | void NextRow (); 87 | }; 88 | 89 | 90 | 91 | 92 | inline XLSXIOWriter::XLSXIOWriter (const char* filename, const char* sheetname, size_t detectionrows) 93 | { 94 | unlink(filename); 95 | handle = xlsxiowrite_open(filename, sheetname); 96 | xlsxiowrite_set_detection_rows(handle, detectionrows); 97 | } 98 | 99 | inline XLSXIOWriter::~XLSXIOWriter () 100 | { 101 | xlsxiowrite_close(handle); 102 | } 103 | 104 | inline void XLSXIOWriter::SetRowHeight (size_t height) 105 | { 106 | xlsxiowrite_set_row_height(handle, height); 107 | } 108 | 109 | inline void XLSXIOWriter::AddColumn (const char* name, int width) 110 | { 111 | xlsxiowrite_add_column(handle, name, width); 112 | } 113 | 114 | inline void XLSXIOWriter::AddCellString (const char* value) 115 | { 116 | xlsxiowrite_add_cell_string(handle, value); 117 | } 118 | 119 | inline void XLSXIOWriter::AddCellInt (long long value) 120 | { 121 | xlsxiowrite_add_cell_int(handle, value); 122 | } 123 | 124 | inline void XLSXIOWriter::AddCellFloat (double value) 125 | { 126 | xlsxiowrite_add_cell_float(handle, value); 127 | } 128 | 129 | inline void XLSXIOWriter::AddCellDateTime (time_t value) 130 | { 131 | xlsxiowrite_add_cell_datetime(handle, value); 132 | } 133 | 134 | inline XLSXIOWriter& XLSXIOWriter::operator << (const char* value) 135 | { 136 | AddCellString(value); return *this; 137 | } 138 | 139 | inline XLSXIOWriter& XLSXIOWriter::operator << (const std::string& value) 140 | { 141 | AddCellString(value.c_str()); 142 | return *this; 143 | } 144 | 145 | inline XLSXIOWriter& XLSXIOWriter::operator << (int64_t value) 146 | { 147 | AddCellInt(value); 148 | return *this; 149 | } 150 | 151 | inline XLSXIOWriter& XLSXIOWriter::operator << (double value) 152 | { 153 | AddCellFloat(value); 154 | return *this; 155 | } 156 | 157 | /* 158 | inline XLSXIOWriter& XLSXIOWriter::operator << (time_t value) 159 | { 160 | AddCellDateTime(value); 161 | return *this; 162 | } 163 | */ 164 | 165 | inline void XLSXIOWriter::NextRow () 166 | { 167 | xlsxiowrite_next_row(handle); 168 | } 169 | 170 | 171 | 172 | const char* filename = "example.xlsx"; 173 | 174 | int main (int argc, char* argv[]) 175 | { 176 | XLSXIOWriter* xlsxfile = new XLSXIOWriter(filename); 177 | xlsxfile->SetRowHeight(1); 178 | xlsxfile->AddColumn("Col1"); 179 | xlsxfile->AddColumn("Col2"); 180 | xlsxfile->AddColumn("Col3"); 181 | xlsxfile->AddColumn("Col4"); 182 | xlsxfile->AddColumn("Col5"); 183 | xlsxfile->NextRow(); 184 | int i; 185 | for (i = 0; i < 1000; i++) { 186 | *xlsxfile << "Test" << (char*)NULL << (int64_t)i; 187 | xlsxfile->AddCellDateTime(time(NULL)); 188 | *xlsxfile << 3.1415926; 189 | xlsxfile->NextRow(); 190 | } 191 | delete xlsxfile; 192 | return 0; 193 | } 194 | -------------------------------------------------------------------------------- /examples/example_xlsxio_write_getversion.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | /** 24 | * @file example_xlsxio_write_getversion.c 25 | * @brief XLSX I/O example illustrating different methods of getting the version number. 26 | * @author Brecht Sanders 27 | * 28 | * This example gets the library version using the different methods available. 29 | * \sa xlsxioread_get_version() 30 | * \sa xlsxioread_get_version_string() 31 | * \sa xlsxiowrite_get_version() 32 | * \sa xlsxiowrite_get_version_string() 33 | * \sa XLSXIO_VERSION_* 34 | * \sa XLSXIO_VERSION_STRING 35 | */ 36 | 37 | #include 38 | #include "xlsxio_write.h" 39 | #include "xlsxio_version.h" 40 | 41 | int main (int argc, char* argv[]) 42 | { 43 | /* The following methods call the library to get information, this is the preferred method. */ 44 | 45 | //get version string from library 46 | printf("Version: %s\n", xlsxiowrite_get_version_string()); 47 | 48 | //get version numbers from library 49 | int major, minor, micro; 50 | xlsxiowrite_get_version(&major, &minor, µ); 51 | printf("Version: %i.%i.%i\n", major, minor, micro); 52 | 53 | /* The following methods use header file xlsxio_version.h to get information, avoid when using shared libraries. */ 54 | 55 | //get version string from header 56 | printf("Version: %s\n", XLSXIO_VERSION_STRING); 57 | 58 | //get version numbers from header 59 | printf("Version: %i.%i.%i\n", XLSXIO_VERSION_MAJOR, XLSXIO_VERSION_MINOR, XLSXIO_VERSION_MICRO); 60 | 61 | //get library name and version string from header 62 | printf("Name and version: %s\n", XLSXIOWRITE_FULLNAME); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /include/xlsxio_version.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | /** 24 | * @file xlsxio_version.h 25 | * @brief XLSX I/O header file with version information. 26 | * @author Brecht Sanders 27 | * 28 | * Only use this header file when version information is needed at compile 29 | * time. Otherwise the version functions in the libraries should be used. 30 | * \sa XLSXIO_VERSION_* 31 | * \sa XLSXIO_VERSION_STRING 32 | * \sa xlsxioread_get_version() 33 | * \sa xlsxioread_get_version_string() 34 | * \sa xlsxiowrite_get_version() 35 | * \sa xlsxiowrite_get_version_string() 36 | */ 37 | 38 | #ifndef INCLUDED_XLSXIO_VERSION_H 39 | #define INCLUDED_XLSXIO_VERSION_H 40 | 41 | /*! \brief version number constants 42 | * \sa xlsxioread_get_version() 43 | * \sa xlsxiowrite_get_version() 44 | * \name XLSXIO_VERSION_* 45 | * \{ 46 | */ 47 | /*! \brief major version number */ 48 | #define XLSXIO_VERSION_MAJOR 0 49 | /*! \brief minor version number */ 50 | #define XLSXIO_VERSION_MINOR 2 51 | /*! \brief micro version number */ 52 | #define XLSXIO_VERSION_MICRO 36 53 | /*! @} */ 54 | 55 | /*! \cond PRIVATE */ 56 | #ifndef XML_UNICODE_WCHAR_T 57 | #define XLSXIO_VERSION_STRINGIZE_(major, minor, micro) #major"."#minor"."#micro 58 | #else 59 | #define XLSXIO_VERSION_STRINGIZE_(major, minor, micro) L ## #major"."#minor"."#micro 60 | #endif 61 | #define XLSXIO_VERSION_STRINGIZE(major, minor, micro) XLSXIO_VERSION_STRINGIZE_(major, minor, micro) 62 | /*! \endcond */ 63 | 64 | /*! \brief string with dotted version number \hideinitializer */ 65 | #define XLSXIO_VERSION_STRING XLSXIO_VERSION_STRINGIZE(XLSXIO_VERSION_MAJOR, XLSXIO_VERSION_MINOR, XLSXIO_VERSION_MICRO) 66 | 67 | /*! \brief integer version of the library \hideinitializer */ 68 | #define XLSXIO_VERSION_ID (XLSXIO_VERSION_MAJOR * 10000 + XLSXIO_VERSION_MINOR * 100 + XLSXIO_VERSION_MICRO) 69 | 70 | /*! \brief string with name of XLSX I/O reading library */ 71 | #define XLSXIOREAD_NAME "libxlsxio_read" 72 | /*! \brief string with name of XLSX I/O writing library */ 73 | #define XLSXIOWRITE_NAME "libxlsxio_write" 74 | 75 | /*! \brief string with name and version of XLSX I/O reading library \hideinitializer */ 76 | #define XLSXIOREAD_FULLNAME XLSXIOREAD_NAME " " XLSXIO_VERSION_STRING 77 | /*! \brief string with name and version of XLSX I/O writing library \hideinitializer */ 78 | #define XLSXIOWRITE_FULLNAME XLSXIOWRITE_NAME " " XLSXIO_VERSION_STRING 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/xlsxio_write.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | /** 24 | * @file xlsxio_write.h 25 | * @brief XLSX I/O header file for writing .xlsx files. 26 | * @author Brecht Sanders 27 | * @date 2016 28 | * @copyright MIT 29 | * 30 | * Include this header file to use XLSX I/O for writing .xlsx files and 31 | * link with -lxlsxio_write. 32 | */ 33 | 34 | #ifndef INCLUDED_XLSXIO_WRITE_H 35 | #define INCLUDED_XLSXIO_WRITE_H 36 | 37 | #include 38 | #if defined(_MSC_VER) && _MSC_VER < 1600 39 | typedef signed __int64 int64_t; 40 | #else 41 | #include 42 | #endif 43 | #include 44 | 45 | /*! \cond PRIVATE */ 46 | #ifndef DLL_EXPORT_XLSXIO 47 | #ifdef _WIN32 48 | #if defined(BUILD_XLSXIO_DLL) || defined(BUILD_XLSXIO_SHARED) || defined(xlsxio_write_SHARED_EXPORTS) 49 | #define DLL_EXPORT_XLSXIO __declspec(dllexport) 50 | #elif !defined(STATIC) && !defined(BUILD_XLSXIO_STATIC) && !defined(BUILD_XLSXIO) 51 | #define DLL_EXPORT_XLSXIO __declspec(dllimport) 52 | #else 53 | #define DLL_EXPORT_XLSXIO 54 | #endif 55 | #else 56 | #define DLL_EXPORT_XLSXIO 57 | #endif 58 | #endif 59 | /*! \endcond */ 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | /*! \brief get xlsxio_write version 66 | * \param pmajor pointer to integer that will receive major version number 67 | * \param pminor pointer to integer that will receive minor version number 68 | * \param pmicro pointer to integer that will receive micro version number 69 | * \sa xlsxiowrite_get_version_string() 70 | */ 71 | DLL_EXPORT_XLSXIO void xlsxiowrite_get_version (int* pmajor, int* pminor, int* pmicro); 72 | 73 | /*! \brief get xlsxio_write version string 74 | * \return version string 75 | * \sa xlsxiowrite_get_version() 76 | */ 77 | DLL_EXPORT_XLSXIO const char* xlsxiowrite_get_version_string (); 78 | 79 | /*! \brief write handle for .xlsx object */ 80 | typedef struct xlsxio_write_struct* xlsxiowriter; 81 | 82 | /*! \brief create and open .xlsx file 83 | * \param filename path of .xlsx file to open 84 | * \param sheetname name of worksheet 85 | * \return write handle for .xlsx object or NULL on error 86 | * \sa xlsxiowrite_close() 87 | */ 88 | DLL_EXPORT_XLSXIO xlsxiowriter xlsxiowrite_open (const char* filename, const char* sheetname); 89 | 90 | /*! \brief close .xlsx file 91 | * \param handle write handle for .xlsx object 92 | * \return zero on success, non-zero on error 93 | * \sa xlsxiowrite_open() 94 | */ 95 | DLL_EXPORT_XLSXIO int xlsxiowrite_close (xlsxiowriter handle); 96 | 97 | /*! \brief specify how many initial rows will be buffered in memory to determine column widths 98 | * \param handle write handle for .xlsx object 99 | * \param rows number of rows to buffer in memory, zero for none 100 | * Must be called before the first call to xlsxiowrite_next_row() 101 | * \sa xlsxiowrite_add_column() 102 | * \sa xlsxiowrite_next_row() 103 | */ 104 | DLL_EXPORT_XLSXIO void xlsxiowrite_set_detection_rows (xlsxiowriter handle, size_t rows); 105 | 106 | /*! \brief specify the row height to use for the current and next rows 107 | * \param handle write handle for .xlsx object 108 | * \param height row height (in text lines), zero for unspecified 109 | * Must be called before the first call to any xlsxiowrite_add_ function of the current row 110 | * \sa xlsxiowrite_next_row() 111 | */ 112 | DLL_EXPORT_XLSXIO void xlsxiowrite_set_row_height (xlsxiowriter handle, size_t height); 113 | 114 | /*! \brief add a column cell 115 | * \param handle write handle for .xlsx object 116 | * \param name column name 117 | * \param width column width (in characters) 118 | * Only one row of column names is supported or none. 119 | * Call for each column, and finish column row by calling xlsxiowrite_next_row(). 120 | * Must be called before any xlsxiowrite_next_row() or the xlsxiowrite_add_cell_ functions. 121 | * \sa xlsxiowrite_next_row() 122 | * \sa xlsxiowrite_set_detection_rows() 123 | */ 124 | DLL_EXPORT_XLSXIO void xlsxiowrite_add_column (xlsxiowriter handle, const char* name, int width); 125 | 126 | /*! \brief add a cell with string data 127 | * \param handle write handle for .xlsx object 128 | * \param value string value 129 | * \sa xlsxiowrite_next_row() 130 | */ 131 | DLL_EXPORT_XLSXIO void xlsxiowrite_add_cell_string (xlsxiowriter handle, const char* value); 132 | 133 | /*! \brief add a cell with integer data 134 | * \param handle write handle for .xlsx object 135 | * \param value integer value 136 | * \sa xlsxiowrite_next_row() 137 | */ 138 | DLL_EXPORT_XLSXIO void xlsxiowrite_add_cell_int (xlsxiowriter handle, int64_t value); 139 | 140 | /*! \brief add a cell with floating point data 141 | * \param handle write handle for .xlsx object 142 | * \param value floating point value 143 | * \sa xlsxiowrite_next_row() 144 | */ 145 | DLL_EXPORT_XLSXIO void xlsxiowrite_add_cell_float (xlsxiowriter handle, double value); 146 | 147 | /*! \brief add a cell with date and time data 148 | * \param handle write handle for .xlsx object 149 | * \param value date and time value 150 | * \sa xlsxiowrite_next_row() 151 | */ 152 | DLL_EXPORT_XLSXIO void xlsxiowrite_add_cell_datetime (xlsxiowriter handle, time_t value); 153 | 154 | /*! \brief mark the end of a row (next cell will start on a new row) 155 | * \param handle write handle for .xlsx object 156 | * \sa xlsxiowrite_add_cell_string() 157 | */ 158 | DLL_EXPORT_XLSXIO void xlsxiowrite_next_row (xlsxiowriter handle); 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif 165 | -------------------------------------------------------------------------------- /lib/xlsxio_private.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_XLSXIO_PRIVATE_H 2 | #define INCLUDED_XLSXIO_PRIVATE_H 3 | 4 | #if defined(_MSC_VER) || (defined(__MINGW32__) && !defined(__MINGW64__)) 5 | #define strcasecmp _stricmp 6 | #endif 7 | #ifdef _WIN32 8 | #define wcscasecmp _wcsicmp 9 | #endif 10 | 11 | 12 | #define XLSXIOCHAR XML_Char 13 | 14 | #if !defined(XML_UNICODE_WCHAR_T) && !defined(XML_UNICODE) 15 | 16 | //UTF-8 version 17 | #define X(s) s 18 | #ifdef _WIN32 19 | #define XML_Char_icmp stricmp 20 | #else 21 | #define XML_Char_icmp strcasecmp 22 | #endif 23 | #define XML_Char_len strlen 24 | #define XML_Char_dup strdup 25 | #define XML_Char_cpy strcpy 26 | #define XML_Char_poscpy(d,p,s,l) memcpy(d + p, s, l) 27 | #define XML_Char_malloc(n) ((char*)malloc(n)) 28 | #define XML_Char_realloc(m,n) ((char*)realloc((m), (n))) 29 | #define XML_Char_tol(s) strtol((s), NULL, 10) 30 | #define XML_Char_tod(s) strtod((s), NULL) 31 | #define XML_Char_strtol strtol 32 | #define XML_Char_sscanf sscanf 33 | #define XML_Char_printf printf 34 | 35 | #else 36 | 37 | //UTF-16 version 38 | #include 39 | #define X(s) L##s 40 | #define XML_Char_icmp wcscasecmp 41 | #define XML_Char_len wcslen 42 | #define XML_Char_dup wcsdup 43 | #define XML_Char_cpy wcscpy 44 | #define XML_Char_poscpy(d,p,s,l) wmemcpy(d + p, s, l) 45 | #define XML_Char_malloc(n) ((XML_Char*)malloc((n) * sizeof(XML_Char))) 46 | #define XML_Char_realloc(m,n) ((XML_Char*)realloc((m), (n) * sizeof(XML_Char))) 47 | #define XML_Char_tol(s) wcstol((s), NULL, 10) 48 | #define XML_Char_tod(s) wcstod((s), NULL) 49 | #define XML_Char_strtol wcstol 50 | #define XML_Char_sscanf swscanf 51 | #define XML_Char_printf wprintf 52 | 53 | #endif 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lib/xlsxio_read_sharedstrings.c: -------------------------------------------------------------------------------- 1 | #include "xlsxio_private.h" 2 | #include "xlsxio_read_sharedstrings.h" 3 | #include 4 | //#include 5 | #include 6 | 7 | #if defined(_MSC_VER) || (defined(__MINGW32__) && !defined(__MINGW64__)) 8 | #define strcasecmp _stricmp 9 | #endif 10 | #ifdef _WIN32 11 | #define wcscasecmp _wcsicmp 12 | #endif 13 | 14 | struct sharedstringlist* sharedstringlist_create () 15 | { 16 | struct sharedstringlist* sharedstrings; 17 | if ((sharedstrings = (struct sharedstringlist*)malloc(sizeof(struct sharedstringlist))) != NULL) { 18 | sharedstrings->strings = NULL; 19 | sharedstrings->numstrings = 0; 20 | } 21 | return sharedstrings; 22 | } 23 | 24 | void sharedstringlist_destroy (struct sharedstringlist* sharedstrings) 25 | { 26 | if (sharedstrings) { 27 | size_t i; 28 | for (i = 0; i < sharedstrings->numstrings; i++) 29 | free(sharedstrings->strings[i]); 30 | free(sharedstrings->strings); 31 | free(sharedstrings); 32 | } 33 | } 34 | 35 | size_t sharedstringlist_size (struct sharedstringlist* sharedstrings) 36 | { 37 | if (!sharedstrings) 38 | return 0; 39 | return sharedstrings->numstrings; 40 | } 41 | 42 | int sharedstringlist_add_buffer (struct sharedstringlist* sharedstrings, const XML_Char* data, size_t datalen) 43 | { 44 | XML_Char* s; 45 | XML_Char** p; 46 | if (!sharedstrings) 47 | return 1; 48 | if (!data) { 49 | s = NULL; 50 | } else { 51 | if ((s = XML_Char_malloc(datalen + 1)) == NULL) 52 | return 2; 53 | XML_Char_poscpy(s, 0, data, datalen); 54 | s[datalen] = 0; 55 | } 56 | if ((p = (XML_Char**)realloc(sharedstrings->strings, (sharedstrings->numstrings + 1) * sizeof(sharedstrings->strings[0]))) == NULL) { 57 | free(s); 58 | return 3; 59 | } 60 | sharedstrings->strings = p; 61 | sharedstrings->strings[sharedstrings->numstrings++] = s; 62 | return 0; 63 | } 64 | 65 | int sharedstringlist_add_string (struct sharedstringlist* sharedstrings, const XML_Char* data) 66 | { 67 | return sharedstringlist_add_buffer(sharedstrings, data, (data ? XML_Char_len(data) : 0)); 68 | } 69 | 70 | const XML_Char* sharedstringlist_get (struct sharedstringlist* sharedstrings, size_t index) 71 | { 72 | if (!sharedstrings || index >= sharedstrings->numstrings) 73 | return NULL; 74 | return sharedstrings->strings[index]; 75 | } 76 | 77 | //////////////////////////////////////////////////////////////////////// 78 | 79 | void shared_strings_callback_data_initialize (struct shared_strings_callback_data* data, struct sharedstringlist* sharedstrings) 80 | { 81 | data->xmlparser = NULL; 82 | data->sharedstrings = sharedstrings; 83 | data->insst = 0; 84 | data->insi = 0; 85 | data->intext = 0; 86 | data->text = NULL; 87 | data->textlen = 0; 88 | data->skiptag = NULL; 89 | data->skiptagcount = 0; 90 | data->skip_start = NULL; 91 | data->skip_end = NULL; 92 | data->skip_data = NULL; 93 | } 94 | 95 | void shared_strings_callback_data_cleanup (struct shared_strings_callback_data* data) 96 | { 97 | free(data->text); 98 | free(data->skiptag); 99 | } 100 | 101 | void shared_strings_callback_skip_tag_start (void* callbackdata, const XML_Char* name, const XML_Char** atts) 102 | { 103 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 104 | if (name && XML_Char_icmp(name, data->skiptag) == 0) { 105 | //increment nesting level 106 | data->skiptagcount++; 107 | } 108 | } 109 | 110 | void shared_strings_callback_skip_tag_end (void* callbackdata, const XML_Char* name) 111 | { 112 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 113 | if (!name || XML_Char_icmp(name, data->skiptag) == 0) { 114 | if (--data->skiptagcount == 0) { 115 | //restore handlers when done skipping 116 | XML_SetElementHandler(data->xmlparser, data->skip_start, data->skip_end); 117 | XML_SetCharacterDataHandler(data->xmlparser, data->skip_data); 118 | free(data->skiptag); 119 | data->skiptag = NULL; 120 | } 121 | } 122 | } 123 | 124 | void shared_strings_callback_find_sharedstringtable_start (void* callbackdata, const XML_Char* name, const XML_Char** atts) 125 | { 126 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 127 | if (XML_Char_icmp(name, X("sst")) == 0) { 128 | XML_SetElementHandler(data->xmlparser, shared_strings_callback_find_shared_stringitem_start, NULL); 129 | } 130 | } 131 | 132 | void shared_strings_callback_find_sharedstringtable_end (void* callbackdata, const XML_Char* name) 133 | { 134 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 135 | if (XML_Char_icmp(name, X("sst")) == 0) { 136 | XML_SetElementHandler(data->xmlparser, shared_strings_callback_find_sharedstringtable_start, NULL); 137 | } 138 | } 139 | 140 | void shared_strings_callback_find_shared_stringitem_start (void* callbackdata, const XML_Char* name, const XML_Char** atts) 141 | { 142 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 143 | if (XML_Char_icmp(name, X("si")) == 0) { 144 | if (data->text) 145 | free(data->text); 146 | data->text = NULL; 147 | data->textlen = 0; 148 | XML_SetElementHandler(data->xmlparser, shared_strings_callback_find_shared_string_start, shared_strings_callback_find_sharedstringtable_end); 149 | } 150 | } 151 | 152 | void shared_strings_callback_find_shared_stringitem_end (void* callbackdata, const XML_Char* name) 153 | { 154 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 155 | if (XML_Char_icmp(name, X("si")) == 0) { 156 | sharedstringlist_add_buffer(data->sharedstrings, data->text, data->textlen); 157 | if (data->text) 158 | free(data->text); 159 | data->text = NULL; 160 | data->textlen = 0; 161 | XML_SetElementHandler(data->xmlparser, shared_strings_callback_find_shared_stringitem_start, shared_strings_callback_find_sharedstringtable_end); 162 | } else { 163 | shared_strings_callback_find_sharedstringtable_end(callbackdata, name); 164 | } 165 | } 166 | 167 | void shared_strings_callback_find_shared_string_start (void* callbackdata, const XML_Char* name, const XML_Char** atts) 168 | { 169 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 170 | if (XML_Char_icmp(name, X("t")) == 0) { 171 | XML_SetElementHandler(data->xmlparser, NULL, shared_strings_callback_find_shared_string_end); 172 | XML_SetCharacterDataHandler(data->xmlparser, shared_strings_callback_string_data); 173 | } else if (XML_Char_icmp(name, X("rPh")) == 0) { 174 | data->skiptag = XML_Char_dup(name); 175 | data->skiptagcount = 1; 176 | data->skip_start = shared_strings_callback_find_shared_string_start; 177 | data->skip_end = shared_strings_callback_find_shared_stringitem_end; 178 | data->skip_data = NULL; 179 | XML_SetElementHandler(data->xmlparser, shared_strings_callback_skip_tag_start, shared_strings_callback_skip_tag_end); 180 | XML_SetCharacterDataHandler(data->xmlparser, NULL); 181 | } 182 | } 183 | 184 | void shared_strings_callback_find_shared_string_end (void* callbackdata, const XML_Char* name) 185 | { 186 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 187 | if (XML_Char_icmp(name, X("t")) == 0) { 188 | XML_SetElementHandler(data->xmlparser, shared_strings_callback_find_shared_string_start, shared_strings_callback_find_shared_stringitem_end); 189 | XML_SetCharacterDataHandler(data->xmlparser, NULL); 190 | } else { 191 | shared_strings_callback_find_shared_stringitem_end(callbackdata, name); 192 | } 193 | } 194 | 195 | void shared_strings_callback_string_data (void* callbackdata, const XML_Char* buf, int buflen) 196 | { 197 | struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata; 198 | if ((data->text = XML_Char_realloc(data->text, data->textlen + buflen)) == NULL) { 199 | //memory allocation error 200 | data->textlen = 0; 201 | } else { 202 | XML_Char_poscpy(data->text, data->textlen, buf, buflen); 203 | data->textlen += buflen; 204 | } 205 | } 206 | 207 | //////////////////////////////////////////////////////////////////////// 208 | 209 | -------------------------------------------------------------------------------- /lib/xlsxio_read_sharedstrings.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_XLSXIO_READ_SHAREDSTRINGS_H 2 | #define INCLUDED_XLSXIO_READ_SHAREDSTRINGS_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct sharedstringlist { 12 | XML_Char** strings; 13 | size_t numstrings; 14 | }; 15 | 16 | struct sharedstringlist* sharedstringlist_create (); 17 | void sharedstringlist_destroy (struct sharedstringlist* sharedstrings); 18 | size_t sharedstringlist_size (struct sharedstringlist* sharedstrings); 19 | int sharedstringlist_add_buffer (struct sharedstringlist* sharedstrings, const XML_Char* data, size_t datalen); 20 | int sharedstringlist_add_string (struct sharedstringlist* sharedstrings, const XML_Char* data); 21 | const XML_Char* sharedstringlist_get (struct sharedstringlist* sharedstrings, size_t index); 22 | 23 | //////////////////////////////////////////////////////////////////////// 24 | 25 | struct shared_strings_callback_data { 26 | XML_Parser xmlparser; 27 | struct sharedstringlist* sharedstrings; 28 | int insst; 29 | int insi; 30 | int intext; 31 | XML_Char* text; 32 | size_t textlen; 33 | XML_Char* skiptag; //tag to skip 34 | size_t skiptagcount; //nesting level for current tag to skip 35 | XML_StartElementHandler skip_start; //start handler to set after skipping 36 | XML_EndElementHandler skip_end; //end handler to set after skipping 37 | XML_CharacterDataHandler skip_data; //data handler to set after skipping 38 | }; 39 | 40 | void shared_strings_callback_data_initialize (struct shared_strings_callback_data* data, struct sharedstringlist* sharedstrings); 41 | void shared_strings_callback_data_cleanup (struct shared_strings_callback_data* data); 42 | void shared_strings_callback_skip_tag_start (void* callbackdata, const XML_Char* name, const XML_Char** atts); 43 | void shared_strings_callback_skip_tag_end (void* callbackdata, const XML_Char* name); 44 | void shared_strings_callback_find_sharedstringtable_start (void* callbackdata, const XML_Char* name, const XML_Char** atts); 45 | void shared_strings_callback_find_sharedstringtable_end (void* callbackdata, const XML_Char* name); 46 | void shared_strings_callback_find_shared_stringitem_start (void* callbackdata, const XML_Char* name, const XML_Char** atts); 47 | void shared_strings_callback_find_shared_stringitem_end (void* callbackdata, const XML_Char* name); 48 | void shared_strings_callback_find_shared_string_start (void* callbackdata, const XML_Char* name, const XML_Char** atts); 49 | void shared_strings_callback_find_shared_string_end (void* callbackdata, const XML_Char* name); 50 | void shared_strings_callback_string_data (void* callbackdata, const XML_Char* buf, int buflen); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/xlsxio_csv2xlsx.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #ifdef _WIN32 28 | #include //O_BINARY 29 | #endif 30 | #include "xlsxio_write.h" 31 | #include "xlsxio_version.h" 32 | 33 | #define BUFFER_SIZE 256 34 | #define DEFAULT_DETECTION_ROWS 20 35 | 36 | int append_buffer_data (char** pdata, size_t* pdatalen, const char* bufferdata, size_t bufferdatalen) 37 | { 38 | //allocate larger data buffer, abort in case of memory allocation error 39 | if ((*pdata = (char*)realloc(*pdata, *pdatalen + bufferdatalen + 1)) == NULL) { 40 | //memory allocation error 41 | *pdatalen = 0; 42 | return 1; 43 | } 44 | //append new data and adjust length 45 | memcpy(*pdata + *pdatalen, bufferdata, bufferdatalen); 46 | *pdatalen += bufferdatalen; 47 | return 0; 48 | } 49 | 50 | void show_help () 51 | { 52 | printf( 53 | "Usage: xlsxio_csv2xlsx [-h] [-s separator] [-d rows] [-n] csvfile ...\n" 54 | "Parameters:\n" 55 | " -h \tdisplay command line help\n" 56 | " -s separator\tspecify separator to use (default is comma)\n" 57 | " -d rows \trows used for column width detection (default is %i)\n" 58 | " -t \ttread top row as header row\n" 59 | " csvfile \tpath to CSV file (multiple may be specified)\n" 60 | "Description:\n" 61 | "Converts all specified CSV (Comma Separated Values) files to .xlsx files.\n" 62 | "Version: " XLSXIO_VERSION_STRING "\n" 63 | "\n", DEFAULT_DETECTION_ROWS 64 | ); 65 | } 66 | 67 | int main (int argc, char* argv[]) 68 | { 69 | int i; 70 | char* param; 71 | FILE* src; 72 | char separator = ','; 73 | char quote = '"'; 74 | int toprowheaders = 0; 75 | xlsxiowriter xlsxiowrite; 76 | char* sheetname; 77 | char* filename; 78 | size_t xlsxdetectionrows = DEFAULT_DETECTION_ROWS; 79 | //process command line parameters 80 | if (argc == 1) { 81 | show_help(); 82 | return 0; 83 | } 84 | for (i = 1; i < argc; i++) { 85 | //check for command line parameters 86 | if (argv[i][0] && (argv[i][0] == '/' || argv[i][0] == '-')) { 87 | switch (tolower(argv[i][1])) { 88 | case 'h' : 89 | case '?' : 90 | show_help(); 91 | return 0; 92 | case 's' : 93 | if (argv[i][2]) 94 | param = argv[i] + 2; 95 | else if (i + 1 < argc && argv[i + 1]) 96 | param = argv[++i]; 97 | else 98 | param = NULL; 99 | if (param) 100 | separator = param[0]; 101 | continue; 102 | case 'd' : 103 | if (argv[i][2]) 104 | param = argv[i] + 2; 105 | else if (i + 1 < argc && argv[i + 1]) 106 | param = argv[++i]; 107 | else 108 | param = NULL; 109 | if (param) 110 | xlsxdetectionrows = strtol(param, (char**)NULL, 10); 111 | continue; 112 | case 't' : 113 | toprowheaders = 1; 114 | continue; 115 | } 116 | } 117 | //open CSV file 118 | sheetname = NULL; 119 | filename = NULL; 120 | src = NULL; 121 | if (strcmp(argv[i], "-") == 0) { 122 | src = stdin; 123 | #ifdef _WIN32 124 | setmode(fileno(stdin), O_BINARY); 125 | #endif 126 | sheetname = strdup("Sheet1"); 127 | filename = strdup("data.xlsx"); 128 | } else if ((src = fopen(argv[i], "rb")) == NULL) { 129 | fprintf(stderr, "Error opening file: %s\n", argv[i]); 130 | } else { 131 | //determine sheetname 132 | if ((sheetname = strdup(argv[i])) != NULL) { 133 | char* p; 134 | int i; 135 | //strip extension 136 | if ((p = strrchr(sheetname, '.')) != NULL) 137 | *p = 0; 138 | //strip path 139 | i = strlen(sheetname); 140 | while (i-- > 0) { 141 | if (sheetname[i] == '/' 142 | #ifdef _WIN32 143 | || sheetname[i] == '\\' 144 | #endif 145 | ) { 146 | memmove(sheetname, sheetname + i + 1, strlen(sheetname) - i); 147 | break; 148 | } 149 | } 150 | } 151 | //determine output filename 152 | if ((filename = (char*)malloc(strlen(argv[i]) + 6)) == NULL ){ 153 | fprintf(stderr, "Memory allocation error\n"); 154 | } else { 155 | strcpy(filename, argv[i]); 156 | strcat(filename, ".xlsx"); 157 | } 158 | } 159 | if (src && filename && sheetname) { 160 | //create .xslx file 161 | if ((xlsxiowrite = xlsxiowrite_open(filename, sheetname)) != NULL) { 162 | xlsxiowrite_set_detection_rows(xlsxiowrite, xlsxdetectionrows); 163 | xlsxiowrite_set_row_height(xlsxiowrite, 1); 164 | //skip UTF-8 BOM header if present 165 | unsigned char bom[3]; 166 | if (!(fread(bom, 1, 3, src) == 3 && bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF)) { 167 | fseek(src, 0, SEEK_SET); 168 | } 169 | //process CSV file 170 | char buf[BUFFER_SIZE]; 171 | size_t buflen = 0; 172 | size_t bufstart = 0; 173 | size_t bufpos = 0; 174 | char* value = NULL; 175 | size_t valuelen = 0; 176 | size_t unquoted = 1; 177 | char lastchar = 0; 178 | int toprow = 1; 179 | //read data one buffer at a tome 180 | while ((buflen = fread(buf, 1, BUFFER_SIZE, src)) > 0) { 181 | //process each character in buffer 182 | while (bufpos < buflen) { 183 | if (unquoted) { 184 | if (buf[bufpos] == separator || buf[bufpos] == '\n') { 185 | //process end of cell 186 | append_buffer_data(&value, &valuelen, buf + bufstart, bufpos - bufstart); 187 | bufstart = bufpos + 1; 188 | //detect CRLF line breaks and skip CR 189 | if (buf[bufpos] == '\n' && valuelen > 0 && value[valuelen - 1] == '\r') 190 | valuelen--; 191 | //write cell value 192 | if (value) 193 | value[valuelen] = 0; 194 | if (toprow && toprowheaders) 195 | xlsxiowrite_add_column(xlsxiowrite, value, 0); 196 | else 197 | xlsxiowrite_add_cell_string(xlsxiowrite, value); 198 | //clean up cell value 199 | free(value); 200 | value = NULL; 201 | valuelen = 0; 202 | //process end of line 203 | if (buf[bufpos] == '\n') { 204 | xlsxiowrite_next_row(xlsxiowrite); 205 | toprow = 0; 206 | } 207 | } else if (buf[bufpos] == quote) { 208 | //process upen quote 209 | append_buffer_data(&value, &valuelen, buf + bufstart, bufpos - bufstart + (lastchar == quote ? 1 : 0)); 210 | bufstart = bufpos + 1; 211 | unquoted = 0; 212 | } 213 | } else if (buf[bufpos] == quote) { 214 | //process close quote 215 | append_buffer_data(&value, &valuelen, buf + bufstart, bufpos - bufstart); 216 | bufstart = bufpos + 1; 217 | unquoted = 1; 218 | } 219 | //prepare for processing next character 220 | lastchar = buf[bufpos]; 221 | bufpos++; 222 | } 223 | //dump data at end of buffer and reset counters 224 | append_buffer_data(&value, &valuelen, buf + bufstart, bufpos - bufstart); 225 | bufstart = 0; 226 | bufpos = 0; 227 | } 228 | //close .xlsx file 229 | xlsxiowrite_close(xlsxiowrite); 230 | //clean up 231 | free(value); 232 | } 233 | //close CSV file 234 | fclose(src); 235 | } 236 | //clean up 237 | free(filename); 238 | free(sheetname); 239 | } 240 | return 0; 241 | } 242 | -------------------------------------------------------------------------------- /src/xlsxio_read_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "xlsxio_read.h" 5 | 6 | struct xlsx_list_sheets_data { 7 | int index; 8 | char* firstsheet; 9 | }; 10 | 11 | int xlsx_list_sheets_callback (const char* name, void* callbackdata) 12 | { 13 | struct xlsx_list_sheets_data* data = (struct xlsx_list_sheets_data*)callbackdata; 14 | if (!data->firstsheet) 15 | data->firstsheet = strdup(name); 16 | printf("%3i: %s\n", data->index, name); 17 | data->index++; 18 | return 0; 19 | } 20 | 21 | int sheet_row_callback (size_t row, size_t maxcol, void* callbackdata) 22 | { 23 | printf("\n"); 24 | printf("[[%i,%i]]\n", (int)row, (int)maxcol);///// 25 | return 0; 26 | } 27 | 28 | int sheet_cell_callback (size_t row, size_t col, const char* value, void* callbackdata) 29 | { 30 | if (col > 1) 31 | printf("\t"); 32 | printf("[%i,%i]", (int)row, (int)col);///// 33 | if (value) 34 | printf("%s", value); 35 | return 0; 36 | } 37 | 38 | int main (int argc, char* argv[]) 39 | { 40 | int i; 41 | xlsxioreader xlsxioread; 42 | for (i = 1; i < argc; i++) { 43 | if ((xlsxioread = xlsxioread_open(argv[i])) != NULL) { 44 | //list available sheets 45 | struct xlsx_list_sheets_data sheetdata; 46 | printf("Available sheets:\n"); 47 | sheetdata.index = 0; 48 | sheetdata.firstsheet = NULL; 49 | xlsxioread_list_sheets(xlsxioread, xlsx_list_sheets_callback, &sheetdata); 50 | printf("Sheets found: %i\n", sheetdata.index); 51 | 52 | //perform tests 53 | xlsxioread_process(xlsxioread, sheetdata.firstsheet, XLSXIOREAD_SKIP_EMPTY_ROWS *0+XLSXIOREAD_SKIP_ALL_EMPTY , sheet_cell_callback, sheet_row_callback, NULL); 54 | 55 | /**/ 56 | printf("-------------------------------------------------------------------------------\n"); 57 | char* value; 58 | xlsxioreadersheet sheet = xlsxioread_sheet_open(xlsxioread, sheetdata.firstsheet, XLSXIOREAD_SKIP_EMPTY_ROWS); 59 | while (xlsxioread_sheet_next_row(sheet)) { 60 | while ((value = xlsxioread_sheet_next_cell(sheet)) != NULL) { 61 | printf("%s\t", value); 62 | free(value); 63 | } 64 | printf("\n"); 65 | } 66 | xlsxioread_sheet_close(sheet); 67 | printf("-------------------------------------------------------------------------------\n"); 68 | /**/ 69 | 70 | //clean up 71 | free(sheetdata.firstsheet); 72 | xlsxioread_close(xlsxioread); 73 | } 74 | } 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /src/xlsxio_write_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "xlsxio_write.h" 4 | 5 | int main (int argc, char* argv[]) 6 | { 7 | xlsxiowriter handle; 8 | if (argc <= 1) 9 | return 0; 10 | unlink(argv[1]); 11 | if ((handle = xlsxiowrite_open(argv[1], NULL)) == NULL) { 12 | fprintf(stderr, "Error creating zip file\n"); 13 | return 1; 14 | } 15 | //write data 16 | int i; 17 | for (i = 0; i < 1000; i++) { 18 | xlsxiowrite_add_cell_string(handle, "Test"); 19 | xlsxiowrite_add_cell_string(handle, NULL); 20 | xlsxiowrite_add_cell_string(handle, "1"); 21 | xlsxiowrite_add_cell_string(handle, "2"); 22 | xlsxiowrite_add_cell_string(handle, "3"); 23 | xlsxiowrite_next_row(handle); 24 | } 25 | //close data 26 | xlsxiowrite_close(handle); 27 | return 0; 28 | } 29 | 30 | /* 31 | TO DO: 32 | - htmlencode cell values 33 | - value types: integer, floating point, date/time 34 | - alignment 35 | - layout 36 | - header functions 37 | */ 38 | -------------------------------------------------------------------------------- /src/xlsxio_xlsx2csv.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (C) 2016 Brecht Sanders All Rights Reserved 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | *****************************************************************************/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "xlsxio_read.h" 28 | #include "xlsxio_version.h" 29 | 30 | struct xlsx_data { 31 | xlsxioreader xlsxioread; 32 | FILE* dst; 33 | int nobom; 34 | int sheetnumbers; 35 | const char* newline; 36 | char separator; 37 | char quote; 38 | const char* filename; 39 | unsigned int sheetcount; 40 | }; 41 | 42 | int sheet_row_callback (size_t row, size_t maxcol, void* callbackdata) 43 | { 44 | struct xlsx_data* data = (struct xlsx_data*)callbackdata; 45 | fprintf(data->dst, "%s", data->newline); 46 | return 0; 47 | } 48 | 49 | int sheet_cell_callback (size_t row, size_t col, const XLSXIOCHAR* value, void* callbackdata) 50 | { 51 | struct xlsx_data* data = (struct xlsx_data*)callbackdata; 52 | if (col > 1) 53 | fprintf(data->dst, "%c", data->separator); 54 | if (value) { 55 | //print quoted value? 56 | if (data->quote && (strchr(value, data->quote) || strchr(value, data->separator) || strchr(value, '\n') || strchr(value, '\r'))) { 57 | const char* p = value; 58 | fprintf(data->dst, "%c", data->quote); 59 | while (*p) { 60 | //duplicate quote character 61 | if (*p == data->quote) 62 | fprintf(data->dst, "%c%c", *p, *p); 63 | //otherwise just print character 64 | else 65 | fprintf(data->dst, "%c", *p); 66 | p++; 67 | } 68 | fprintf(data->dst, "%c", data->quote); 69 | } else { 70 | fprintf(data->dst, "%s", value); 71 | } 72 | } 73 | return 0; 74 | } 75 | 76 | int xlsx_list_sheets_callback (const char* name, void* callbackdata) 77 | { 78 | char* filename; 79 | struct xlsx_data* data = (struct xlsx_data*)callbackdata; 80 | size_t filenamelen = strlen(data->filename) + (data->sheetnumbers ? 16 : strlen(name)) + 6; 81 | data->sheetcount++; 82 | //determine output file 83 | if ((filename = (char*)malloc(filenamelen)) == NULL) { 84 | fprintf(stderr, "Memory allocation error\n"); 85 | } else { 86 | //determine export filename 87 | if (data->sheetnumbers) 88 | snprintf(filename, filenamelen, "%s.%u.csv", data->filename, data->sheetcount); 89 | else 90 | snprintf(filename, filenamelen, "%s.%s.csv", data->filename, name); 91 | //display status 92 | printf("Sheet found: %s, exporting to: %s\n", name, filename); 93 | //open output file 94 | if ((data->dst = fopen(filename, "wb")) == NULL) { 95 | fprintf(stderr, "Error creating output file: %s\n", filename); 96 | } else { 97 | //write UTF-8 BOM header 98 | if (!data->nobom) 99 | fprintf(data->dst, "\xEF\xBB\xBF"); 100 | //process data 101 | xlsxioread_process(data->xlsxioread, name, XLSXIOREAD_SKIP_EMPTY_ROWS, sheet_cell_callback, sheet_row_callback, data); 102 | //close output file 103 | fclose(data->dst); 104 | } 105 | //clean up 106 | free(filename); 107 | } 108 | return 0; 109 | } 110 | 111 | void show_help () 112 | { 113 | printf( 114 | "Usage: xlsxio_xlsx2csv [-h] [-s separator] [-n] xlsxfile ...\n" 115 | "Parameters:\n" 116 | " -h \tdisplay command line help\n" 117 | " -s separator\tspecify separator to use (default is comma)\n" 118 | " -b \tdon't write UTF-8 BOM signature\n" 119 | " -n \tuse UNIX style line breaks\n" 120 | " -u \tuse sheet number in output file name (instead of sheet name)\n" 121 | " xlsxfile \tpath to .xlsx file (multiple may be specified)\n" 122 | "Description:\n" 123 | "Converts all sheets in all specified .xlsx files to individual CSV (Comma Separated Values) files.\n" 124 | "Version: " XLSXIO_VERSION_STRING "\n" 125 | "\n" 126 | ); 127 | } 128 | 129 | int main (int argc, char* argv[]) 130 | { 131 | int i; 132 | char* param; 133 | xlsxioreader xlsxioread; 134 | struct xlsx_data sheetdata = { 135 | .nobom = 0, 136 | .sheetnumbers = 0, 137 | .newline = "\r\n", 138 | .separator = ',', 139 | .quote = '"', 140 | }; 141 | //process command line parameters 142 | if (argc == 1) { 143 | show_help(); 144 | return 0; 145 | } 146 | for (i = 1; i < argc; i++) { 147 | //check for command line parameters 148 | if (argv[i][0] && (argv[i][0] == '/' || argv[i][0] == '-')) { 149 | switch (tolower(argv[i][1])) { 150 | case 'h' : 151 | case '?' : 152 | show_help(); 153 | return 0; 154 | case 's' : 155 | if (argv[i][2]) 156 | param = argv[i] + 2; 157 | else if (i + 1 < argc && argv[i + 1]) 158 | param = argv[++i]; 159 | else 160 | param = NULL; 161 | if (param) 162 | sheetdata.separator = param[0]; 163 | continue; 164 | case 'b' : 165 | sheetdata.nobom = 1; 166 | continue; 167 | case 'u' : 168 | sheetdata.sheetnumbers = 1; 169 | continue; 170 | case 'n' : 171 | sheetdata.newline = "\n"; 172 | continue; 173 | } 174 | } 175 | //open .xlsx file 176 | if ((xlsxioread = xlsxioread_open(argv[i])) != NULL) { 177 | sheetdata.xlsxioread = xlsxioread; 178 | sheetdata.filename = argv[i]; 179 | sheetdata.sheetcount = 0; 180 | //iterate through available sheets 181 | printf("Processing file: %s\n", argv[i]); 182 | xlsxioread_list_sheets(xlsxioread, xlsx_list_sheets_callback, &sheetdata); 183 | //close .xlsx file 184 | xlsxioread_close(xlsxioread); 185 | } 186 | } 187 | return 0; 188 | } 189 | -------------------------------------------------------------------------------- /template.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: @XLSXIO_NAME@ 7 | Version: @XLSXIO_VER@ 8 | Description: @XLSXIO_DESC@ 9 | URL: https://github.com/brechtsanders/xlsxio 10 | #Requires: 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} @XLSXIO_LDFLAGS@ 13 | #Libs.private: 14 | -------------------------------------------------------------------------------- /templateConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # cmake version configuration file for @XLSXIO_NAME@ 2 | GET_FILENAME_COMPONENT(XLSXIOREAD_ROOT "${CMAKE_CURRENT_LIST_FILE}" PATH) 3 | 4 | # find library file 5 | FIND_LIBRARY(@XLSXIO_LIB@_LIBRARY @XLSXIO_LIB@ PATHS ${XLSXIOREAD_ROOT}/lib /opt/xlsxio/lib PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE} NO_DEFAULT_PATH ) 6 | SET(@XLSXIO_LIB@_LIBRARIES ${@XLSXIO_LIB@_LIBRARY} @XLSXIO_LDFLAGS@) 7 | 8 | # find include file 9 | FIND_PATH(@XLSXIO_LIB@_INCLUDE_DIR @XLSXIO_HEADER@ PATHS ${XLSXIOREAD_ROOT}/include /opt/xlsxio/include NO_DEFAULT_PATH) 10 | SET(@XLSXIO_LIB@_INCLUDE_DIRS ${@XLSXIO_LIB@_INCLUDE_DIR}) 11 | 12 | IF(NOT @XLSXIO_LIB@_LIBRARY OR NOT @XLSXIO_LIB@_INCLUDE_DIR) 13 | # find using pkg_config 14 | INCLUDE(FindPkgConfig) 15 | PKG_CHECK_MODULES(@XLSXIO_LIB@ REQUIRED @XLSXIO_LIB@) 16 | ELSE() 17 | SET(@XLSXIO_LIB@_FOUND TRUE) 18 | ENDIF() 19 | 20 | IF(NOT @XLSXIO_LIB@_FOUND) 21 | MESSAGE(FATAL_ERROR "Unable to find library: @XLSXIO_LIB@") 22 | ENDIF() 23 | -------------------------------------------------------------------------------- /templateConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | # cmake version configuration file for @XLSXIO_NAME@ 2 | set(PACKAGE_VERSION "@XLSXIO_VER@") 3 | 4 | # check whether the requested PACKAGE_FIND_VERSION is compatible 5 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 6 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 7 | else() 8 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 9 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 10 | set(PACKAGE_VERSION_EXACT TRUE) 11 | endif() 12 | endif() 13 | --------------------------------------------------------------------------------