Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement xlsxioread_sheet_next_cell_struct with cell types #47

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.URL
*.a
*.so
*.dylib
obj/
bin/
doc/
Expand All @@ -18,3 +19,7 @@ example_xlsxio_write
example_xlsxio_write_getversion
xlsxio_csv2xlsx
xlsxio_xlsx2csv
lib/*.o
src/*.o
examples/*.o

24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: c

os:
- osx
- linux
- windows

# linux distro
dist: xenial

addons:
apt:
packages: ["libminizip-dev"]
homebrew:
packages: ["minizip"]

script:
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then ./build/ci_windows_prepare; fi
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then export XLSXIO_CMAKE_ARGS="-DMINIZIP_DIR:PATH=$(pwd)/minizip-2.8.4/build"; fi
- cmake . $XLSXIO_CMAKE_ARGS
- cmake --build .
- ./example_xlsxio_write
- ls -lah example.xlsx
- ./example_xlsxio_read
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ SHARED_CFLAGS = -DBUILD_XLSXIO_DLL
LIBS =
LDFLAGS =
ifeq ($(OS),Darwin)
CFLAGS += -I/opt/local/include -I/opt/local/lib/libzip/include
LDFLAGS += -L/opt/local/lib
#CFLAGS += -I/opt/local/include -I/opt/local/lib/libzip/include
#LDFLAGS += -L/opt/local/lib
#CFLAGS += -arch i386 -arch x86_64
#LDFLAGS += -arch i386 -arch x86_64
STRIPFLAG =
Expand Down Expand Up @@ -66,8 +66,8 @@ CFLAGS += -DUSE_MINIZIP
endif

XLSXIOREAD_OBJ = lib/xlsxio_read.o lib/xlsxio_read_sharedstrings.o
XLSXIOREAD_LDFLAGS = $(ZIPLIB_LDFLAGS) -lexpat
XLSXIOREADW_LDFLAGS = $(ZIPLIB_LDFLAGS) -lexpatw
XLSXIOREAD_LDFLAGS += $(ZIPLIB_LDFLAGS) -lexpat
XLSXIOREADW_LDFLAGS += $(ZIPLIB_LDFLAGS) -lexpatw
XLSXIOREAD_SHARED_LDFLAGS =
XLSXIOWRITE_OBJ = lib/xlsxio_write.o
XLSXIOWRITE_LDFLAGS = $(ZIPLIB_LDFLAGS)
Expand Down
20 changes: 20 additions & 0 deletions build/ci_windows_prepare
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -v
set -e

wget https://zlib.net/zlib-1.2.11.tar.gz
tar -xzf zlib-1.2.11.tar.gz
rm zlib-1.2.11.tar.gz

cd zlib-1.2.11

./configure
make
make install

cd contrib/minizip
make
make install

ls -lah
30 changes: 18 additions & 12 deletions examples/example_xlsxio_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ THE SOFTWARE.
#include "xlsxio_read.h"

#if !defined(XML_UNICODE_WCHAR_T) && !defined(XML_UNICODE)
//UTF-8 version
// UTF-8 version
#define X(s) s
#define XML_Char_printf printf
#else
//UTF-16 version
// UTF-16 version
#define X(s) L##s
#define XML_Char_printf wprintf
#endif
Expand All @@ -68,7 +68,7 @@ const char* filename = "example.xlsx";
int main (int argc, char* argv[])
{
#ifdef _WIN32
//switch Windows console to UTF-8
// switch Windows console to UTF-8
SetConsoleOutputCP(CP_UTF8);
#endif

Expand All @@ -81,7 +81,7 @@ int main (int argc, char* argv[])

#if defined(PROCESS_FROM_MEMORY)
{
//load file in memory
// load file in memory
int filehandle;
char* buf = NULL;
size_t buflen = 0;
Expand All @@ -106,7 +106,7 @@ int main (int argc, char* argv[])
}
}
#elif defined(PROCESS_FROM_FILEHANDLE)
//open .xlsx file for reading
// open .xlsx file for reading
int filehandle;
if ((filehandle = open(filename, O_RDONLY | O_BINARY, 0)) == -1) {
fprintf(stderr, "Error opening .xlsx file\n");
Expand All @@ -117,14 +117,14 @@ int main (int argc, char* argv[])
return 1;
}
#else
//open .xlsx file for reading
// open .xlsx file for reading
if ((xlsxioread = xlsxioread_open(filename)) == NULL) {
fprintf(stderr, "Error opening .xlsx file\n");
return 1;
}
#endif

//list available sheets
// list available sheets
xlsxioreadersheetlist sheetlist;
const XLSXIOCHAR* sheetname;
printf("Available sheets:\n");
Expand All @@ -134,21 +134,27 @@ int main (int argc, char* argv[])
}
xlsxioread_sheetlist_close(sheetlist);
}
XML_Char_printf(X("\n"));

// read values from first sheet
xlsxioread_cell value;
const char *typeNames[] = { "none", "value", "boolean", "string", "date" };

//read values from first sheet
XLSXIOCHAR* value;
printf("Contents of first sheet:\n");
xlsxioreadersheet sheet = xlsxioread_sheet_open(xlsxioread, NULL, XLSXIOREAD_SKIP_EMPTY_ROWS);
while (xlsxioread_sheet_next_row(sheet)) {
while ((value = xlsxioread_sheet_next_cell(sheet)) != NULL) {
XML_Char_printf(X("%s\t"), value);
while ((value = xlsxioread_sheet_next_cell_struct(sheet)) != NULL) {
XML_Char_printf(X("%s\t"), value->data);
// print with row num, cell num and type
//XML_Char_printf("cell %zu %zu %s %s %s\n", value->row_num, value->col_num,
// typeNames[value->cell_type], value->number_fmt, value->data);
free(value);
}
printf("\n");
}
xlsxioread_sheet_close(sheet);

//clean up
// clean up
xlsxioread_close(xlsxioread);
return 0;
}
25 changes: 25 additions & 0 deletions include/xlsxio_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ DLL_EXPORT_XLSXIO const XLSXIOCHAR* xlsxioread_get_version_string ();

/*! \brief read handle for .xlsx object */
typedef struct xlsxio_read_struct* xlsxioreader;
typedef struct xlsxio_read_struct xlsxio_read_struct;

