Skip to content

Commit 2de95de

Browse files
authored
Merge pull request #246 from viest/dev
windows full function support
2 parents 98188f1 + 603f037 commit 2de95de

17 files changed

+3909
-240
lines changed

.appveyor.yml

Lines changed: 223 additions & 204 deletions
Large diffs are not rendered by default.

.gitmodules

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@
55
[submodule "library/libexpat"]
66
path = library/libexpat
77
url = https://github.com/libexpat/libexpat.git
8-
branch = R_2_2_7
9-
[submodule "library/libxlsxio"]
10-
path = library/libxlsxio
11-
url = https://github.com/brechtsanders/xlsxio.git
12-
branch = 0.2.26
8+
branch = R_2_2_7

config.w32

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,77 @@ ARG_WITH("xlswriter", "xlswriter support", "no");
44

55
if (PHP_XLSWRITER != "no") {
66

7-
if (CHECK_LIB("xlsxwriter.lib;xlsxwriter_a.lib", "xlswriter", PHP_XLSWRITER) &&
8-
CHECK_HEADER_ADD_INCLUDE("xlsxwriter.h", "CFLAGS_XLSWRITER", PHP_PHP_BUILD + "\\include;" + PHP_XLSWRITER) &&
9-
CHECK_HEADER_ADD_INCLUDE("xlsxwriter/format.h", "CFLAGS_XLSWRITER", PHP_PHP_BUILD + "\\include;" + PHP_XLSWRITER) &&
10-
CHECK_HEADER_ADD_INCLUDE("xlsxwriter/packager.h", "CFLAGS_XLSWRITER", PHP_PHP_BUILD + "\\include;" + PHP_XLSWRITER) &&
11-
CHECK_HEADER_ADD_INCLUDE("xlswriter.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\include;" + PHP_EXTRA_INCLUDES)) {
12-
7+
if (
8+
CHECK_HEADER_ADD_INCLUDE("minizip/zip.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\library\\libxlsxwriter\\third_party;" + PHP_EXTRA_INCLUDES) &&
9+
CHECK_HEADER_ADD_INCLUDE("xlsxwriter.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\library\\libxlsxwriter\\include;" + PHP_EXTRA_INCLUDES) &&
10+
CHECK_HEADER_ADD_INCLUDE("expat.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\library\\libexpat\\expat\\lib;" + PHP_EXTRA_INCLUDES) &&
11+
CHECK_HEADER_ADD_INCLUDE("xlsxio_read.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\library\\libxlsxio\\include;" + PHP_EXTRA_INCLUDES) &&
12+
CHECK_HEADER_ADD_INCLUDE("xlswriter.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\include;" + PHP_EXTRA_INCLUDES)
13+
) {
1314
EXTENSION("xlswriter", "xlswriter.c")
1415

15-
ADD_FLAG("CFLAGS_XLSWRITER", ' /I "' + configure_module_dirname + '" ');
16+
ADD_FLAG("CFLAGS_XLSWRITER", ' /D ENABLE_READER /D USE_SYSTEM_MINIZIP /D USE_MINIZIP /I "' + configure_module_dirname + '" ');
1617

1718
AC_DEFINE("HAVE_LXW_VERSION", 1, "lxw_version available in 0.7.7");
1819

19-
ADD_SOURCES(configure_module_dirname + "\\kernel", "common.c resource.c exception.c excel.c write.c format.c chart.c", "xlswriter");
20+
ADD_SOURCES(configure_module_dirname + "\\kernel", "\
21+
exception.c \
22+
resource.c \
23+
common.c \
24+
excel.c \
25+
write.c \
26+
format.c \
27+
chart.c \
28+
read.c \
29+
csv.c \
30+
", "xlswriter");
31+
32+
ADD_SOURCES(configure_module_dirname + "\\library\\libxlsxwriter\\third_party\\minizip", "\
33+
ioapi.c \
34+
iowin32.c \
35+
mztools.c \
36+
unzip.c \
37+
zip.c \
38+
", "xlswriter");
39+
40+
ADD_SOURCES(configure_module_dirname + "\\library\\libxlsxwriter\\third_party\\tmpfileplus", "\
41+
tmpfileplus.c \
42+
", "xlswriter");
43+
44+
ADD_SOURCES(configure_module_dirname + "\\library\\libxlsxwriter\\src", "\
45+
app.c \
46+
chart.c \
47+
content_types.c \
48+
core.c \
49+
custom.c \
50+
drawing.c \
51+
format.c \
52+
hash_table.c \
53+
packager.c \
54+
relationships.c \
55+
shared_strings.c \
56+
styles.c \
57+
theme.c \
58+
utility.c \
59+
workbook.c \
60+
worksheet.c \
61+
xmlwriter.c \
62+
", "xlswriter", "libxlsxwriter");
63+
64+
ADD_SOURCES(configure_module_dirname + "\\library\\libexpat\\expat\\lib", "\
65+
loadlibrary.c \
66+
xmlparse.c \
67+
xmlrole.c \
68+
xmltok.c \
69+
xmltok_impl.c \
70+
xmltok_ns.c \
71+
", "xlswriter");
72+
73+
ADD_SOURCES(configure_module_dirname + "\\library\\libxlsxio\\lib", "\
74+
xlsxio_read.c \
75+
xlsxio_read_sharedstrings.c \
76+
", "xlswriter");
2077
} else {
2178
WARNING("xlswriter not enabled, xlsxwriter.lib or headers not found");
2279
}
23-
24-
}
80+
}

kernel/excel.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "xlswriter.h"
1414
#include "ext/date/php_date.h"
15+
#include "ext/standard/php_filestat.h"
1516

1617
zend_class_entry *vtiful_xls_ce;
1718

@@ -273,7 +274,7 @@ PHP_METHOD(vtiful_xls, __construct)
273274
PHP_METHOD(vtiful_xls, fileName)
274275
{
275276
char *sheet_name = NULL;
276-
zval file_path, *dir_path = NULL;
277+
zval file_path, dir_exists, *dir_path = NULL;
277278
zend_string *zs_file_name = NULL, *zs_sheet_name = NULL;
278279

279280
ZEND_PARSE_PARAMETERS_START(1, 2)
@@ -282,10 +283,17 @@ PHP_METHOD(vtiful_xls, fileName)
282283
Z_PARAM_STR(zs_sheet_name)
283284
ZEND_PARSE_PARAMETERS_END();
284285

286+
ZVAL_NULL(&dir_exists);
285287
ZVAL_COPY(return_value, getThis());
286288

287289
GET_CONFIG_PATH(dir_path, vtiful_xls_ce, return_value);
288290

291+
php_stat(ZSTR_VAL(Z_STR_P(dir_path)), strlen(ZSTR_VAL(Z_STR_P(dir_path))), FS_IS_DIR, &dir_exists);
292+
293+
if (Z_TYPE(dir_exists) == IS_FALSE) {
294+
zend_throw_exception(vtiful_exception_ce, "Configure 'path' directory does not exist", 121);
295+
}
296+
289297
xls_object *obj = Z_XLS_P(getThis());
290298

291299
if(obj->write_ptr.workbook == NULL) {
@@ -302,6 +310,8 @@ PHP_METHOD(vtiful_xls, fileName)
302310

303311
zval_ptr_dtor(&file_path);
304312
}
313+
314+
zval_ptr_dtor(&dir_exists);
305315
}
306316
/* }}} */
307317

@@ -913,15 +923,15 @@ PHP_METHOD(vtiful_xls, stringFromColumnIndex)
913923
PHP_METHOD(vtiful_xls, gridline)
914924
{
915925
zend_long option = LXW_SHOW_ALL_GRIDLINES;
916-
926+
917927
ZEND_PARSE_PARAMETERS_START(1, 1)
918928
Z_PARAM_LONG(option)
919929
ZEND_PARSE_PARAMETERS_END();
920-
930+
921931
ZVAL_COPY(return_value, getThis());
922932

923933
xls_object* obj = Z_XLS_P(getThis());
924-
934+
925935
gridlines(&obj->write_ptr, option);
926936
}
927937
/* }}} */
@@ -1236,7 +1246,7 @@ zend_function_entry xls_methods[] = {
12361246

12371247
PHP_ME(vtiful_xls, zoom, xls_sheet_zoom_arginfo, ZEND_ACC_PUBLIC)
12381248
PHP_ME(vtiful_xls, gridline, xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC)
1239-
1249+
12401250
PHP_ME(vtiful_xls, columnIndexFromString, xls_index_to_string, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12411251
PHP_ME(vtiful_xls, stringFromColumnIndex, xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12421252

@@ -1285,7 +1295,7 @@ VTIFUL_STARTUP_FUNCTION(excel) {
12851295
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "GRIDLINES_SHOW_ALL", LXW_SHOW_ALL_GRIDLINES)
12861296
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "GRIDLINES_SHOW_PRINT", LXW_SHOW_PRINT_GRIDLINES)
12871297
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "GRIDLINES_SHOW_SCREEN", LXW_SHOW_SCREEN_GRIDLINES)
1288-
1298+
12891299
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_INT, READ_TYPE_INT);
12901300
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_DOUBLE, READ_TYPE_DOUBLE);
12911301
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_STRING, READ_TYPE_STRING);

kernel/read.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515

1616
/* {{{ */
1717
xlsxioreader file_open(const char *directory, const char *file_name) {
18-
char path[strlen(directory) + strlen(file_name) + 2];
18+
char *path = (char *)emalloc(strlen(directory) + strlen(file_name) + 2);
1919
xlsxioreader file;
2020

21-
lxw_strcpy(path, directory);
21+
strcpy(path, directory);
2222
strcat(path, "/");
2323
strcat(path, file_name);
2424

2525
if ((file = xlsxioread_open(path)) == NULL) {
26+
efree(path);
2627
zend_throw_exception(vtiful_exception_ce, "Failed to open file", 100);
2728
return NULL;
2829
}
2930

31+
efree(path);
3032
return file;
3133
}
3234
/* }}} */

library/libxlsxio

Lines changed: 0 additions & 1 deletion
This file was deleted.

library/libxlsxio/LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.

0 commit comments

Comments
 (0)