excel.c 18 KB

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