DLL_EXPORT_XLSXIO typedef enum {
cell_type_none,
cell_type_value,
cell_type_boolean,
cell_type_string,
cell_type_date
} cell_type_enum;

struct data_sheet_cell_data {
size_t row_num;
size_t col_num;
char* data;
cell_type_enum cell_type;
char* number_fmt;
};

typedef struct data_sheet_cell_data* xlsxioread_cell;

//typedef struct data_sheet_callback_data* xlsxioread_cell;

/*! \brief open .xlsx file
* \param filename path of .xlsx file to open
Expand Down Expand Up @@ -254,6 +275,8 @@ DLL_EXPORT_XLSXIO int xlsxioread_sheet_next_row (xlsxioreadersheet sheethandle);
*/
DLL_EXPORT_XLSXIO XLSXIOCHAR* xlsxioread_sheet_next_cell (xlsxioreadersheet sheethandle);

DLL_EXPORT_XLSXIO struct data_sheet_cell_data* xlsxioread_sheet_next_cell_struct (xlsxioreadersheet sheethandle);

/*! \brief get next cell from worksheet as a string
* \param sheethandle read handle for worksheet object
* \param pvalue pointer where string will be stored if data is available (caller must free the result)
Expand Down Expand Up @@ -290,6 +313,8 @@ DLL_EXPORT_XLSXIO int xlsxioread_sheet_next_cell_float (xlsxioreadersheet sheeth
*/
DLL_EXPORT_XLSXIO int xlsxioread_sheet_next_cell_datetime (xlsxioreadersheet sheethandle, time_t* pvalue);

void xlsxioread_debug_internals(xlsxioreader handle);

#ifdef __cplusplus
}
#endif
Expand Down
Loading