Skip to content

Commit fdcd294

Browse files
committed
Feat: exception message and reader
1. default enable reader 2. exception message
1 parent 201d453 commit fdcd294

File tree

6 files changed

+90
-8
lines changed

6 files changed

+90
-8
lines changed

config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PHP_ARG_WITH(libxlsxio, system libxlsxio,
88
[ --with-libxlsxio=DIR Use system libxlsxio], no, no)
99

1010
PHP_ARG_ENABLE(reader, enable xlsx reader support,
11-
[ --enable-reader Enable xlsx reader?], no, no)
11+
[ --enable-reader Enable xlsx reader?], yes, yes)
1212

1313
if test "$PHP_XLSWRITER" != "no"; then
1414
xls_writer_sources="

include/exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ extern zend_class_entry *vtiful_exception_ce;
1717

1818
VTIFUL_STARTUP_FUNCTION(exception);
1919

20+
char* exception_message_map(int code);
21+
2022
#endif

include/xlswriter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ typedef struct _vtiful_validation_object {
161161
} \
162162
} while(0);
163163

164-
#define WORKSHEET_WRITER_EXCEPTION(error) \
165-
do { \
166-
if(error > LXW_NO_ERROR) { \
167-
zend_throw_exception(vtiful_exception_ce, "Worksheet write exception", error); \
168-
return; \
169-
} \
164+
#define WORKSHEET_WRITER_EXCEPTION(error) \
165+
do { \
166+
if(error > LXW_NO_ERROR) { \
167+
zend_throw_exception(vtiful_exception_ce, exception_message_map(error), error); \
168+
return; \
169+
} \
170170
} while(0)
171171

172172
#define FCALL_TWO_ARGS(bucket) \

kernel/excel.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,11 @@ PHP_METHOD(vtiful_xls, constMemory)
470470
if(obj->write_ptr.workbook == NULL) {
471471
xls_file_path(zs_file_name, dir_path, &file_path);
472472

473-
lxw_workbook_options options = {.constant_memory = LXW_TRUE, .tmpdir = NULL};
473+
lxw_workbook_options options = {
474+
.constant_memory = LXW_TRUE,
475+
.tmpdir = NULL,
476+
.use_zip64 = LXW_TRUE
477+
};
474478

475479
if(zs_sheet_name != NULL) {
476480
sheet_name = ZSTR_VAL(zs_sheet_name);

kernel/exception.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,53 @@ VTIFUL_STARTUP_FUNCTION(exception) {
3333
return SUCCESS;
3434
}
3535
/* }}} */
36+
37+
/** {{{ exception_message_map
38+
*/
39+
char* exception_message_map(int code) {
40+
switch (code) {
41+
case LXW_ERROR_MEMORY_MALLOC_FAILED:
42+
return "Memory error, failed to malloc() required memory.";
43+
case LXW_ERROR_CREATING_XLSX_FILE:
44+
return "Error creating output xlsx file. Usually a permissions error.";
45+
case LXW_ERROR_CREATING_TMPFILE:
46+
return "Error encountered when creating a tmpfile during file assembly.";
47+
case LXW_ERROR_READING_TMPFILE:
48+
return "Error reading a tmpfile.";
49+
case LXW_ERROR_ZIP_FILE_OPERATION:
50+
return "Zlib error with a file operation while creating xlsx file.";
51+
case LXW_ERROR_ZIP_FILE_ADD:
52+
return "Zlib error when adding sub file to xlsx file.";
53+
case LXW_ERROR_ZIP_CLOSE:
54+
return "Zlib error when closing xlsx file.";
55+
case LXW_ERROR_NULL_PARAMETER_IGNORED:
56+
return "NULL function parameter ignored.";
57+
case LXW_ERROR_PARAMETER_VALIDATION:
58+
return "Function parameter validation error.";
59+
case LXW_ERROR_SHEETNAME_LENGTH_EXCEEDED:
60+
return "Worksheet name exceeds Excel's limit of 31 characters.";
61+
case LXW_ERROR_INVALID_SHEETNAME_CHARACTER:
62+
return "Worksheet name contains invalid.";
63+
case LXW_ERROR_SHEETNAME_ALREADY_USED:
64+
return "Worksheet name is already in use.";
65+
case LXW_ERROR_32_STRING_LENGTH_EXCEEDED:
66+
return "Parameter exceeds Excel's limit of 32 characters.";
67+
case LXW_ERROR_128_STRING_LENGTH_EXCEEDED:
68+
return "Parameter exceeds Excel's limit of 128 characters.";
69+
case LXW_ERROR_255_STRING_LENGTH_EXCEEDED:
70+
return "Parameter exceeds Excel's limit of 255 characters.";
71+
case LXW_ERROR_MAX_STRING_LENGTH_EXCEEDED:
72+
return "String exceeds Excel's limit of 32:767 characters.";
73+
case LXW_ERROR_SHARED_STRING_INDEX_NOT_FOUND:
74+
return "Error finding internal string index.";
75+
case LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE:
76+
return "Worksheet row or column index out of range.";
77+
case LXW_ERROR_WORKSHEET_MAX_NUMBER_URLS_EXCEEDED:
78+
return "Maximum number of worksheet URLs (65530) exceeded.";
79+
case LXW_ERROR_IMAGE_DIMENSIONS:
80+
return "Couldn't read image dimensions or DPI.";
81+
default:
82+
return "Unknown error";
83+
}
84+
}
85+
/* }}} */

tests/writer_exception.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
try {
8+
$config = ['path' => './tests'];
9+
10+
$fileObject = new \Vtiful\Kernel\Excel($config);
11+
12+
$fileObject->constMemory('tutorial.xlsx', 'DemoSheet')
13+
->insertText(1, 0, 'viest')
14+
->insertText(0, 0, 'viest');
15+
} catch (\Vtiful\Kernel\Exception $exception) {
16+
echo $exception->getCode() . PHP_EOL;
17+
echo $exception->getMessage() . PHP_EOL;
18+
}
19+
?>
20+
--CLEAN--
21+
<?php
22+
@unlink(__DIR__ . '/tutorial.xlsx');
23+
?>
24+
--EXPECT--
25+
23
26+
Worksheet row or column index out of range.

0 commit comments

Comments
 (0)