write.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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. /*
  14. * According to the zval type written to the file
  15. */
  16. void type_writer(zval *value, zend_long row, zend_long columns, xls_resource_write_t *res, zend_string *format, lxw_format *format_handle)
  17. {
  18. lxw_format *value_format = NULL;
  19. lxw_col_t lxw_col = (lxw_col_t)columns;
  20. lxw_row_t lxw_row = (lxw_row_t)row;
  21. zend_uchar value_type = Z_TYPE_P(value);
  22. if (value_type == IS_STRING) {
  23. zend_string *_zs_value = zval_get_string(value);
  24. int error = worksheet_write_string(res->worksheet, lxw_row, lxw_col, ZSTR_VAL(_zs_value), format_handle);
  25. zend_string_release(_zs_value);
  26. WORKSHEET_WRITER_EXCEPTION(error);
  27. return;
  28. }
  29. if (value_type == IS_LONG) {
  30. if (format != NULL && format_handle == NULL) {
  31. value_format = workbook_add_format(res->workbook);
  32. format_set_num_format(value_format, ZSTR_VAL(format));
  33. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, (double)zval_get_long(value), value_format));
  34. return;
  35. }
  36. if (format == NULL && format_handle != NULL) {
  37. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, (double)zval_get_long(value), format_handle));
  38. return;
  39. }
  40. if(format != NULL && format_handle != NULL) {
  41. value_format = workbook_add_format(res->workbook);
  42. format_copy(value_format, format_handle);
  43. format_set_num_format(value_format, ZSTR_VAL(format));
  44. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, (double)zval_get_long(value), value_format));
  45. return;
  46. }
  47. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, (double)zval_get_long(value), NULL));
  48. }
  49. if (value_type == IS_DOUBLE) {
  50. if (format != NULL && format_handle == NULL) {
  51. value_format = workbook_add_format(res->workbook);
  52. format_set_num_format(value_format, ZSTR_VAL(format));
  53. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_double(value), value_format));
  54. return;
  55. }
  56. if (format == NULL && format_handle != NULL) {
  57. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_double(value), format_handle));
  58. return;
  59. }
  60. if(format != NULL && format_handle != NULL) {
  61. value_format = workbook_add_format(res->workbook);
  62. format_copy(value_format, format_handle);
  63. format_set_num_format(value_format, ZSTR_VAL(format));
  64. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_double(value), value_format));
  65. return;
  66. }
  67. WORKSHEET_WRITER_EXCEPTION(worksheet_write_number(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, zval_get_double(value), NULL));
  68. return;
  69. }
  70. }
  71. /*
  72. * Write the rich string to the file
  73. */
  74. void rich_string_writer(zend_long row, zend_long columns, xls_resource_write_t *res, zval *rich_strings, lxw_format *format)
  75. {
  76. int index = 0, resource_count = 0;
  77. zval *zv_rich_string = NULL;
  78. lxw_col_t lxw_col = (lxw_col_t)columns;
  79. lxw_row_t lxw_row = (lxw_row_t)row;
  80. if (Z_TYPE_P(rich_strings) != IS_ARRAY) {
  81. return;
  82. }
  83. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(rich_strings), zv_rich_string)
  84. if (Z_TYPE_P(zv_rich_string) != IS_OBJECT) {
  85. continue;
  86. }
  87. if (!instanceof_function(Z_OBJCE_P(zv_rich_string), vtiful_rich_string_ce)) {
  88. zend_throw_exception(vtiful_exception_ce, "The parameter must be an instance of Vtiful\\Kernel\\RichString.", 500);
  89. return;
  90. }
  91. resource_count++;
  92. ZEND_HASH_FOREACH_END();
  93. lxw_rich_string_tuple **rich_string_list = (lxw_rich_string_tuple **)ecalloc(resource_count + 1,sizeof(lxw_rich_string_tuple *));
  94. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(rich_strings), zv_rich_string)
  95. rich_string_object *obj = Z_RICH_STR_P(zv_rich_string);
  96. rich_string_list[index] = obj->ptr.tuple;
  97. index++;
  98. ZEND_HASH_FOREACH_END();
  99. rich_string_list[index] = NULL;
  100. WORKSHEET_WRITER_EXCEPTION(worksheet_write_rich_string(res->worksheet, lxw_row, lxw_col, rich_string_list, format));
  101. efree(rich_string_list);
  102. }
  103. void format_copy(lxw_format *new_format, lxw_format *other_format)
  104. {
  105. new_format->bold = other_format->bold;
  106. new_format->bg_color = other_format->bg_color;
  107. new_format->border_count = other_format->border_count;
  108. new_format->border_index = other_format->border_index;
  109. new_format->bottom = other_format->bottom;
  110. new_format->bottom_color = other_format->bottom_color;
  111. new_format->color_indexed = other_format->color_indexed;
  112. new_format->diag_border = other_format->diag_border;
  113. new_format->diag_color = other_format->diag_color;
  114. new_format->font_size = other_format->font_size;
  115. new_format->bold = other_format->bold;
  116. new_format->italic = other_format->italic;
  117. new_format->font_color = other_format->font_color;
  118. new_format->underline = other_format->underline;
  119. new_format->font_strikeout = other_format->font_strikeout;
  120. new_format->font_outline = other_format->font_outline;
  121. new_format->font_shadow = other_format->font_shadow;
  122. new_format->font_script = other_format->font_script;
  123. new_format->font_family = other_format->font_family;
  124. new_format->font_charset = other_format->font_charset;
  125. new_format->font_condense = other_format->font_condense;
  126. new_format->font_extend = other_format->font_extend;
  127. new_format->theme = other_format->theme;
  128. new_format->hyperlink = other_format->hyperlink;
  129. new_format->hidden = other_format->hidden;
  130. new_format->locked = other_format->locked;
  131. new_format->text_h_align = other_format->text_h_align;
  132. new_format->text_wrap = other_format->text_wrap;
  133. new_format->text_v_align = other_format->text_v_align;
  134. new_format->text_justlast = other_format->text_justlast;
  135. new_format->rotation = other_format->rotation;
  136. new_format->fg_color = other_format->fg_color;
  137. new_format->bg_color = other_format->bg_color;
  138. new_format->pattern = other_format->pattern;
  139. new_format->has_fill = other_format->has_fill;
  140. new_format->has_dxf_fill = other_format->has_dxf_fill;
  141. new_format->fill_index = other_format->fill_index;
  142. new_format->fill_count = other_format->fill_count;
  143. new_format->border_index = other_format->border_index;
  144. new_format->has_border = other_format->has_border;
  145. new_format->has_dxf_border = other_format->has_dxf_border;
  146. new_format->border_count = other_format->border_count;
  147. new_format->bottom = other_format->bottom;
  148. new_format->diag_border = other_format->diag_border;
  149. new_format->diag_type = other_format->diag_type;
  150. new_format->left = other_format->left;
  151. new_format->right = other_format->right;
  152. new_format->top = other_format->top;
  153. new_format->bottom_color = other_format->bottom_color;
  154. new_format->diag_color = other_format->diag_color;
  155. new_format->left_color = other_format->left_color;
  156. new_format->right_color = other_format->right_color;
  157. new_format->top_color = other_format->top_color;
  158. new_format->indent = other_format->indent;
  159. new_format->shrink = other_format->shrink;
  160. new_format->merge_range = other_format->merge_range;
  161. new_format->reading_order = other_format->reading_order;
  162. new_format->just_distrib = other_format->just_distrib;
  163. new_format->color_indexed = other_format->color_indexed;
  164. new_format->font_only = other_format->font_only;
  165. }
  166. void url_writer(zend_long row, zend_long columns, xls_resource_write_t *res, zend_string *url, zend_string *text, zend_string *tool_tip, lxw_format *format)
  167. {
  168. if (text == NULL && tool_tip == NULL) {
  169. worksheet_write_url_opt(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(url), format, NULL, NULL);
  170. return;
  171. }
  172. if (text == NULL && tool_tip != NULL) {
  173. worksheet_write_url_opt(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(url), format, NULL, ZSTR_VAL(tool_tip));
  174. return;
  175. }
  176. if (text != NULL && tool_tip == NULL) {
  177. worksheet_write_url_opt(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(url), format, ZSTR_VAL(text), NULL);
  178. return;
  179. }
  180. worksheet_write_url_opt(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(url), format, ZSTR_VAL(text), ZSTR_VAL(tool_tip));
  181. }
  182. /*
  183. * Write the image to the file
  184. */
  185. void image_writer(zval *value, zend_long row, zend_long columns, double width, double height, xls_resource_write_t *res)
  186. {
  187. lxw_image_options options = {.x_scale = width, .y_scale = height};
  188. worksheet_insert_image_opt(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(zval_get_string(value)), &options);
  189. }
  190. /*
  191. * Write the image to the file
  192. */
  193. void formula_writer(zend_string *value, zend_long row, zend_long columns, xls_resource_write_t *res, lxw_format *format)
  194. {
  195. worksheet_write_formula(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(value), format);
  196. }
  197. /*
  198. * Write the chart to the file
  199. */
  200. void chart_writer(zend_long row, zend_long columns, xls_resource_chart_t *chart_resource, xls_resource_write_t *res)
  201. {
  202. worksheet_insert_chart(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, chart_resource->chart);
  203. }
  204. /*
  205. * Write the datetime to the file
  206. */
  207. void datetime_writer(lxw_datetime *datetime, zend_long row, zend_long columns, zend_string *format, xls_resource_write_t *res, lxw_format *format_handle)
  208. {
  209. lxw_format *value_format = workbook_add_format(res->workbook);
  210. if (format_handle != NULL) {
  211. format_copy(value_format, format_handle);
  212. }
  213. format_set_num_format(value_format, ZSTR_VAL(format));
  214. worksheet_write_datetime(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, datetime, value_format);
  215. }
  216. /*
  217. * Write the comment to the cell
  218. */
  219. void comment_writer(zend_string *comment, zend_long row, zend_long columns, xls_resource_write_t *res)
  220. {
  221. int error = worksheet_write_comment(res->worksheet, (lxw_row_t)row, (lxw_col_t)columns, ZSTR_VAL(comment));
  222. WORKSHEET_WRITER_EXCEPTION(error);
  223. }
  224. /*
  225. * Show all comments
  226. */
  227. void comment_show(xls_resource_write_t *res)
  228. {
  229. worksheet_show_comments(res->worksheet);
  230. }
  231. /*
  232. * Add the autofilter.
  233. */
  234. void auto_filter(zend_string *range, xls_resource_write_t *res)
  235. {
  236. int error = worksheet_autofilter(res->worksheet, RANGE(ZSTR_VAL(range)));
  237. // Cells that have been placed cannot be modified using optimization mode
  238. WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(res, error)
  239. // Worksheet row or column index out of range
  240. WORKSHEET_INDEX_OUT_OF_CHANGE_EXCEPTION(error)
  241. }
  242. /*
  243. * Merge cells.
  244. */
  245. void merge_cells(zend_string *range, zval *value, xls_resource_write_t *res, lxw_format *format)
  246. {
  247. char *_range = ZSTR_VAL(range);
  248. int error = worksheet_merge_range(res->worksheet, RANGE(_range), "", format);
  249. // Cells that have been placed cannot be modified using optimization mode
  250. WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(res, error)
  251. // Worksheet row or column index out of range
  252. WORKSHEET_INDEX_OUT_OF_CHANGE_EXCEPTION(error)
  253. // writer merge cell
  254. type_writer(value, lxw_name_to_row(_range), lxw_name_to_col(_range), res, NULL, format);
  255. }
  256. /*
  257. * Set column format
  258. */
  259. void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format)
  260. {
  261. int error = worksheet_set_column(res->worksheet, COLS(ZSTR_VAL(range)), width, format);
  262. // Cells that have been placed cannot be modified using optimization mode
  263. WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(res, error)
  264. // Worksheet row or column index out of range
  265. WORKSHEET_INDEX_OUT_OF_CHANGE_EXCEPTION(error)
  266. }
  267. /*
  268. * Set row format
  269. */
  270. void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format)
  271. {
  272. char *rows = ZSTR_VAL(range);
  273. if (strchr(rows, ':')) {
  274. worksheet_set_rows(ROWS(rows), height, res, format);
  275. } else {
  276. int error = worksheet_set_row(res->worksheet, ROW(rows), height, format);
  277. // Cells that have been placed cannot be modified using optimization mode
  278. WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(res, error)
  279. // Worksheet row or column index out of range
  280. WORKSHEET_INDEX_OUT_OF_CHANGE_EXCEPTION(error)
  281. }
  282. }
  283. /*
  284. * Add data validations to a worksheet
  285. */
  286. void validation(xls_resource_write_t *res, zend_string *range, lxw_data_validation *validation)
  287. {
  288. worksheet_data_validation_cell(res->worksheet, CELL(ZSTR_VAL(range)), validation);
  289. }
  290. /*
  291. * Set rows format
  292. */
  293. void worksheet_set_rows(lxw_row_t start, lxw_row_t end, double height, xls_resource_write_t *res, lxw_format *format)
  294. {
  295. while (1) {
  296. worksheet_set_row(res->worksheet, end, height, format);
  297. if (end == start)
  298. break;
  299. end--;
  300. }
  301. }
  302. /*
  303. * Set freeze panes
  304. */
  305. void freeze_panes(xls_resource_write_t *res, zend_long row, zend_long column)
  306. {
  307. worksheet_freeze_panes(res->worksheet, row, column);
  308. }
  309. /*
  310. * Display or hide screen and print gridlines
  311. */
  312. void gridlines(xls_resource_write_t *res, zend_long option)
  313. {
  314. worksheet_gridlines(res->worksheet, option);
  315. }
  316. /*
  317. * Set the worksheet zoom factor
  318. */
  319. void zoom(xls_resource_write_t *res, zend_long zoom)
  320. {
  321. worksheet_set_zoom(res->worksheet, zoom);
  322. }
  323. /*
  324. * Set the worksheet protection
  325. */
  326. void protection(xls_resource_write_t *res, zend_string *password)
  327. {
  328. if (password == NULL) {
  329. worksheet_protect(res->worksheet, NULL, NULL);
  330. } else {
  331. worksheet_protect(res->worksheet, ZSTR_VAL(password), NULL);
  332. }
  333. }
  334. /*
  335. * Set the worksheet printed direction
  336. */
  337. void printed_direction(xls_resource_write_t *res, unsigned int direction)
  338. {
  339. if (direction == XLSWRITER_PRINTED_PORTRAIT) {
  340. worksheet_set_portrait(res->worksheet);
  341. }
  342. worksheet_set_landscape(res->worksheet);
  343. }
  344. /*
  345. * Set the worksheet printed scale
  346. */
  347. void printed_scale(xls_resource_write_t *res, zend_long scale)
  348. {
  349. if (scale < 10) {
  350. scale = 10;
  351. }
  352. if (scale > 400) {
  353. scale = 400;
  354. }
  355. worksheet_set_print_scale(res->worksheet, scale);
  356. }
  357. /*
  358. * Hide worksheet
  359. */
  360. void hide_worksheet(xls_resource_write_t *res)
  361. {
  362. worksheet_hide(res->worksheet);
  363. }
  364. /*
  365. * First worksheet
  366. */
  367. void first_worksheet(xls_resource_write_t *res)
  368. {
  369. worksheet_set_first_sheet(res->worksheet);
  370. }
  371. /*
  372. * Paper format
  373. */
  374. void paper(xls_resource_write_t *res, zend_long type)
  375. {
  376. worksheet_set_paper(res->worksheet, type);
  377. }
  378. /*
  379. * Set margins
  380. */
  381. void margins(xls_resource_write_t *res, double left, double right, double top, double bottom)
  382. {
  383. worksheet_set_margins(res->worksheet, left, right, top, bottom);
  384. }
  385. /*
  386. * Call finalization code and close file.
  387. */
  388. lxw_error
  389. workbook_file(xls_resource_write_t *self)
  390. {
  391. lxw_sheet *sheet = NULL;
  392. lxw_worksheet *worksheet = NULL;
  393. lxw_packager *packager = NULL;
  394. lxw_error error = LXW_NO_ERROR;
  395. char codename[LXW_MAX_SHEETNAME_LENGTH] = { 0 };
  396. /* Add a default worksheet if non have been added. */
  397. if (!self->workbook->num_sheets)
  398. workbook_add_worksheet(self->workbook, NULL);
  399. /* Ensure that at least one worksheet has been selected. */
  400. if (self->workbook->active_sheet == 0) {
  401. sheet = STAILQ_FIRST(self->workbook->sheets);
  402. if (!sheet->is_chartsheet) {
  403. worksheet = sheet->u.worksheet;
  404. worksheet->selected = 1;
  405. worksheet->hidden = 0;
  406. }
  407. }
  408. /* Set the active sheet and check if a metadata file is needed. */
  409. STAILQ_FOREACH(sheet, self->workbook->sheets, list_pointers) {
  410. if (sheet->is_chartsheet)
  411. continue;
  412. else
  413. worksheet = sheet->u.worksheet;
  414. if (worksheet->index == self->workbook->active_sheet)
  415. worksheet->active = 1;
  416. if (worksheet->has_dynamic_arrays)
  417. self->workbook->has_metadata = LXW_TRUE;
  418. }
  419. /* Set workbook and worksheet VBA codenames if a macro has been added. */
  420. if (self->workbook->vba_project) {
  421. if (!self->workbook->vba_codename)
  422. workbook_set_vba_name(self->workbook, "ThisWorkbook");
  423. STAILQ_FOREACH(sheet, self->workbook->sheets, list_pointers) {
  424. if (sheet->is_chartsheet)
  425. continue;
  426. else
  427. worksheet = sheet->u.worksheet;
  428. if (!worksheet->vba_codename) {
  429. lxw_snprintf(codename, LXW_MAX_SHEETNAME_LENGTH, "Sheet%d",
  430. worksheet->index + 1);
  431. worksheet_set_vba_name(worksheet, codename);
  432. }
  433. }
  434. }
  435. /* Prepare the worksheet VML elements such as comments. */
  436. _prepare_vml(self->workbook);
  437. /* Set the defined names for the worksheets such as Print Titles. */
  438. _prepare_defined_names(self->workbook);
  439. /* Prepare the drawings, charts and images. */
  440. _prepare_drawings(self->workbook);
  441. /* Add cached data to charts. */
  442. _add_chart_cache_data(self->workbook);
  443. /* Create a packager object to assemble sub-elements into a zip file. */
  444. packager = lxw_packager_new(self->workbook->filename,
  445. self->workbook->options.tmpdir,
  446. self->workbook->options.use_zip64);
  447. /* If the packager fails it is generally due to a zip permission error. */
  448. if (packager == NULL) {
  449. fprintf(stderr, "[ERROR] workbook_close(): "
  450. "Error creating '%s'. "
  451. "Error = %s\n", self->workbook->filename, strerror(errno));
  452. error = LXW_ERROR_CREATING_XLSX_FILE;
  453. goto mem_error;
  454. }
  455. /* Set the workbook object in the packager. */
  456. packager->workbook = self->workbook;
  457. /* Assemble all the sub-files in the xlsx package. */
  458. error = lxw_create_package(packager);
  459. /* Error and non-error conditions fall through to the cleanup code. */
  460. if (error == LXW_ERROR_CREATING_TMPFILE) {
  461. fprintf(stderr, "[ERROR] workbook_close(): "
  462. "Error creating tmpfile(s) to assemble '%s'. "
  463. "Error = %s\n", self->workbook->filename, strerror(errno));
  464. }
  465. /* If LXW_ERROR_ZIP_FILE_OPERATION then errno is set by zlib. */
  466. if (error == LXW_ERROR_ZIP_FILE_OPERATION) {
  467. fprintf(stderr, "[ERROR] workbook_close(): "
  468. "Zlib error while creating xlsx file '%s'. "
  469. "Error = %s\n", self->workbook->filename, strerror(errno));
  470. }
  471. /* If LXW_ERROR_ZIP_PARAMETER_ERROR then errno is set by zip. */
  472. if (error == LXW_ERROR_ZIP_PARAMETER_ERROR) {
  473. fprintf(stderr, "[ERROR] workbook_close(): "
  474. "Zip ZIP_PARAMERROR error while creating xlsx file '%s'. "
  475. "System error = %s\n", self->workbook->filename, strerror(errno));
  476. }
  477. /* If LXW_ERROR_ZIP_BAD_ZIP_FILE then errno is set by zip. */
  478. if (error == LXW_ERROR_ZIP_BAD_ZIP_FILE) {
  479. fprintf(stderr, "[ERROR] workbook_close(): "
  480. "Zip ZIP_BADZIPFILE error while creating xlsx file '%s'. "
  481. "This may require the use_zip64 option for large files. "
  482. "System error = %s\n", self->workbook->filename, strerror(errno));
  483. }
  484. /* If LXW_ERROR_ZIP_INTERNAL_ERROR then errno is set by zip. */
  485. if (error == LXW_ERROR_ZIP_INTERNAL_ERROR) {
  486. fprintf(stderr, "[ERROR] workbook_close(): "
  487. "Zip ZIP_INTERNALERROR error while creating xlsx file '%s'. "
  488. "System error = %s\n", self->workbook->filename, strerror(errno));
  489. }
  490. /* The next 2 error conditions don't set errno. */
  491. if (error == LXW_ERROR_ZIP_FILE_ADD) {
  492. fprintf(stderr, "[ERROR] workbook_close(): "
  493. "Zlib error adding file to xlsx file '%s'.\n",
  494. self->workbook->filename);
  495. }
  496. if (error == LXW_ERROR_ZIP_CLOSE) {
  497. fprintf(stderr, "[ERROR] workbook_close(): "
  498. "Zlib error closing xlsx file '%s'.\n", self->workbook->filename);
  499. }
  500. mem_error:
  501. lxw_packager_free(packager);
  502. return error;
  503. }
  504. void _php_vtiful_xls_close(zend_resource *rsrc TSRMLS_DC)
  505. {
  506. }
  507. /*
  508. * Iterate through the worksheets and set up the VML objects.
  509. */
  510. STATIC void
  511. _prepare_vml(lxw_workbook *self)
  512. {
  513. lxw_worksheet *worksheet;
  514. lxw_sheet *sheet;
  515. uint32_t comment_id = 0;
  516. uint32_t vml_drawing_id = 0;
  517. uint32_t vml_data_id = 1;
  518. uint32_t vml_shape_id = 1024;
  519. uint32_t comment_count = 0;
  520. STAILQ_FOREACH(sheet, self->sheets, list_pointers) {
  521. if (sheet->is_chartsheet)
  522. continue;
  523. else
  524. worksheet = sheet->u.worksheet;
  525. if (!worksheet->has_vml && !worksheet->has_header_vml)
  526. continue;
  527. if (worksheet->has_vml) {
  528. self->has_vml = LXW_TRUE;
  529. if (worksheet->has_comments) {
  530. self->comment_count += 1;
  531. comment_id += 1;
  532. self->has_comments = LXW_TRUE;
  533. }
  534. vml_drawing_id += 1;
  535. comment_count = lxw_worksheet_prepare_vml_objects(worksheet,
  536. vml_data_id,
  537. vml_shape_id,
  538. vml_drawing_id,
  539. comment_id);
  540. /* Each VML should start with a shape id incremented by 1024. */
  541. vml_data_id += 1 * ((1024 + comment_count) / 1024);
  542. vml_shape_id += 1024 * ((1024 + comment_count) / 1024);
  543. }
  544. }
  545. }
  546. /*
  547. * Iterate through the worksheets and store any defined names used for print
  548. * ranges or repeat rows/columns.
  549. */
  550. STATIC void
  551. _prepare_defined_names(lxw_workbook *self)
  552. {
  553. lxw_worksheet *worksheet;
  554. char app_name[LXW_DEFINED_NAME_LENGTH];
  555. char range[LXW_DEFINED_NAME_LENGTH];
  556. char area[LXW_MAX_CELL_RANGE_LENGTH];
  557. char first_col[8];
  558. char last_col[8];
  559. STAILQ_FOREACH(worksheet, self->worksheets, list_pointers) {
  560. /*
  561. * Check for autofilter settings and store them.
  562. */
  563. if (worksheet->autofilter.in_use) {
  564. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  565. "%s!_FilterDatabase", worksheet->quoted_name);
  566. lxw_rowcol_to_range_abs(area,
  567. worksheet->autofilter.first_row,
  568. worksheet->autofilter.first_col,
  569. worksheet->autofilter.last_row,
  570. worksheet->autofilter.last_col);
  571. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH, "%s!%s",
  572. worksheet->quoted_name, area);
  573. /* Autofilters are the only defined name to set the hidden flag. */
  574. _store_defined_name(self, "_xlnm._FilterDatabase", app_name, range, worksheet->index, LXW_TRUE);
  575. }
  576. /*
  577. * Check for Print Area settings and store them.
  578. */
  579. if (worksheet->print_area.in_use) {
  580. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  581. "%s!Print_Area", worksheet->quoted_name);
  582. /* Check for print area that is the max row range. */
  583. if (worksheet->print_area.first_row == 0
  584. && worksheet->print_area.last_row == LXW_ROW_MAX - 1) {
  585. lxw_col_to_name(first_col,
  586. worksheet->print_area.first_col, LXW_FALSE);
  587. lxw_col_to_name(last_col,
  588. worksheet->print_area.last_col, LXW_FALSE);
  589. lxw_snprintf(area, LXW_MAX_CELL_RANGE_LENGTH - 1, "$%s:$%s",
  590. first_col, last_col);
  591. }
  592. /* Check for print area that is the max column range. */
  593. else if (worksheet->print_area.first_col == 0
  594. && worksheet->print_area.last_col == LXW_COL_MAX - 1) {
  595. lxw_snprintf(area, LXW_MAX_CELL_RANGE_LENGTH - 1, "$%d:$%d",
  596. worksheet->print_area.first_row + 1,
  597. worksheet->print_area.last_row + 1);
  598. }
  599. else {
  600. lxw_rowcol_to_range_abs(area,
  601. worksheet->print_area.first_row,
  602. worksheet->print_area.first_col,
  603. worksheet->print_area.last_row,
  604. worksheet->print_area.last_col);
  605. }
  606. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH, "%s!%s",
  607. worksheet->quoted_name, area);
  608. _store_defined_name(self, "_xlnm.Print_Area", app_name,
  609. range, worksheet->index, LXW_FALSE);
  610. }
  611. /*
  612. * Check for repeat rows/cols. aka, Print Titles and store them.
  613. */
  614. if (worksheet->repeat_rows.in_use || worksheet->repeat_cols.in_use) {
  615. if (worksheet->repeat_rows.in_use
  616. && worksheet->repeat_cols.in_use) {
  617. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  618. "%s!Print_Titles", worksheet->quoted_name);
  619. lxw_col_to_name(first_col,
  620. worksheet->repeat_cols.first_col, LXW_FALSE);
  621. lxw_col_to_name(last_col,
  622. worksheet->repeat_cols.last_col, LXW_FALSE);
  623. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH,
  624. "%s!$%s:$%s,%s!$%d:$%d",
  625. worksheet->quoted_name, first_col,
  626. last_col, worksheet->quoted_name,
  627. worksheet->repeat_rows.first_row + 1,
  628. worksheet->repeat_rows.last_row + 1);
  629. _store_defined_name(self, "_xlnm.Print_Titles", app_name,
  630. range, worksheet->index, LXW_FALSE);
  631. }
  632. else if (worksheet->repeat_rows.in_use) {
  633. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  634. "%s!Print_Titles", worksheet->quoted_name);
  635. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH,
  636. "%s!$%d:$%d", worksheet->quoted_name,
  637. worksheet->repeat_rows.first_row + 1,
  638. worksheet->repeat_rows.last_row + 1);
  639. _store_defined_name(self, "_xlnm.Print_Titles", app_name,
  640. range, worksheet->index, LXW_FALSE);
  641. }
  642. else if (worksheet->repeat_cols.in_use) {
  643. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  644. "%s!Print_Titles", worksheet->quoted_name);
  645. lxw_col_to_name(first_col,
  646. worksheet->repeat_cols.first_col, LXW_FALSE);
  647. lxw_col_to_name(last_col,
  648. worksheet->repeat_cols.last_col, LXW_FALSE);
  649. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH,
  650. "%s!$%s:$%s", worksheet->quoted_name,
  651. first_col, last_col);
  652. _store_defined_name(self, "_xlnm.Print_Titles", app_name,
  653. range, worksheet->index, LXW_FALSE);
  654. }
  655. }
  656. }
  657. }
  658. /*
  659. * Iterate through the worksheets and set up any chart or image drawings.
  660. */
  661. STATIC void
  662. _prepare_drawings(lxw_workbook *self)
  663. {
  664. lxw_worksheet *worksheet;
  665. lxw_object_properties *image_options;
  666. uint16_t chart_ref_id = 0;
  667. uint16_t image_ref_id = 0;
  668. uint16_t drawing_id = 0;
  669. STAILQ_FOREACH(worksheet, self->worksheets, list_pointers) {
  670. if (STAILQ_EMPTY(worksheet->image_props)
  671. && STAILQ_EMPTY(worksheet->chart_data))
  672. continue;
  673. drawing_id++;
  674. STAILQ_FOREACH(image_options, worksheet->chart_data, list_pointers) {
  675. chart_ref_id++;
  676. lxw_worksheet_prepare_chart(worksheet, chart_ref_id, drawing_id,
  677. image_options, 0);
  678. if (image_options->chart)
  679. STAILQ_INSERT_TAIL(self->ordered_charts, image_options->chart,
  680. ordered_list_pointers);
  681. }
  682. STAILQ_FOREACH(image_options, worksheet->image_props, list_pointers) {
  683. if (image_options->image_type == LXW_IMAGE_PNG)
  684. self->has_png = LXW_TRUE;
  685. if (image_options->image_type == LXW_IMAGE_JPEG)
  686. self->has_jpeg = LXW_TRUE;
  687. if (image_options->image_type == LXW_IMAGE_BMP)
  688. self->has_bmp = LXW_TRUE;
  689. image_ref_id++;
  690. lxw_worksheet_prepare_image(worksheet, image_ref_id, drawing_id,
  691. image_options);
  692. }
  693. }
  694. self->drawing_count = drawing_id;
  695. }
  696. /*
  697. * Add "cached" data to charts to provide the numCache and strCache data for
  698. * series and title/axis ranges.
  699. */
  700. STATIC void
  701. _add_chart_cache_data(lxw_workbook *self)
  702. {
  703. lxw_chart *chart;
  704. lxw_chart_series *series;
  705. STAILQ_FOREACH(chart, self->ordered_charts, ordered_list_pointers) {
  706. _populate_range(self, chart->title.range);
  707. _populate_range(self, chart->x_axis->title.range);
  708. _populate_range(self, chart->y_axis->title.range);
  709. if (STAILQ_EMPTY(chart->series_list))
  710. continue;
  711. STAILQ_FOREACH(series, chart->series_list, list_pointers) {
  712. _populate_range(self, series->categories);
  713. _populate_range(self, series->values);
  714. _populate_range(self, series->title.range);
  715. }
  716. }
  717. }
  718. /*
  719. * Process and store the defined names. The defined names are stored with
  720. * the Workbook.xml but also with the App.xml if they refer to a sheet
  721. * range like "Sheet1!:A1". The defined names are store in sorted
  722. * order for consistency with Excel. The names need to be normalized before
  723. * sorting.
  724. */
  725. STATIC lxw_error
  726. _store_defined_name(lxw_workbook *self, const char *name, const char *app_name, const char *formula, int16_t index, uint8_t hidden)
  727. {
  728. lxw_worksheet *worksheet;
  729. lxw_defined_name *defined_name;
  730. lxw_defined_name *list_defined_name;
  731. char name_copy[LXW_DEFINED_NAME_LENGTH];
  732. char *tmp_str;
  733. char *worksheet_name;
  734. /* Do some checks on the input data */
  735. if (!name || !formula)
  736. return LXW_ERROR_NULL_PARAMETER_IGNORED;
  737. if (lxw_utf8_strlen(name) > LXW_DEFINED_NAME_LENGTH ||
  738. lxw_utf8_strlen(formula) > LXW_DEFINED_NAME_LENGTH) {
  739. return LXW_ERROR_128_STRING_LENGTH_EXCEEDED;
  740. }
  741. /* Allocate a new defined_name to be added to the linked list of names. */
  742. defined_name = calloc(1, sizeof(struct lxw_defined_name));
  743. RETURN_ON_MEM_ERROR(defined_name, LXW_ERROR_MEMORY_MALLOC_FAILED);
  744. /* Copy the user input string. */
  745. lxw_strcpy(name_copy, name);
  746. /* Set the worksheet index or -1 for a global defined name. */
  747. defined_name->index = index;
  748. defined_name->hidden = hidden;
  749. /* Check for local defined names like like "Sheet1!name". */
  750. tmp_str = strchr(name_copy, '!');
  751. if (tmp_str == NULL) {
  752. /* The name is global. We just store the defined name string. */
  753. lxw_strcpy(defined_name->name, name_copy);
  754. }
  755. else {
  756. /* The name is worksheet local. We need to extract the sheet name
  757. * and map it to a sheet index. */
  758. /* Split the into the worksheet name and defined name. */
  759. *tmp_str = '\0';
  760. tmp_str++;
  761. worksheet_name = name_copy;
  762. /* Remove any worksheet quoting. */
  763. if (worksheet_name[0] == '\'')
  764. worksheet_name++;
  765. if (worksheet_name[strlen(worksheet_name) - 1] == '\'')
  766. worksheet_name[strlen(worksheet_name) - 1] = '\0';
  767. /* Search for worksheet name to get the equivalent worksheet index. */
  768. STAILQ_FOREACH(worksheet, self->worksheets, list_pointers) {
  769. if (strcmp(worksheet_name, worksheet->name) == 0) {
  770. defined_name->index = worksheet->index;
  771. lxw_strcpy(defined_name->normalised_sheetname,
  772. worksheet_name);
  773. }
  774. }
  775. /* If we didn't find the worksheet name we exit. */
  776. if (defined_name->index == -1)
  777. goto mem_error;
  778. lxw_strcpy(defined_name->name, tmp_str);
  779. }
  780. /* Print titles and repeat title pass in the name used for App.xml. */
  781. if (app_name) {
  782. lxw_strcpy(defined_name->app_name, app_name);
  783. lxw_strcpy(defined_name->normalised_sheetname, app_name);
  784. }
  785. else {
  786. lxw_strcpy(defined_name->app_name, name);
  787. }
  788. /* We need to normalize the defined names for sorting. This involves
  789. * removing any _xlnm namespace and converting it to lowercase. */
  790. tmp_str = strstr(name_copy, "_xlnm.");
  791. if (tmp_str)
  792. lxw_strcpy(defined_name->normalised_name, defined_name->name + 6);
  793. else
  794. lxw_strcpy(defined_name->normalised_name, defined_name->name);
  795. lxw_str_tolower(defined_name->normalised_name);
  796. lxw_str_tolower(defined_name->normalised_sheetname);
  797. /* Strip leading "=" from the formula. */
  798. if (formula[0] == '=')
  799. lxw_strcpy(defined_name->formula, formula + 1);
  800. else
  801. lxw_strcpy(defined_name->formula, formula);
  802. /* We add the defined name to the list in sorted order. */
  803. list_defined_name = TAILQ_FIRST(self->defined_names);
  804. if (list_defined_name == NULL ||
  805. _compare_defined_names(defined_name, list_defined_name) < 1) {
  806. /* List is empty or defined name goes to the head. */
  807. TAILQ_INSERT_HEAD(self->defined_names, defined_name, list_pointers);
  808. return LXW_NO_ERROR;
  809. }
  810. TAILQ_FOREACH(list_defined_name, self->defined_names, list_pointers) {
  811. int res = _compare_defined_names(defined_name, list_defined_name);
  812. /* The entry already exists. We exit and don't overwrite. */
  813. if (res == 0)
  814. goto mem_error;
  815. /* New defined name is inserted in sorted order before other entries. */
  816. if (res < 0) {
  817. TAILQ_INSERT_BEFORE(list_defined_name, defined_name,
  818. list_pointers);
  819. return LXW_NO_ERROR;
  820. }
  821. }
  822. /* If the entry wasn't less than any of the entries in the list we add it
  823. * to the end. */
  824. TAILQ_INSERT_TAIL(self->defined_names, defined_name, list_pointers);
  825. return LXW_NO_ERROR;
  826. mem_error:
  827. free(defined_name);
  828. return LXW_ERROR_MEMORY_MALLOC_FAILED;
  829. }
  830. /*
  831. * Compare two defined_name structures.
  832. */
  833. static int
  834. _compare_defined_names(lxw_defined_name *a, lxw_defined_name *b)
  835. {
  836. int res = strcmp(a->normalised_name, b->normalised_name);
  837. /* Primary comparison based on defined name. */
  838. if (res)
  839. return res;
  840. /* Secondary comparison based on worksheet name. */
  841. res = strcmp(a->normalised_sheetname, b->normalised_sheetname);
  842. return res;
  843. }
  844. /* Convert a chart range such as Sheet1!$A$1:$A$5 to a sheet name and row-col
  845. * dimensions, or vice-versa. This gives us the dimensions to read data back
  846. * from the worksheet.
  847. */
  848. STATIC void
  849. _populate_range_dimensions(lxw_workbook *self, lxw_series_range *range)
  850. {
  851. char formula[LXW_MAX_FORMULA_RANGE_LENGTH] = { 0 };
  852. char *tmp_str;
  853. char *sheetname;
  854. /* If neither the range formula or sheetname is defined then this probably
  855. * isn't a valid range.
  856. */
  857. if (!range->formula && !range->sheetname) {
  858. range->ignore_cache = LXW_TRUE;
  859. return;
  860. }
  861. /* If the sheetname is already defined it was already set via
  862. * chart_series_set_categories() or chart_series_set_values().
  863. */
  864. if (range->sheetname)
  865. return;
  866. /* Ignore non-contiguous range like (Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5) */
  867. if (range->formula[0] == '(') {
  868. range->ignore_cache = LXW_TRUE;
  869. return;
  870. }
  871. /* Create a copy of the formula to modify and parse into parts. */
  872. lxw_snprintf(formula, LXW_MAX_FORMULA_RANGE_LENGTH, "%s", range->formula);
  873. /* Check for valid formula. TODO. This needs stronger validation. */
  874. tmp_str = strchr(formula, '!');
  875. if (tmp_str == NULL) {
  876. range->ignore_cache = LXW_TRUE;
  877. return;
  878. }
  879. else {
  880. /* Split the formulas into sheetname and row-col data. */
  881. *tmp_str = '\0';
  882. tmp_str++;
  883. sheetname = formula;
  884. /* Remove any worksheet quoting. */
  885. if (sheetname[0] == '\'')
  886. sheetname++;
  887. if (sheetname[strlen(sheetname) - 1] == '\'')
  888. sheetname[strlen(sheetname) - 1] = '\0';
  889. /* Check that the sheetname exists. */
  890. if (!workbook_get_worksheet_by_name(self, sheetname)) {
  891. LXW_WARN_FORMAT2("workbook_add_chart(): worksheet name '%s' "
  892. "in chart formula '%s' doesn't exist.",
  893. sheetname, range->formula);
  894. range->ignore_cache = LXW_TRUE;
  895. return;
  896. }
  897. range->sheetname = lxw_strdup(sheetname);
  898. range->first_row = lxw_name_to_row(tmp_str);
  899. range->first_col = lxw_name_to_col(tmp_str);
  900. if (strchr(tmp_str, ':')) {
  901. /* 2D range. */
  902. range->last_row = lxw_name_to_row_2(tmp_str);
  903. range->last_col = lxw_name_to_col_2(tmp_str);
  904. }
  905. else {
  906. /* 1D range. */
  907. range->last_row = range->first_row;
  908. range->last_col = range->first_col;
  909. }
  910. }
  911. }
  912. /*
  913. * Populate the data cache of a chart data series by reading the data from the
  914. * relevant worksheet and adding it to the cached in the range object as a
  915. * list of points.
  916. *
  917. * Note, the data cache isn't strictly required by Excel but it helps if the
  918. * chart is embedded in another application such as PowerPoint and it also
  919. * helps with comparison testing.
  920. */
  921. STATIC void
  922. _populate_range_data_cache(lxw_workbook *self, lxw_series_range *range)
  923. {
  924. lxw_worksheet *worksheet;
  925. lxw_row_t row_num;
  926. lxw_col_t col_num;
  927. lxw_row *row_obj;
  928. lxw_cell *cell_obj;
  929. struct lxw_series_data_point *data_point;
  930. uint16_t num_data_points = 0;
  931. /* If ignore_cache is set then don't try to populate the cache. This flag
  932. * may be set manually, for testing, or due to a case where the cache
  933. * can't be calculated.
  934. */
  935. if (range->ignore_cache)
  936. return;
  937. /* Currently we only handle 2D ranges so ensure either the rows or cols
  938. * are the same.
  939. */
  940. if (range->first_row != range->last_row
  941. && range->first_col != range->last_col) {
  942. range->ignore_cache = LXW_TRUE;
  943. return;
  944. }
  945. /* Check that the sheetname exists. */
  946. worksheet = workbook_get_worksheet_by_name(self, range->sheetname);
  947. if (!worksheet) {
  948. LXW_WARN_FORMAT2("workbook_add_chart(): worksheet name '%s' "
  949. "in chart formula '%s' doesn't exist.",
  950. range->sheetname, range->formula);
  951. range->ignore_cache = LXW_TRUE;
  952. return;
  953. }
  954. /* We can't read the data when worksheet optimization is on. */
  955. if (worksheet->optimize) {
  956. range->ignore_cache = LXW_TRUE;
  957. return;
  958. }
  959. /* Iterate through the worksheet data and populate the range cache. */
  960. for (row_num = range->first_row; row_num <= range->last_row; row_num++) {
  961. row_obj = lxw_worksheet_find_row(worksheet, row_num);
  962. for (col_num = range->first_col; col_num <= range->last_col;
  963. col_num++) {
  964. data_point = calloc(1, sizeof(struct lxw_series_data_point));
  965. if (!data_point) {
  966. range->ignore_cache = LXW_TRUE;
  967. return;
  968. }
  969. #if defined(LXW_VERSION_ID) && LXW_VERSION_ID >= 93
  970. cell_obj = lxw_worksheet_find_cell_in_row(row_obj, col_num);
  971. #else
  972. cell_obj = lxw_worksheet_find_cell(row_obj, col_num);
  973. #endif
  974. if (cell_obj) {
  975. if (cell_obj->type == NUMBER_CELL) {
  976. data_point->number = cell_obj->u.number;
  977. }
  978. if (cell_obj->type == STRING_CELL) {
  979. data_point->string = lxw_strdup(cell_obj->sst_string);
  980. data_point->is_string = LXW_TRUE;
  981. range->has_string_cache = LXW_TRUE;
  982. }
  983. }
  984. else {
  985. data_point->no_data = LXW_TRUE;
  986. }
  987. STAILQ_INSERT_TAIL(range->data_cache, data_point, list_pointers);
  988. num_data_points++;
  989. }
  990. }
  991. range->num_data_points = num_data_points;
  992. }
  993. /* Set the range dimensions and set the data cache.
  994. */
  995. STATIC void
  996. _populate_range(lxw_workbook *self, lxw_series_range *range)
  997. {
  998. _populate_range_dimensions(self, range);
  999. _populate_range_data_cache(self, range);
  1000. }