excel.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. +----------------------------------------------------------------------+
  3. | XlsWriter Extension |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2017-2018 The Viest |
  6. +----------------------------------------------------------------------+
  7. | http://www.viest.me |
  8. +----------------------------------------------------------------------+
  9. | Author: viest <[email protected]> |
  10. +----------------------------------------------------------------------+
  11. */
  12. #include "xlswriter.h"
  13. zend_class_entry *vtiful_xls_ce;
  14. static zend_object_handlers vtiful_xls_handlers;
  15. static zend_always_inline void *vtiful_object_alloc(size_t obj_size, zend_class_entry *ce) {
  16. void *obj = emalloc(obj_size + zend_object_properties_size(ce));
  17. memset(obj, 0, obj_size);
  18. return obj;
  19. }
  20. /* {{{ xls_objects_new
  21. */
  22. PHP_VTIFUL_API zend_object *vtiful_xls_objects_new(zend_class_entry *ce)
  23. {
  24. xls_object *intern = vtiful_object_alloc(sizeof(xls_object), ce);
  25. SHEET_LINE_INIT(intern)
  26. zend_object_std_init(&intern->zo, ce);
  27. object_properties_init(&intern->zo, ce);
  28. intern->zo.handlers = &vtiful_xls_handlers;
  29. return &intern->zo;
  30. }
  31. /* }}} */
  32. /* {{{ vtiful_xls_objects_free
  33. */
  34. static void vtiful_xls_objects_free(zend_object *object)
  35. {
  36. xls_object *intern = php_vtiful_xls_fetch_object(object);
  37. lxw_workbook_free(intern->ptr.workbook);
  38. zend_object_std_dtor(&intern->zo);
  39. }
  40. /* }}} */
  41. /* {{{ ARG_INFO
  42. */
  43. ZEND_BEGIN_ARG_INFO_EX(xls_construct_arginfo, 0, 0, 1)
  44. ZEND_ARG_INFO(0, config)
  45. ZEND_END_ARG_INFO()
  46. ZEND_BEGIN_ARG_INFO_EX(xls_file_name_arginfo, 0, 0, 1)
  47. ZEND_ARG_INFO(0, file_name)
  48. ZEND_ARG_INFO(0, sheet_name)
  49. ZEND_END_ARG_INFO()
  50. ZEND_BEGIN_ARG_INFO_EX(xls_const_memory_arginfo, 0, 0, 1)
  51. ZEND_ARG_INFO(0, file_name)
  52. ZEND_ARG_INFO(0, sheet_name)
  53. ZEND_END_ARG_INFO()
  54. ZEND_BEGIN_ARG_INFO_EX(xls_file_add_sheet, 0, 0, 1)
  55. ZEND_ARG_INFO(0, sheet_name)
  56. ZEND_END_ARG_INFO()
  57. ZEND_BEGIN_ARG_INFO_EX(xls_file_checkout_sheet, 0, 0, 1)
  58. ZEND_ARG_INFO(0, sheet_name)
  59. ZEND_END_ARG_INFO()
  60. ZEND_BEGIN_ARG_INFO_EX(xls_header_arginfo, 0, 0, 1)
  61. ZEND_ARG_INFO(0, header)
  62. ZEND_END_ARG_INFO()
  63. ZEND_BEGIN_ARG_INFO_EX(xls_data_arginfo, 0, 0, 1)
  64. ZEND_ARG_INFO(0, data)
  65. ZEND_END_ARG_INFO()
  66. ZEND_BEGIN_ARG_INFO_EX(xls_insert_text_arginfo, 0, 0, 4)
  67. ZEND_ARG_INFO(0, row)
  68. ZEND_ARG_INFO(0, column)
  69. ZEND_ARG_INFO(0, data)
  70. ZEND_ARG_INFO(0, format_handle)
  71. ZEND_END_ARG_INFO()
  72. ZEND_BEGIN_ARG_INFO_EX(xls_insert_url_arginfo, 0, 0, 4)
  73. ZEND_ARG_INFO(0, row)
  74. ZEND_ARG_INFO(0, column)
  75. ZEND_ARG_INFO(0, url)
  76. ZEND_ARG_INFO(0, format)
  77. ZEND_END_ARG_INFO()
  78. ZEND_BEGIN_ARG_INFO_EX(xls_insert_chart_arginfo, 0, 0, 3)
  79. ZEND_ARG_INFO(0, row)
  80. ZEND_ARG_INFO(0, column)
  81. ZEND_ARG_INFO(0, chart_resource)
  82. ZEND_END_ARG_INFO()
  83. ZEND_BEGIN_ARG_INFO_EX(xls_insert_image_arginfo, 0, 0, 3)
  84. ZEND_ARG_INFO(0, row)
  85. ZEND_ARG_INFO(0, column)
  86. ZEND_ARG_INFO(0, image)
  87. ZEND_ARG_INFO(0, width)
  88. ZEND_ARG_INFO(0, height)
  89. ZEND_END_ARG_INFO()
  90. ZEND_BEGIN_ARG_INFO_EX(xls_insert_formula_arginfo, 0, 0, 3)
  91. ZEND_ARG_INFO(0, row)
  92. ZEND_ARG_INFO(0, column)
  93. ZEND_ARG_INFO(0, formula)
  94. ZEND_END_ARG_INFO()
  95. ZEND_BEGIN_ARG_INFO_EX(xls_auto_filter_arginfo, 0, 0, 1)
  96. ZEND_ARG_INFO(0, range)
  97. ZEND_END_ARG_INFO()
  98. ZEND_BEGIN_ARG_INFO_EX(xls_merge_cells_arginfo, 0, 0, 2)
  99. ZEND_ARG_INFO(0, range)
  100. ZEND_ARG_INFO(0, data)
  101. ZEND_END_ARG_INFO()
  102. ZEND_BEGIN_ARG_INFO_EX(xls_set_column_arginfo, 0, 0, 3)
  103. ZEND_ARG_INFO(0, format_handle)
  104. ZEND_ARG_INFO(0, range)
  105. ZEND_ARG_INFO(0, width)
  106. ZEND_END_ARG_INFO()
  107. ZEND_BEGIN_ARG_INFO_EX(xls_set_row_arginfo, 0, 0, 3)
  108. ZEND_ARG_INFO(0, format_handle)
  109. ZEND_ARG_INFO(0, range)
  110. ZEND_ARG_INFO(0, height)
  111. ZEND_END_ARG_INFO()
  112. /* }}} */
  113. /** {{{ \Vtiful\Kernel\xls::__construct(array $config)
  114. */
  115. PHP_METHOD(vtiful_xls, __construct)
  116. {
  117. zval *config, *c_path;
  118. ZEND_PARSE_PARAMETERS_START(1, 1)
  119. Z_PARAM_ARRAY(config)
  120. ZEND_PARSE_PARAMETERS_END();
  121. if((c_path = zend_hash_str_find(Z_ARRVAL_P(config), ZEND_STRL(V_XLS_PAT))) == NULL)
  122. {
  123. zend_throw_exception(vtiful_exception_ce, "Lack of 'path' configuration", 110);
  124. return;
  125. }
  126. if(Z_TYPE_P(c_path) != IS_STRING)
  127. {
  128. zend_throw_exception(vtiful_exception_ce, "Configure 'path' must be a string type", 120);
  129. return;
  130. }
  131. add_property_zval(getThis(), V_XLS_COF, config);
  132. }
  133. /* }}} */
  134. /** {{{ \Vtiful\Kernel\xls::filename(string $fileName [, string $sheetName])
  135. */
  136. PHP_METHOD(vtiful_xls, fileName)
  137. {
  138. zval file_path, *dir_path = NULL;
  139. zend_string *zs_file_name = NULL, *zs_sheet_name = NULL;
  140. char *sheet_name = NULL;
  141. ZEND_PARSE_PARAMETERS_START(1, 2)
  142. Z_PARAM_STR(zs_file_name)
  143. Z_PARAM_OPTIONAL
  144. Z_PARAM_STR(zs_sheet_name)
  145. ZEND_PARSE_PARAMETERS_END();
  146. ZVAL_COPY(return_value, getThis());
  147. GET_CONFIG_PATH(dir_path, vtiful_xls_ce, return_value);
  148. xls_object *obj = Z_XLS_P(getThis());
  149. if(obj->ptr.workbook == NULL) {
  150. xls_file_path(zs_file_name, dir_path, &file_path);
  151. if(zs_sheet_name != NULL) {
  152. sheet_name = ZSTR_VAL(zs_sheet_name);
  153. }
  154. obj->ptr.workbook = workbook_new(Z_STRVAL(file_path));
  155. obj->ptr.worksheet = workbook_add_worksheet(obj->ptr.workbook, sheet_name);
  156. add_property_zval(return_value, V_XLS_FIL, &file_path);
  157. zval_ptr_dtor(&file_path);
  158. }
  159. }
  160. /* }}} */
  161. /** {{{ \Vtiful\Kernel\xls::addSheet(string $sheetName)
  162. */
  163. PHP_METHOD(vtiful_xls, addSheet)
  164. {
  165. zend_string *zs_sheet_name = NULL;
  166. char *sheet_name = NULL;
  167. ZEND_PARSE_PARAMETERS_START(0, 1)
  168. Z_PARAM_OPTIONAL
  169. Z_PARAM_STR(zs_sheet_name)
  170. ZEND_PARSE_PARAMETERS_END();
  171. ZVAL_COPY(return_value, getThis());
  172. xls_object *obj = Z_XLS_P(getThis());
  173. SHEET_LINE_INIT(obj)
  174. if(obj->ptr.workbook == NULL) {
  175. zend_throw_exception(vtiful_exception_ce, "Please create a file first, use the filename method", 130);
  176. return;
  177. }
  178. if(zs_sheet_name != NULL) {
  179. sheet_name = ZSTR_VAL(zs_sheet_name);
  180. }
  181. obj->ptr.worksheet = workbook_add_worksheet(obj->ptr.workbook, sheet_name);
  182. }
  183. /* }}} */
  184. /** {{{ \Vtiful\Kernel\xls::checkoutSheet(string $sheetName)
  185. */
  186. PHP_METHOD(vtiful_xls, checkoutSheet)
  187. {
  188. int line = 0;
  189. lxw_worksheet *sheet_t = NULL;
  190. zend_string *zs_sheet_name = NULL;
  191. ZEND_PARSE_PARAMETERS_START(1, 1)
  192. Z_PARAM_STR(zs_sheet_name)
  193. ZEND_PARSE_PARAMETERS_END();
  194. ZVAL_COPY(return_value, getThis());
  195. xls_object *obj = Z_XLS_P(getThis());
  196. if(obj->ptr.workbook == NULL) {
  197. zend_throw_exception(vtiful_exception_ce, "Please create a file first, use the filename method", 130);
  198. return;
  199. }
  200. if ((sheet_t = workbook_get_worksheet_by_name(obj->ptr.workbook, ZSTR_VAL(zs_sheet_name))) == NULL) {
  201. zend_throw_exception(vtiful_exception_ce, "Sheet not fund", 140);
  202. return;
  203. }
  204. line = sheet_t->table->cached_row_num;
  205. SHEET_LINE_SET(obj, line);
  206. obj->ptr.worksheet = sheet_t;
  207. }
  208. /* }}} */
  209. /** {{{ \Vtiful\Kernel\xls::constMemory(string $fileName [, string $sheetName])
  210. */
  211. PHP_METHOD(vtiful_xls, constMemory)
  212. {
  213. zval file_path, *dir_path = NULL;
  214. zend_string *zs_file_name = NULL, *zs_sheet_name = NULL;
  215. char *sheet_name = NULL;
  216. ZEND_PARSE_PARAMETERS_START(1, 2)
  217. Z_PARAM_STR(zs_file_name)
  218. Z_PARAM_OPTIONAL
  219. Z_PARAM_STR(zs_sheet_name)
  220. ZEND_PARSE_PARAMETERS_END();
  221. ZVAL_COPY(return_value, getThis());
  222. GET_CONFIG_PATH(dir_path, vtiful_xls_ce, return_value);
  223. xls_object *obj = Z_XLS_P(getThis());
  224. if(obj->ptr.workbook == NULL) {
  225. xls_file_path(zs_file_name, dir_path, &file_path);
  226. lxw_workbook_options options = {.constant_memory = LXW_TRUE, .tmpdir = NULL};
  227. if(zs_sheet_name != NULL) {
  228. sheet_name = ZSTR_VAL(zs_sheet_name);
  229. }
  230. obj->ptr.workbook = workbook_new_opt(Z_STRVAL(file_path), &options);
  231. obj->ptr.worksheet = workbook_add_worksheet(obj->ptr.workbook, sheet_name);
  232. add_property_zval(return_value, V_XLS_FIL, &file_path);
  233. zval_ptr_dtor(&file_path);
  234. }
  235. }
  236. /* }}} */
  237. /** {{{ \Vtiful\Kernel\xls::header(array $header)
  238. */
  239. PHP_METHOD(vtiful_xls, header)
  240. {
  241. zval *header, *header_value;
  242. zend_long header_l_key;
  243. ZEND_PARSE_PARAMETERS_START(1, 1)
  244. Z_PARAM_ARRAY(header)
  245. ZEND_PARSE_PARAMETERS_END();
  246. ZVAL_COPY(return_value, getThis());
  247. xls_object *obj = Z_XLS_P(getThis());
  248. ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(header), header_l_key, header_value)
  249. type_writer(header_value, 0, header_l_key, &obj->ptr, NULL, NULL);
  250. zval_ptr_dtor(header_value);
  251. ZEND_HASH_FOREACH_END();
  252. }
  253. /* }}} */
  254. /** {{{ \Vtiful\Kernel\xls::data(array $data)
  255. */
  256. PHP_METHOD(vtiful_xls, data)
  257. {
  258. zval *data = NULL, *data_r_value = NULL;
  259. ZEND_PARSE_PARAMETERS_START(1, 1)
  260. Z_PARAM_ARRAY(data)
  261. ZEND_PARSE_PARAMETERS_END();
  262. ZVAL_COPY(return_value, getThis());
  263. xls_object *obj = Z_XLS_P(getThis());
  264. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), data_r_value)
  265. if(Z_TYPE_P(data_r_value) == IS_ARRAY) {
  266. SHEET_LINE_ADD(obj)
  267. ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(data_r_value), Bucket *bucket)
  268. type_writer(&bucket->val, SHEET_CURRENT_LINE(obj), bucket->h, &obj->ptr, NULL, NULL);
  269. zval_ptr_dtor(&bucket->val);
  270. ZEND_HASH_FOREACH_END();
  271. }
  272. ZEND_HASH_FOREACH_END();
  273. }
  274. /* }}} */
  275. /** {{{ \Vtiful\Kernel\xls::output()
  276. */
  277. PHP_METHOD(vtiful_xls, output)
  278. {
  279. zval rv, *file_path;
  280. file_path = zend_read_property(vtiful_xls_ce, getThis(), ZEND_STRL(V_XLS_FIL), 0, &rv TSRMLS_DC);
  281. xls_object *obj = Z_XLS_P(getThis());
  282. workbook_file(&obj->ptr);
  283. add_property_null(getThis(), V_XLS_HANDLE);
  284. add_property_null(getThis(), V_XLS_PAT);
  285. ZVAL_COPY(return_value, file_path);
  286. }
  287. /* }}} */
  288. /** {{{ \Vtiful\Kernel\xls::getHandle()
  289. */
  290. PHP_METHOD(vtiful_xls, getHandle)
  291. {
  292. xls_object *obj = Z_XLS_P(getThis());
  293. RETURN_RES(zend_register_resource(&obj->ptr, le_xls_writer));
  294. }
  295. /* }}} */
  296. /** {{{ \Vtiful\Kernel\xls::insertText(int $row, int $column, string|int|double $data[, string $format, resource $formatHandle])
  297. */
  298. PHP_METHOD(vtiful_xls, insertText)
  299. {
  300. zval *data, *format_handle = NULL;
  301. zend_long row, column;
  302. zend_string *format = NULL;
  303. ZEND_PARSE_PARAMETERS_START(3, 5)
  304. Z_PARAM_LONG(row)
  305. Z_PARAM_LONG(column)
  306. Z_PARAM_ZVAL(data)
  307. Z_PARAM_OPTIONAL
  308. Z_PARAM_STR(format)
  309. Z_PARAM_RESOURCE(format_handle)
  310. ZEND_PARSE_PARAMETERS_END();
  311. ZVAL_COPY(return_value, getThis());
  312. xls_object *obj = Z_XLS_P(getThis());
  313. SHEET_LINE_SET(obj, row);
  314. if (format_handle) {
  315. type_writer(data, row, column, &obj->ptr, format, zval_get_format(format_handle));
  316. } else {
  317. type_writer(data, row, column, &obj->ptr, format, NULL);
  318. }
  319. }
  320. /* }}} */
  321. /** {{{ \Vtiful\Kernel\xls::insertChart(int $row, int $column, resource $chartResource)
  322. */
  323. PHP_METHOD(vtiful_xls, insertChart)
  324. {
  325. zval *chart_resource;
  326. zend_long row, column;
  327. ZEND_PARSE_PARAMETERS_START(3, 3)
  328. Z_PARAM_LONG(row)
  329. Z_PARAM_LONG(column)
  330. Z_PARAM_ZVAL(chart_resource)
  331. ZEND_PARSE_PARAMETERS_END();
  332. ZVAL_COPY(return_value, getThis());
  333. xls_object *obj = Z_XLS_P(getThis());
  334. chart_writer(row, column, zval_get_chart(chart_resource), &obj->ptr);
  335. }
  336. /* }}} */
  337. /** {{{ \Vtiful\Kernel\xls::insertUrl(int $row, int $column, string $url)
  338. */
  339. PHP_METHOD(vtiful_xls, insertUrl)
  340. {
  341. zend_long row, column;
  342. zend_string *url = NULL;
  343. zval *format_handle = NULL;
  344. int argc = ZEND_NUM_ARGS();
  345. ZEND_PARSE_PARAMETERS_START(3, 4)
  346. Z_PARAM_LONG(row)
  347. Z_PARAM_LONG(column)
  348. Z_PARAM_STR(url)
  349. Z_PARAM_OPTIONAL
  350. Z_PARAM_RESOURCE(format_handle)
  351. ZEND_PARSE_PARAMETERS_END();
  352. ZVAL_COPY(return_value, getThis());
  353. xls_object *obj = Z_XLS_P(getThis());
  354. if (argc == 4) {
  355. url_writer(row, column, &obj->ptr, url, zval_get_format(format_handle));
  356. }
  357. if (argc == 3) {
  358. url_writer(row, column, &obj->ptr, url, NULL);
  359. }
  360. }
  361. /* }}} */
  362. /** {{{ \Vtiful\Kernel\xls::insertImage(int $row, int $column, string $imagePath)
  363. */
  364. PHP_METHOD(vtiful_xls, insertImage)
  365. {
  366. zval *image;
  367. zend_long row, column;
  368. double width = 1, height = 1;
  369. ZEND_PARSE_PARAMETERS_START(3, 5)
  370. Z_PARAM_LONG(row)
  371. Z_PARAM_LONG(column)
  372. Z_PARAM_ZVAL(image)
  373. Z_PARAM_OPTIONAL
  374. Z_PARAM_DOUBLE(width)
  375. Z_PARAM_DOUBLE(height)
  376. ZEND_PARSE_PARAMETERS_END();
  377. ZVAL_COPY(return_value, getThis());
  378. xls_object *obj = Z_XLS_P(getThis());
  379. image_writer(image, row, column, width, height, &obj->ptr);
  380. }
  381. /* }}} */
  382. /** {{{ \Vtiful\Kernel\xls::insertImage(int $row, int $column, string $imagePath)
  383. */
  384. PHP_METHOD(vtiful_xls, insertFormula)
  385. {
  386. zval *formula;
  387. zend_long row, column;
  388. ZEND_PARSE_PARAMETERS_START(3, 3)
  389. Z_PARAM_LONG(row)
  390. Z_PARAM_LONG(column)
  391. Z_PARAM_ZVAL(formula)
  392. ZEND_PARSE_PARAMETERS_END();
  393. ZVAL_COPY(return_value, getThis());
  394. xls_object *obj = Z_XLS_P(getThis());
  395. formula_writer(formula, row, column, &obj->ptr);
  396. }
  397. /* }}} */
  398. /** {{{ \Vtiful\Kernel\xls::autoFilter(int $rowStart, int $rowEnd, int $columnStart, int $columnEnd)
  399. */
  400. PHP_METHOD(vtiful_xls, autoFilter)
  401. {
  402. zend_string *range;
  403. ZEND_PARSE_PARAMETERS_START(1, 1)
  404. Z_PARAM_STR(range)
  405. ZEND_PARSE_PARAMETERS_END();
  406. ZVAL_COPY(return_value, getThis());
  407. xls_object *obj = Z_XLS_P(getThis());
  408. auto_filter(range, &obj->ptr);
  409. }
  410. /* }}} */
  411. /** {{{ \Vtiful\Kernel\xls::mergeCells(string $range, string $data)
  412. */
  413. PHP_METHOD(vtiful_xls, mergeCells)
  414. {
  415. zend_string *range, *data;
  416. ZEND_PARSE_PARAMETERS_START(2, 2)
  417. Z_PARAM_STR(range)
  418. Z_PARAM_STR(data)
  419. ZEND_PARSE_PARAMETERS_END();
  420. ZVAL_COPY(return_value, getThis());
  421. xls_object *obj = Z_XLS_P(getThis());
  422. merge_cells(range, data, &obj->ptr);
  423. }
  424. /* }}} */
  425. /** {{{ \Vtiful\Kernel\xls::setColumn(resource $format, string $range [, int $width])
  426. */
  427. PHP_METHOD(vtiful_xls, setColumn)
  428. {
  429. zval *format_handle;
  430. zend_string *range;
  431. double width = 0;
  432. int argc = ZEND_NUM_ARGS();
  433. ZEND_PARSE_PARAMETERS_START(2, 3)
  434. Z_PARAM_STR(range)
  435. Z_PARAM_DOUBLE(width)
  436. Z_PARAM_OPTIONAL
  437. Z_PARAM_RESOURCE(format_handle)
  438. ZEND_PARSE_PARAMETERS_END();
  439. ZVAL_COPY(return_value, getThis());
  440. xls_object *obj = Z_XLS_P(getThis());
  441. if (argc == 3) {
  442. set_column(range, width, &obj->ptr, zval_get_format(format_handle));
  443. }
  444. if (argc == 2) {
  445. set_column(range, width, &obj->ptr, NULL);
  446. }
  447. }
  448. /* }}} */
  449. /** {{{ \Vtiful\Kernel\xls::setRow(resource $format, string $range [, int $heitght])
  450. */
  451. PHP_METHOD(vtiful_xls, setRow)
  452. {
  453. zval *format_handle;
  454. zend_string *range;
  455. double height = 0;
  456. int argc = ZEND_NUM_ARGS();
  457. ZEND_PARSE_PARAMETERS_START(2, 3)
  458. Z_PARAM_STR(range)
  459. Z_PARAM_DOUBLE(height)
  460. Z_PARAM_OPTIONAL
  461. Z_PARAM_RESOURCE(format_handle)
  462. ZEND_PARSE_PARAMETERS_END();
  463. ZVAL_COPY(return_value, getThis());
  464. xls_object *obj = Z_XLS_P(getThis());
  465. if (argc == 3) {
  466. set_row(range, height, &obj->ptr, zval_get_format(format_handle));
  467. }
  468. if (argc == 2) {
  469. set_row(range, height, &obj->ptr, NULL);
  470. }
  471. }
  472. /* }}} */
  473. /** {{{ xls_methods
  474. */
  475. zend_function_entry xls_methods[] = {
  476. PHP_ME(vtiful_xls, __construct, xls_construct_arginfo, ZEND_ACC_PUBLIC)
  477. PHP_ME(vtiful_xls, fileName, xls_file_name_arginfo, ZEND_ACC_PUBLIC)
  478. PHP_ME(vtiful_xls, addSheet, xls_file_add_sheet, ZEND_ACC_PUBLIC)
  479. PHP_ME(vtiful_xls, checkoutSheet, xls_file_checkout_sheet, ZEND_ACC_PUBLIC)
  480. PHP_ME(vtiful_xls, constMemory, xls_const_memory_arginfo, ZEND_ACC_PUBLIC)
  481. PHP_ME(vtiful_xls, header, xls_header_arginfo, ZEND_ACC_PUBLIC)
  482. PHP_ME(vtiful_xls, data, xls_data_arginfo, ZEND_ACC_PUBLIC)
  483. PHP_ME(vtiful_xls, output, NULL, ZEND_ACC_PUBLIC)
  484. PHP_ME(vtiful_xls, getHandle, NULL, ZEND_ACC_PUBLIC)
  485. PHP_ME(vtiful_xls, autoFilter, xls_auto_filter_arginfo, ZEND_ACC_PUBLIC)
  486. PHP_ME(vtiful_xls, insertText, xls_insert_text_arginfo, ZEND_ACC_PUBLIC)
  487. PHP_ME(vtiful_xls, insertChart, xls_insert_chart_arginfo, ZEND_ACC_PUBLIC)
  488. PHP_ME(vtiful_xls, insertUrl, xls_insert_url_arginfo, ZEND_ACC_PUBLIC)
  489. PHP_ME(vtiful_xls, insertImage, xls_insert_image_arginfo, ZEND_ACC_PUBLIC)
  490. PHP_ME(vtiful_xls, insertFormula, xls_insert_formula_arginfo, ZEND_ACC_PUBLIC)
  491. PHP_ME(vtiful_xls, mergeCells, xls_merge_cells_arginfo, ZEND_ACC_PUBLIC)
  492. PHP_ME(vtiful_xls, setColumn, xls_set_column_arginfo, ZEND_ACC_PUBLIC)
  493. PHP_ME(vtiful_xls, setRow, xls_set_row_arginfo, ZEND_ACC_PUBLIC)
  494. PHP_FE_END
  495. };
  496. /* }}} */
  497. /** {{{ VTIFUL_STARTUP_FUNCTION
  498. */
  499. VTIFUL_STARTUP_FUNCTION(excel) {
  500. zend_class_entry ce;
  501. INIT_NS_CLASS_ENTRY(ce, "Vtiful\\Kernel", "Excel", xls_methods);
  502. ce.create_object = vtiful_xls_objects_new;
  503. vtiful_xls_ce = zend_register_internal_class(&ce);
  504. memcpy(&vtiful_xls_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  505. vtiful_xls_handlers.offset = XtOffsetOf(xls_object, zo);
  506. vtiful_xls_handlers.free_obj = vtiful_xls_objects_free;
  507. REGISTER_CLASS_PROPERTY_NULL(vtiful_xls_ce, V_XLS_COF, ZEND_ACC_PRIVATE);
  508. REGISTER_CLASS_PROPERTY_NULL(vtiful_xls_ce, V_XLS_FIL, ZEND_ACC_PRIVATE);
  509. return SUCCESS;
  510. }
  511. /* }}} */