write.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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. char *rangeStr = ZSTR_VAL(range);
  289. if (strchr(rangeStr, ':')) {
  290. worksheet_data_validation_range(res->worksheet, RANGE(rangeStr), validation);
  291. } else {
  292. worksheet_data_validation_cell(res->worksheet, CELL(rangeStr), validation);
  293. }
  294. }
  295. /*
  296. * Set rows format
  297. */
  298. void worksheet_set_rows(lxw_row_t start, lxw_row_t end, double height, xls_resource_write_t *res, lxw_format *format)
  299. {
  300. while (1) {
  301. worksheet_set_row(res->worksheet, end, height, format);
  302. if (end == start)
  303. break;
  304. end--;
  305. }
  306. }
  307. /*
  308. * Set freeze panes
  309. */
  310. void freeze_panes(xls_resource_write_t *res, zend_long row, zend_long column)
  311. {
  312. worksheet_freeze_panes(res->worksheet, row, column);
  313. }
  314. /*
  315. * Display or hide screen and print gridlines
  316. */
  317. void gridlines(xls_resource_write_t *res, zend_long option)
  318. {
  319. worksheet_gridlines(res->worksheet, option);
  320. }
  321. /*
  322. * Set the worksheet zoom factor
  323. */
  324. void zoom(xls_resource_write_t *res, zend_long zoom)
  325. {
  326. worksheet_set_zoom(res->worksheet, zoom);
  327. }
  328. /*
  329. * Set the worksheet protection
  330. */
  331. void protection(xls_resource_write_t *res, zend_string *password)
  332. {
  333. if (password == NULL) {
  334. worksheet_protect(res->worksheet, NULL, NULL);
  335. } else {
  336. worksheet_protect(res->worksheet, ZSTR_VAL(password), NULL);
  337. }
  338. }
  339. /*
  340. * Set the worksheet printed direction
  341. */
  342. void printed_direction(xls_resource_write_t *res, unsigned int direction)
  343. {
  344. if (direction == XLSWRITER_PRINTED_PORTRAIT) {
  345. worksheet_set_portrait(res->worksheet);
  346. }
  347. worksheet_set_landscape(res->worksheet);
  348. }
  349. /*
  350. * Set the worksheet printed scale
  351. */
  352. void printed_scale(xls_resource_write_t *res, zend_long scale)
  353. {
  354. if (scale < 10) {
  355. scale = 10;
  356. }
  357. if (scale > 400) {
  358. scale = 400;
  359. }
  360. worksheet_set_print_scale(res->worksheet, scale);
  361. }
  362. /*
  363. * Hide worksheet
  364. */
  365. void hide_worksheet(xls_resource_write_t *res)
  366. {
  367. worksheet_hide(res->worksheet);
  368. }
  369. /*
  370. * First worksheet
  371. */
  372. void first_worksheet(xls_resource_write_t *res)
  373. {
  374. worksheet_set_first_sheet(res->worksheet);
  375. }
  376. /*
  377. * Paper format
  378. */
  379. void paper(xls_resource_write_t *res, zend_long type)
  380. {
  381. worksheet_set_paper(res->worksheet, type);
  382. }
  383. /*
  384. * Set margins
  385. */
  386. void margins(xls_resource_write_t *res, double left, double right, double top, double bottom)
  387. {
  388. worksheet_set_margins(res->worksheet, left, right, top, bottom);
  389. }
  390. /*
  391. * Call finalization code and close file.
  392. */
  393. lxw_error
  394. workbook_file(xls_resource_write_t *self)
  395. {
  396. lxw_sheet *sheet = NULL;
  397. lxw_worksheet *worksheet = NULL;
  398. lxw_packager *packager = NULL;
  399. lxw_error error = LXW_NO_ERROR;
  400. char codename[LXW_MAX_SHEETNAME_LENGTH] = { 0 };
  401. /* Add a default worksheet if non have been added. */
  402. if (!self->workbook->num_sheets)
  403. workbook_add_worksheet(self->workbook, NULL);
  404. /* Ensure that at least one worksheet has been selected. */
  405. if (self->workbook->active_sheet == 0) {
  406. sheet = STAILQ_FIRST(self->workbook->sheets);
  407. if (!sheet->is_chartsheet) {
  408. worksheet = sheet->u.worksheet;
  409. worksheet->selected = 1;
  410. worksheet->hidden = 0;
  411. }
  412. }
  413. /* Set the active sheet and check if a metadata file is needed. */
  414. STAILQ_FOREACH(sheet, self->workbook->sheets, list_pointers) {
  415. if (sheet->is_chartsheet)
  416. continue;
  417. else
  418. worksheet = sheet->u.worksheet;
  419. if (worksheet->index == self->workbook->active_sheet)
  420. worksheet->active = 1;
  421. if (worksheet->has_dynamic_arrays)
  422. self->workbook->has_metadata = LXW_TRUE;
  423. }
  424. /* Set workbook and worksheet VBA codenames if a macro has been added. */
  425. if (self->workbook->vba_project) {
  426. if (!self->workbook->vba_codename)
  427. workbook_set_vba_name(self->workbook, "ThisWorkbook");
  428. STAILQ_FOREACH(sheet, self->workbook->sheets, list_pointers) {
  429. if (sheet->is_chartsheet)
  430. continue;
  431. else
  432. worksheet = sheet->u.worksheet;
  433. if (!worksheet->vba_codename) {
  434. lxw_snprintf(codename, LXW_MAX_SHEETNAME_LENGTH, "Sheet%d",
  435. worksheet->index + 1);
  436. worksheet_set_vba_name(worksheet, codename);
  437. }
  438. }
  439. }
  440. /* Prepare the worksheet VML elements such as comments. */
  441. _prepare_vml(self->workbook);
  442. /* Set the defined names for the worksheets such as Print Titles. */
  443. _prepare_defined_names(self->workbook);
  444. /* Prepare the drawings, charts and images. */
  445. _prepare_drawings(self->workbook);
  446. /* Add cached data to charts. */
  447. _add_chart_cache_data(self->workbook);
  448. /* Create a packager object to assemble sub-elements into a zip file. */
  449. packager = lxw_packager_new(self->workbook->filename,
  450. self->workbook->options.tmpdir,
  451. self->workbook->options.use_zip64);
  452. /* If the packager fails it is generally due to a zip permission error. */
  453. if (packager == NULL) {
  454. fprintf(stderr, "[ERROR] workbook_close(): "
  455. "Error creating '%s'. "
  456. "Error = %s\n", self->workbook->filename, strerror(errno));
  457. error = LXW_ERROR_CREATING_XLSX_FILE;
  458. goto mem_error;
  459. }
  460. /* Set the workbook object in the packager. */
  461. packager->workbook = self->workbook;
  462. /* Assemble all the sub-files in the xlsx package. */
  463. error = lxw_create_package(packager);
  464. /* Error and non-error conditions fall through to the cleanup code. */
  465. if (error == LXW_ERROR_CREATING_TMPFILE) {
  466. fprintf(stderr, "[ERROR] workbook_close(): "
  467. "Error creating tmpfile(s) to assemble '%s'. "
  468. "Error = %s\n", self->workbook->filename, strerror(errno));
  469. }
  470. /* If LXW_ERROR_ZIP_FILE_OPERATION then errno is set by zlib. */
  471. if (error == LXW_ERROR_ZIP_FILE_OPERATION) {
  472. fprintf(stderr, "[ERROR] workbook_close(): "
  473. "Zlib error while creating xlsx file '%s'. "
  474. "Error = %s\n", self->workbook->filename, strerror(errno));
  475. }
  476. /* If LXW_ERROR_ZIP_PARAMETER_ERROR then errno is set by zip. */
  477. if (error == LXW_ERROR_ZIP_PARAMETER_ERROR) {
  478. fprintf(stderr, "[ERROR] workbook_close(): "
  479. "Zip ZIP_PARAMERROR error while creating xlsx file '%s'. "
  480. "System error = %s\n", self->workbook->filename, strerror(errno));
  481. }
  482. /* If LXW_ERROR_ZIP_BAD_ZIP_FILE then errno is set by zip. */
  483. if (error == LXW_ERROR_ZIP_BAD_ZIP_FILE) {
  484. fprintf(stderr, "[ERROR] workbook_close(): "
  485. "Zip ZIP_BADZIPFILE error while creating xlsx file '%s'. "
  486. "This may require the use_zip64 option for large files. "
  487. "System error = %s\n", self->workbook->filename, strerror(errno));
  488. }
  489. /* If LXW_ERROR_ZIP_INTERNAL_ERROR then errno is set by zip. */
  490. if (error == LXW_ERROR_ZIP_INTERNAL_ERROR) {
  491. fprintf(stderr, "[ERROR] workbook_close(): "
  492. "Zip ZIP_INTERNALERROR error while creating xlsx file '%s'. "
  493. "System error = %s\n", self->workbook->filename, strerror(errno));
  494. }
  495. /* The next 2 error conditions don't set errno. */
  496. if (error == LXW_ERROR_ZIP_FILE_ADD) {
  497. fprintf(stderr, "[ERROR] workbook_close(): "
  498. "Zlib error adding file to xlsx file '%s'.\n",
  499. self->workbook->filename);
  500. }
  501. if (error == LXW_ERROR_ZIP_CLOSE) {
  502. fprintf(stderr, "[ERROR] workbook_close(): "
  503. "Zlib error closing xlsx file '%s'.\n", self->workbook->filename);
  504. }
  505. mem_error:
  506. lxw_packager_free(packager);
  507. return error;
  508. }
  509. void _php_vtiful_xls_close(zend_resource *rsrc TSRMLS_DC)
  510. {
  511. //
  512. }
  513. /*
  514. * Iterate through the worksheets and set up the VML objects.
  515. */
  516. STATIC void
  517. _prepare_vml(lxw_workbook *self)
  518. {
  519. lxw_worksheet *worksheet;
  520. lxw_sheet *sheet;
  521. uint32_t comment_id = 0;
  522. uint32_t vml_drawing_id = 0;
  523. uint32_t vml_data_id = 1;
  524. uint32_t vml_shape_id = 1024;
  525. uint32_t comment_count = 0;
  526. STAILQ_FOREACH(sheet, self->sheets, list_pointers) {
  527. if (sheet->is_chartsheet)
  528. continue;
  529. else
  530. worksheet = sheet->u.worksheet;
  531. if (!worksheet->has_vml && !worksheet->has_header_vml)
  532. continue;
  533. if (worksheet->has_vml) {
  534. self->has_vml = LXW_TRUE;
  535. if (worksheet->has_comments) {
  536. self->comment_count += 1;
  537. comment_id += 1;
  538. self->has_comments = LXW_TRUE;
  539. }
  540. vml_drawing_id += 1;
  541. comment_count = lxw_worksheet_prepare_vml_objects(worksheet,
  542. vml_data_id,
  543. vml_shape_id,
  544. vml_drawing_id,
  545. comment_id);
  546. /* Each VML should start with a shape id incremented by 1024. */
  547. vml_data_id += 1 * ((1024 + comment_count) / 1024);
  548. vml_shape_id += 1024 * ((1024 + comment_count) / 1024);
  549. }
  550. }
  551. }
  552. /*
  553. * Iterate through the worksheets and store any defined names used for print
  554. * ranges or repeat rows/columns.
  555. */
  556. STATIC void
  557. _prepare_defined_names(lxw_workbook *self)
  558. {
  559. lxw_worksheet *worksheet;
  560. char app_name[LXW_DEFINED_NAME_LENGTH];
  561. char range[LXW_DEFINED_NAME_LENGTH];
  562. char area[LXW_MAX_CELL_RANGE_LENGTH];
  563. char first_col[8];
  564. char last_col[8];
  565. STAILQ_FOREACH(worksheet, self->worksheets, list_pointers) {
  566. /*
  567. * Check for autofilter settings and store them.
  568. */
  569. if (worksheet->autofilter.in_use) {
  570. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  571. "%s!_FilterDatabase", worksheet->quoted_name);
  572. lxw_rowcol_to_range_abs(area,
  573. worksheet->autofilter.first_row,
  574. worksheet->autofilter.first_col,
  575. worksheet->autofilter.last_row,
  576. worksheet->autofilter.last_col);
  577. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH, "%s!%s",
  578. worksheet->quoted_name, area);
  579. /* Autofilters are the only defined name to set the hidden flag. */
  580. _store_defined_name(self, "_xlnm._FilterDatabase", app_name, range, worksheet->index, LXW_TRUE);
  581. }
  582. /*
  583. * Check for Print Area settings and store them.
  584. */
  585. if (worksheet->print_area.in_use) {
  586. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  587. "%s!Print_Area", worksheet->quoted_name);
  588. /* Check for print area that is the max row range. */
  589. if (worksheet->print_area.first_row == 0
  590. && worksheet->print_area.last_row == LXW_ROW_MAX - 1) {
  591. lxw_col_to_name(first_col,
  592. worksheet->print_area.first_col, LXW_FALSE);
  593. lxw_col_to_name(last_col,
  594. worksheet->print_area.last_col, LXW_FALSE);
  595. lxw_snprintf(area, LXW_MAX_CELL_RANGE_LENGTH - 1, "$%s:$%s",
  596. first_col, last_col);
  597. }
  598. /* Check for print area that is the max column range. */
  599. else if (worksheet->print_area.first_col == 0
  600. && worksheet->print_area.last_col == LXW_COL_MAX - 1) {
  601. lxw_snprintf(area, LXW_MAX_CELL_RANGE_LENGTH - 1, "$%d:$%d",
  602. worksheet->print_area.first_row + 1,
  603. worksheet->print_area.last_row + 1);
  604. }
  605. else {
  606. lxw_rowcol_to_range_abs(area,
  607. worksheet->print_area.first_row,
  608. worksheet->print_area.first_col,
  609. worksheet->print_area.last_row,
  610. worksheet->print_area.last_col);
  611. }
  612. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH, "%s!%s",
  613. worksheet->quoted_name, area);
  614. _store_defined_name(self, "_xlnm.Print_Area", app_name,
  615. range, worksheet->index, LXW_FALSE);
  616. }
  617. /*
  618. * Check for repeat rows/cols. aka, Print Titles and store them.
  619. */
  620. if (worksheet->repeat_rows.in_use || worksheet->repeat_cols.in_use) {
  621. if (worksheet->repeat_rows.in_use
  622. && worksheet->repeat_cols.in_use) {
  623. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  624. "%s!Print_Titles", worksheet->quoted_name);
  625. lxw_col_to_name(first_col,
  626. worksheet->repeat_cols.first_col, LXW_FALSE);
  627. lxw_col_to_name(last_col,
  628. worksheet->repeat_cols.last_col, LXW_FALSE);
  629. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH,
  630. "%s!$%s:$%s,%s!$%d:$%d",
  631. worksheet->quoted_name, first_col,
  632. last_col, worksheet->quoted_name,
  633. worksheet->repeat_rows.first_row + 1,
  634. worksheet->repeat_rows.last_row + 1);
  635. _store_defined_name(self, "_xlnm.Print_Titles", app_name,
  636. range, worksheet->index, LXW_FALSE);
  637. }
  638. else if (worksheet->repeat_rows.in_use) {
  639. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  640. "%s!Print_Titles", worksheet->quoted_name);
  641. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH,
  642. "%s!$%d:$%d", worksheet->quoted_name,
  643. worksheet->repeat_rows.first_row + 1,
  644. worksheet->repeat_rows.last_row + 1);
  645. _store_defined_name(self, "_xlnm.Print_Titles", app_name,
  646. range, worksheet->index, LXW_FALSE);
  647. }
  648. else if (worksheet->repeat_cols.in_use) {
  649. lxw_snprintf(app_name, LXW_DEFINED_NAME_LENGTH,
  650. "%s!Print_Titles", worksheet->quoted_name);
  651. lxw_col_to_name(first_col,
  652. worksheet->repeat_cols.first_col, LXW_FALSE);
  653. lxw_col_to_name(last_col,
  654. worksheet->repeat_cols.last_col, LXW_FALSE);
  655. lxw_snprintf(range, LXW_DEFINED_NAME_LENGTH,
  656. "%s!$%s:$%s", worksheet->quoted_name,
  657. first_col, last_col);
  658. _store_defined_name(self, "_xlnm.Print_Titles", app_name,
  659. range, worksheet->index, LXW_FALSE);
  660. }
  661. }
  662. }
  663. }
  664. /*
  665. * Iterate through the worksheets and set up any chart or image drawings.
  666. */
  667. STATIC void
  668. _prepare_drawings(lxw_workbook *self)
  669. {
  670. lxw_worksheet *worksheet;
  671. lxw_object_properties *image_options;
  672. uint16_t chart_ref_id = 0;
  673. uint16_t image_ref_id = 0;
  674. uint16_t drawing_id = 0;
  675. STAILQ_FOREACH(worksheet, self->worksheets, list_pointers) {
  676. if (STAILQ_EMPTY(worksheet->image_props)
  677. && STAILQ_EMPTY(worksheet->chart_data))
  678. continue;
  679. drawing_id++;
  680. STAILQ_FOREACH(image_options, worksheet->chart_data, list_pointers) {
  681. chart_ref_id++;
  682. lxw_worksheet_prepare_chart(worksheet, chart_ref_id, drawing_id,
  683. image_options, 0);
  684. if (image_options->chart)
  685. STAILQ_INSERT_TAIL(self->ordered_charts, image_options->chart,
  686. ordered_list_pointers);
  687. }
  688. STAILQ_FOREACH(image_options, worksheet->image_props, list_pointers) {
  689. if (image_options->image_type == LXW_IMAGE_PNG)
  690. self->has_png = LXW_TRUE;
  691. if (image_options->image_type == LXW_IMAGE_JPEG)
  692. self->has_jpeg = LXW_TRUE;
  693. if (image_options->image_type == LXW_IMAGE_BMP)
  694. self->has_bmp = LXW_TRUE;
  695. image_ref_id++;
  696. lxw_worksheet_prepare_image(worksheet, image_ref_id, drawing_id,
  697. image_options);
  698. }
  699. }
  700. self->drawing_count = drawing_id;
  701. }
  702. /*
  703. * Add "cached" data to charts to provide the numCache and strCache data for
  704. * series and title/axis ranges.
  705. */
  706. STATIC void
  707. _add_chart_cache_data(lxw_workbook *self)
  708. {
  709. lxw_chart *chart;
  710. lxw_chart_series *series;
  711. STAILQ_FOREACH(chart, self->ordered_charts, ordered_list_pointers) {
  712. _populate_range(self, chart->title.range);
  713. _populate_range(self, chart->x_axis->title.range);
  714. _populate_range(self, chart->y_axis->title.range);
  715. if (STAILQ_EMPTY(chart->series_list))
  716. continue;
  717. STAILQ_FOREACH(series, chart->series_list, list_pointers) {
  718. _populate_range(self, series->categories);
  719. _populate_range(self, series->values);
  720. _populate_range(self, series->title.range);
  721. }
  722. }
  723. }
  724. /*
  725. * Process and store the defined names. The defined names are stored with
  726. * the Workbook.xml but also with the App.xml if they refer to a sheet
  727. * range like "Sheet1!:A1". The defined names are store in sorted
  728. * order for consistency with Excel. The names need to be normalized before
  729. * sorting.
  730. */
  731. STATIC lxw_error
  732. _store_defined_name(lxw_workbook *self, const char *name, const char *app_name, const char *formula, int16_t index, uint8_t hidden)
  733. {
  734. lxw_worksheet *worksheet;
  735. lxw_defined_name *defined_name;
  736. lxw_defined_name *list_defined_name;
  737. char name_copy[LXW_DEFINED_NAME_LENGTH];
  738. char *tmp_str;
  739. char *worksheet_name;
  740. /* Do some checks on the input data */
  741. if (!name || !formula)
  742. return LXW_ERROR_NULL_PARAMETER_IGNORED;
  743. if (lxw_utf8_strlen(name) > LXW_DEFINED_NAME_LENGTH ||
  744. lxw_utf8_strlen(formula) > LXW_DEFINED_NAME_LENGTH) {
  745. return LXW_ERROR_128_STRING_LENGTH_EXCEEDED;
  746. }
  747. /* Allocate a new defined_name to be added to the linked list of names. */
  748. defined_name = calloc(1, sizeof(struct lxw_defined_name));
  749. RETURN_ON_MEM_ERROR(defined_name, LXW_ERROR_MEMORY_MALLOC_FAILED);
  750. /* Copy the user input string. */
  751. lxw_strcpy(name_copy, name);
  752. /* Set the worksheet index or -1 for a global defined name. */
  753. defined_name->index = index;
  754. defined_name->hidden = hidden;
  755. /* Check for local defined names like like "Sheet1!name". */
  756. tmp_str = strchr(name_copy, '!');
  757. if (tmp_str == NULL) {
  758. /* The name is global. We just store the defined name string. */
  759. lxw_strcpy(defined_name->name, name_copy);
  760. }
  761. else {
  762. /* The name is worksheet local. We need to extract the sheet name
  763. * and map it to a sheet index. */
  764. /* Split the into the worksheet name and defined name. */
  765. *tmp_str = '\0';
  766. tmp_str++;
  767. worksheet_name = name_copy;
  768. /* Remove any worksheet quoting. */
  769. if (worksheet_name[0] == '\'')
  770. worksheet_name++;
  771. if (worksheet_name[strlen(worksheet_name) - 1] == '\'')
  772. worksheet_name[strlen(worksheet_name) - 1] = '\0';
  773. /* Search for worksheet name to get the equivalent worksheet index. */
  774. STAILQ_FOREACH(worksheet, self->worksheets, list_pointers) {
  775. if (strcmp(worksheet_name, worksheet->name) == 0) {
  776. defined_name->index = worksheet->index;
  777. lxw_strcpy(defined_name->normalised_sheetname,
  778. worksheet_name);
  779. }
  780. }
  781. /* If we didn't find the worksheet name we exit. */
  782. if (defined_name->index == -1)
  783. goto mem_error;
  784. lxw_strcpy(defined_name->name, tmp_str);
  785. }
  786. /* Print titles and repeat title pass in the name used for App.xml. */
  787. if (app_name) {
  788. lxw_strcpy(defined_name->app_name, app_name);
  789. lxw_strcpy(defined_name->normalised_sheetname, app_name);
  790. }
  791. else {
  792. lxw_strcpy(defined_name->app_name, name);
  793. }
  794. /* We need to normalize the defined names for sorting. This involves
  795. * removing any _xlnm namespace and converting it to lowercase. */
  796. tmp_str = strstr(name_copy, "_xlnm.");
  797. if (tmp_str)
  798. lxw_strcpy(defined_name->normalised_name, defined_name->name + 6);
  799. else
  800. lxw_strcpy(defined_name->normalised_name, defined_name->name);
  801. lxw_str_tolower(defined_name->normalised_name);
  802. lxw_str_tolower(defined_name->normalised_sheetname);
  803. /* Strip leading "=" from the formula. */
  804. if (formula[0] == '=')
  805. lxw_strcpy(defined_name->formula, formula + 1);
  806. else
  807. lxw_strcpy(defined_name->formula, formula);
  808. /* We add the defined name to the list in sorted order. */
  809. list_defined_name = TAILQ_FIRST(self->defined_names);
  810. if (list_defined_name == NULL ||
  811. _compare_defined_names(defined_name, list_defined_name) < 1) {
  812. /* List is empty or defined name goes to the head. */
  813. TAILQ_INSERT_HEAD(self->defined_names, defined_name, list_pointers);
  814. return LXW_NO_ERROR;
  815. }
  816. TAILQ_FOREACH(list_defined_name, self->defined_names, list_pointers) {
  817. int res = _compare_defined_names(defined_name, list_defined_name);
  818. /* The entry already exists. We exit and don't overwrite. */
  819. if (res == 0)
  820. goto mem_error;
  821. /* New defined name is inserted in sorted order before other entries. */
  822. if (res < 0) {
  823. TAILQ_INSERT_BEFORE(list_defined_name, defined_name,
  824. list_pointers);
  825. return LXW_NO_ERROR;
  826. }
  827. }
  828. /* If the entry wasn't less than any of the entries in the list we add it
  829. * to the end. */
  830. TAILQ_INSERT_TAIL(self->defined_names, defined_name, list_pointers);
  831. return LXW_NO_ERROR;
  832. mem_error:
  833. free(defined_name);
  834. return LXW_ERROR_MEMORY_MALLOC_FAILED;
  835. }
  836. /*
  837. * Compare two defined_name structures.
  838. */
  839. static int
  840. _compare_defined_names(lxw_defined_name *a, lxw_defined_name *b)
  841. {
  842. int res = strcmp(a->normalised_name, b->normalised_name);
  843. /* Primary comparison based on defined name. */
  844. if (res)
  845. return res;
  846. /* Secondary comparison based on worksheet name. */
  847. res = strcmp(a->normalised_sheetname, b->normalised_sheetname);
  848. return res;
  849. }
  850. /* Convert a chart range such as Sheet1!$A$1:$A$5 to a sheet name and row-col
  851. * dimensions, or vice-versa. This gives us the dimensions to read data back
  852. * from the worksheet.
  853. */
  854. STATIC void
  855. _populate_range_dimensions(lxw_workbook *self, lxw_series_range *range)
  856. {
  857. char formula[LXW_MAX_FORMULA_RANGE_LENGTH] = { 0 };
  858. char *tmp_str;
  859. char *sheetname;
  860. /* If neither the range formula or sheetname is defined then this probably
  861. * isn't a valid range.
  862. */
  863. if (!range->formula && !range->sheetname) {
  864. range->ignore_cache = LXW_TRUE;
  865. return;
  866. }
  867. /* If the sheetname is already defined it was already set via
  868. * chart_series_set_categories() or chart_series_set_values().
  869. */
  870. if (range->sheetname)
  871. return;
  872. /* Ignore non-contiguous range like (Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5) */
  873. if (range->formula[0] == '(') {
  874. range->ignore_cache = LXW_TRUE;
  875. return;
  876. }
  877. /* Create a copy of the formula to modify and parse into parts. */
  878. lxw_snprintf(formula, LXW_MAX_FORMULA_RANGE_LENGTH, "%s", range->formula);
  879. /* Check for valid formula. TODO. This needs stronger validation. */
  880. tmp_str = strchr(formula, '!');
  881. if (tmp_str == NULL) {
  882. range->ignore_cache = LXW_TRUE;
  883. return;
  884. }
  885. else {
  886. /* Split the formulas into sheetname and row-col data. */
  887. *tmp_str = '\0';
  888. tmp_str++;
  889. sheetname = formula;
  890. /* Remove any worksheet quoting. */
  891. if (sheetname[0] == '\'')
  892. sheetname++;
  893. if (sheetname[strlen(sheetname) - 1] == '\'')
  894. sheetname[strlen(sheetname) - 1] = '\0';
  895. /* Check that the sheetname exists. */
  896. if (!workbook_get_worksheet_by_name(self, sheetname)) {
  897. LXW_WARN_FORMAT2("workbook_add_chart(): worksheet name '%s' "
  898. "in chart formula '%s' doesn't exist.",
  899. sheetname, range->formula);
  900. range->ignore_cache = LXW_TRUE;
  901. return;
  902. }
  903. range->sheetname = lxw_strdup(sheetname);
  904. range->first_row = lxw_name_to_row(tmp_str);
  905. range->first_col = lxw_name_to_col(tmp_str);
  906. if (strchr(tmp_str, ':')) {
  907. /* 2D range. */
  908. range->last_row = lxw_name_to_row_2(tmp_str);
  909. range->last_col = lxw_name_to_col_2(tmp_str);
  910. }
  911. else {
  912. /* 1D range. */
  913. range->last_row = range->first_row;
  914. range->last_col = range->first_col;
  915. }
  916. }
  917. }
  918. /*
  919. * Populate the data cache of a chart data series by reading the data from the
  920. * relevant worksheet and adding it to the cached in the range object as a
  921. * list of points.
  922. *
  923. * Note, the data cache isn't strictly required by Excel but it helps if the
  924. * chart is embedded in another application such as PowerPoint and it also
  925. * helps with comparison testing.
  926. */
  927. STATIC void
  928. _populate_range_data_cache(lxw_workbook *self, lxw_series_range *range)
  929. {
  930. lxw_worksheet *worksheet;
  931. lxw_row_t row_num;
  932. lxw_col_t col_num;
  933. lxw_row *row_obj;
  934. lxw_cell *cell_obj;
  935. struct lxw_series_data_point *data_point;
  936. uint16_t num_data_points = 0;
  937. /* If ignore_cache is set then don't try to populate the cache. This flag
  938. * may be set manually, for testing, or due to a case where the cache
  939. * can't be calculated.
  940. */
  941. if (range->ignore_cache)
  942. return;
  943. /* Currently we only handle 2D ranges so ensure either the rows or cols
  944. * are the same.
  945. */
  946. if (range->first_row != range->last_row
  947. && range->first_col != range->last_col) {
  948. range->ignore_cache = LXW_TRUE;
  949. return;
  950. }
  951. /* Check that the sheetname exists. */
  952. worksheet = workbook_get_worksheet_by_name(self, range->sheetname);
  953. if (!worksheet) {
  954. LXW_WARN_FORMAT2("workbook_add_chart(): worksheet name '%s' "
  955. "in chart formula '%s' doesn't exist.",
  956. range->sheetname, range->formula);
  957. range->ignore_cache = LXW_TRUE;
  958. return;
  959. }
  960. /* We can't read the data when worksheet optimization is on. */
  961. if (worksheet->optimize) {
  962. range->ignore_cache = LXW_TRUE;
  963. return;
  964. }
  965. /* Iterate through the worksheet data and populate the range cache. */
  966. for (row_num = range->first_row; row_num <= range->last_row; row_num++) {
  967. row_obj = lxw_worksheet_find_row(worksheet, row_num);
  968. for (col_num = range->first_col; col_num <= range->last_col;
  969. col_num++) {
  970. data_point = calloc(1, sizeof(struct lxw_series_data_point));
  971. if (!data_point) {
  972. range->ignore_cache = LXW_TRUE;
  973. return;
  974. }
  975. #if defined(LXW_VERSION_ID) && LXW_VERSION_ID >= 93
  976. cell_obj = lxw_worksheet_find_cell_in_row(row_obj, col_num);
  977. #else
  978. cell_obj = lxw_worksheet_find_cell(row_obj, col_num);
  979. #endif
  980. if (cell_obj) {
  981. if (cell_obj->type == NUMBER_CELL) {
  982. data_point->number = cell_obj->u.number;
  983. }
  984. if (cell_obj->type == STRING_CELL) {
  985. data_point->string = lxw_strdup(cell_obj->sst_string);
  986. data_point->is_string = LXW_TRUE;
  987. range->has_string_cache = LXW_TRUE;
  988. }
  989. }
  990. else {
  991. data_point->no_data = LXW_TRUE;
  992. }
  993. STAILQ_INSERT_TAIL(range->data_cache, data_point, list_pointers);
  994. num_data_points++;
  995. }
  996. }
  997. range->num_data_points = num_data_points;
  998. }
  999. /* Set the range dimensions and set the data cache.
  1000. */
  1001. STATIC void
  1002. _populate_range(lxw_workbook *self, lxw_series_range *range)
  1003. {
  1004. _populate_range_dimensions(self, range);
  1005. _populate_range_data_cache(self, range);
  1006. }