@@ -208,6 +208,24 @@ void datetime_writer(lxw_datetime *datetime, zend_long row, zend_long columns, z
208208 worksheet_write_datetime (res -> worksheet , (lxw_row_t )row , (lxw_col_t )columns , datetime , value_format );
209209}
210210
211+ /*
212+ * Write the comment to the cell
213+ */
214+ void comment_writer (zend_string * comment , zend_long row , zend_long columns , xls_resource_write_t * res )
215+ {
216+ int error = worksheet_write_comment (res -> worksheet , (lxw_row_t )row , (lxw_col_t )columns , ZSTR_VAL (comment ));
217+
218+ WORKSHEET_WRITER_EXCEPTION (error );
219+ }
220+
221+ /*
222+ * Show all comments
223+ */
224+ void comment_show (xls_resource_write_t * res )
225+ {
226+ worksheet_show_comments (res -> worksheet );
227+ }
228+
211229/*
212230 * Add the autofilter.
213231 */
@@ -333,6 +351,9 @@ workbook_file(xls_resource_write_t *self)
333351 worksheet -> active = 1 ;
334352 }
335353
354+ /* Prepare the worksheet VML elements such as comments. */
355+ _prepare_vml (self -> workbook );
356+
336357 /* Set the defined names for the worksheets such as Print Titles. */
337358 _prepare_defined_names (self -> workbook );
338359
@@ -343,7 +364,7 @@ workbook_file(xls_resource_write_t *self)
343364 _add_chart_cache_data (self -> workbook );
344365
345366 /* Create a packager object to assemble sub-elements into a zip file. */
346- packager = lxw_packager_new (self -> workbook -> filename , self -> workbook -> options .tmpdir , 0 );
367+ packager = lxw_packager_new (self -> workbook -> filename , self -> workbook -> options .tmpdir , self -> workbook -> options . use_zip64 );
347368
348369 /* If the packager fails it is generally due to a zip permission error. */
349370 if (packager == NULL ) {
@@ -375,6 +396,28 @@ workbook_file(xls_resource_write_t *self)
375396 "Error = %s\n" , self -> workbook -> filename , strerror (errno ));
376397 }
377398
399+ /* If LXW_ERROR_ZIP_PARAMETER_ERROR then errno is set by zip. */
400+ if (error == LXW_ERROR_ZIP_PARAMETER_ERROR ) {
401+ fprintf (stderr , "[ERROR] workbook_close(): "
402+ "Zip ZIP_PARAMERROR error while creating xlsx file '%s'. "
403+ "System error = %s\n" , self -> workbook -> filename , strerror (errno ));
404+ }
405+
406+ /* If LXW_ERROR_ZIP_BAD_ZIP_FILE then errno is set by zip. */
407+ if (error == LXW_ERROR_ZIP_BAD_ZIP_FILE ) {
408+ fprintf (stderr , "[ERROR] workbook_close(): "
409+ "Zip ZIP_BADZIPFILE error while creating xlsx file '%s'. "
410+ "This may require the use_zip64 option for large files. "
411+ "System error = %s\n" , self -> workbook -> filename , strerror (errno ));
412+ }
413+
414+ /* If LXW_ERROR_ZIP_INTERNAL_ERROR then errno is set by zip. */
415+ if (error == LXW_ERROR_ZIP_INTERNAL_ERROR ) {
416+ fprintf (stderr , "[ERROR] workbook_close(): "
417+ "Zip ZIP_INTERNALERROR error while creating xlsx file '%s'. "
418+ "System error = %s\n" , self -> workbook -> filename , strerror (errno ));
419+ }
420+
378421 /* The next 2 error conditions don't set errno. */
379422 if (error == LXW_ERROR_ZIP_FILE_ADD ) {
380423 fprintf (stderr , "[ERROR] workbook_close(): "
@@ -398,6 +441,53 @@ void _php_vtiful_xls_close(zend_resource *rsrc TSRMLS_DC)
398441
399442}
400443
444+ /*
445+ * Iterate through the worksheets and set up the VML objects.
446+ */
447+
448+ STATIC void
449+ _prepare_vml (lxw_workbook * self )
450+ {
451+ lxw_worksheet * worksheet ;
452+ lxw_sheet * sheet ;
453+ uint32_t comment_id = 0 ;
454+ uint32_t vml_drawing_id = 0 ;
455+ uint32_t vml_data_id = 1 ;
456+ uint32_t vml_shape_id = 1024 ;
457+ uint32_t comment_count = 0 ;
458+
459+ STAILQ_FOREACH (sheet , self -> sheets , list_pointers ) {
460+ if (sheet -> is_chartsheet )
461+ continue ;
462+ else
463+ worksheet = sheet -> u .worksheet ;
464+
465+ if (!worksheet -> has_vml && !worksheet -> has_header_vml )
466+ continue ;
467+
468+ if (worksheet -> has_vml ) {
469+ self -> has_vml = LXW_TRUE ;
470+ if (worksheet -> has_comments ) {
471+ self -> comment_count += 1 ;
472+ comment_id += 1 ;
473+ self -> has_comments = LXW_TRUE ;
474+ }
475+
476+ vml_drawing_id += 1 ;
477+
478+ comment_count = lxw_worksheet_prepare_vml_objects (worksheet ,
479+ vml_data_id ,
480+ vml_shape_id ,
481+ vml_drawing_id ,
482+ comment_id );
483+
484+ /* Each VML should start with a shape id incremented by 1024. */
485+ vml_data_id += 1 * ((1024 + comment_count ) / 1024 );
486+ vml_shape_id += 1024 * ((1024 + comment_count ) / 1024 );
487+ }
488+ }
489+ }
490+
401491/*
402492 * Iterate through the worksheets and store any defined names used for print
403493 * ranges or repeat rows/columns.
0 commit comments