fast_excel 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/CHANGELOG.md +3 -1
  4. data/Rakefile +4 -1
  5. data/fast_excel.gemspec +1 -1
  6. data/lib/fast_excel/binding/workbook.rb +9 -0
  7. data/lib/fast_excel/binding/worksheet.rb +2 -2
  8. data/lib/fast_excel/binding.rb +16 -13
  9. data/libxlsxwriter/.cirrus.yml +9 -0
  10. data/libxlsxwriter/.github/workflows/cmake_actions.yml +10 -6
  11. data/libxlsxwriter/.github/workflows/code_style.yml +2 -0
  12. data/libxlsxwriter/.github/workflows/make_32_actions.yml +43 -0
  13. data/libxlsxwriter/.github/workflows/windows_build.yml +7 -6
  14. data/libxlsxwriter/.github/workflows/zig_build.yml +1 -3
  15. data/libxlsxwriter/.gitignore +9 -7
  16. data/libxlsxwriter/.indent.pro +6 -0
  17. data/libxlsxwriter/CMakeLists.txt +377 -238
  18. data/libxlsxwriter/Changes.txt +189 -0
  19. data/libxlsxwriter/LICENSE.txt +1 -1
  20. data/libxlsxwriter/Makefile +36 -4
  21. data/libxlsxwriter/Readme.md +1 -1
  22. data/libxlsxwriter/build.zig +181 -92
  23. data/libxlsxwriter/build.zig.zon +15 -4
  24. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +4 -0
  25. data/libxlsxwriter/include/xlsxwriter/app.h +2 -1
  26. data/libxlsxwriter/include/xlsxwriter/chart.h +134 -1
  27. data/libxlsxwriter/include/xlsxwriter/chartsheet.h +2 -1
  28. data/libxlsxwriter/include/xlsxwriter/comment.h +2 -1
  29. data/libxlsxwriter/include/xlsxwriter/common.h +12 -8
  30. data/libxlsxwriter/include/xlsxwriter/content_types.h +3 -1
  31. data/libxlsxwriter/include/xlsxwriter/core.h +2 -1
  32. data/libxlsxwriter/include/xlsxwriter/custom.h +2 -1
  33. data/libxlsxwriter/include/xlsxwriter/drawing.h +2 -1
  34. data/libxlsxwriter/include/xlsxwriter/format.h +34 -3
  35. data/libxlsxwriter/include/xlsxwriter/hash_table.h +2 -1
  36. data/libxlsxwriter/include/xlsxwriter/metadata.h +5 -1
  37. data/libxlsxwriter/include/xlsxwriter/packager.h +6 -1
  38. data/libxlsxwriter/include/xlsxwriter/relationships.h +3 -1
  39. data/libxlsxwriter/include/xlsxwriter/rich_value.h +51 -0
  40. data/libxlsxwriter/include/xlsxwriter/rich_value_rel.h +50 -0
  41. data/libxlsxwriter/include/xlsxwriter/rich_value_structure.h +53 -0
  42. data/libxlsxwriter/include/xlsxwriter/rich_value_types.h +49 -0
  43. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +2 -1
  44. data/libxlsxwriter/include/xlsxwriter/styles.h +2 -1
  45. data/libxlsxwriter/include/xlsxwriter/table.h +2 -1
  46. data/libxlsxwriter/include/xlsxwriter/theme.h +2 -1
  47. data/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +4 -4
  48. data/libxlsxwriter/include/xlsxwriter/third_party/zip.h +3 -3
  49. data/libxlsxwriter/include/xlsxwriter/utility.h +58 -7
  50. data/libxlsxwriter/include/xlsxwriter/vml.h +2 -1
  51. data/libxlsxwriter/include/xlsxwriter/workbook.h +59 -2
  52. data/libxlsxwriter/include/xlsxwriter/worksheet.h +159 -13
  53. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +11 -10
  54. data/libxlsxwriter/include/xlsxwriter.h +5 -4
  55. data/libxlsxwriter/libxlsxwriter.podspec +6 -6
  56. data/libxlsxwriter/src/Makefile +2 -1
  57. data/libxlsxwriter/src/app.c +2 -1
  58. data/libxlsxwriter/src/chart.c +360 -63
  59. data/libxlsxwriter/src/chartsheet.c +2 -1
  60. data/libxlsxwriter/src/comment.c +2 -1
  61. data/libxlsxwriter/src/content_types.c +22 -1
  62. data/libxlsxwriter/src/core.c +2 -1
  63. data/libxlsxwriter/src/custom.c +2 -1
  64. data/libxlsxwriter/src/drawing.c +7 -3
  65. data/libxlsxwriter/src/format.c +21 -1
  66. data/libxlsxwriter/src/hash_table.c +2 -1
  67. data/libxlsxwriter/src/metadata.c +176 -20
  68. data/libxlsxwriter/src/packager.c +306 -6
  69. data/libxlsxwriter/src/relationships.c +25 -1
  70. data/libxlsxwriter/src/rich_value.c +191 -0
  71. data/libxlsxwriter/src/rich_value_rel.c +142 -0
  72. data/libxlsxwriter/src/rich_value_structure.c +162 -0
  73. data/libxlsxwriter/src/rich_value_types.c +199 -0
  74. data/libxlsxwriter/src/shared_strings.c +2 -1
  75. data/libxlsxwriter/src/styles.c +31 -7
  76. data/libxlsxwriter/src/table.c +2 -1
  77. data/libxlsxwriter/src/theme.c +2 -1
  78. data/libxlsxwriter/src/utility.c +136 -46
  79. data/libxlsxwriter/src/vml.c +2 -1
  80. data/libxlsxwriter/src/workbook.c +191 -10
  81. data/libxlsxwriter/src/worksheet.c +514 -34
  82. data/libxlsxwriter/src/xmlwriter.c +17 -22
  83. data/libxlsxwriter/third_party/minizip/Makefile.orig +1 -1
  84. data/libxlsxwriter/third_party/minizip/configure.ac +1 -1
  85. data/libxlsxwriter/third_party/minizip/ioapi.h +6 -6
  86. data/libxlsxwriter/third_party/minizip/miniunz.c +16 -2
  87. data/libxlsxwriter/third_party/minizip/unzip.c +4 -4
  88. data/libxlsxwriter/third_party/minizip/unzip.h +1 -1
  89. data/libxlsxwriter/third_party/minizip/zip.c +5 -5
  90. data/libxlsxwriter/third_party/minizip/zip.h +3 -3
  91. data/libxlsxwriter/version.txt +1 -1
  92. data/test/validations_test.rb +3 -3
  93. data/test/worksheet_test.rb +10 -2
  94. metadata +11 -4
  95. data/libxlsxwriter/cmake/FindMINIZIP.cmake +0 -121
  96. data/libxlsxwriter/cmake/FindPackage.cmake +0 -183
  97. data/libxlsxwriter/cmake/i686-toolchain.cmake +0 -7
@@ -39,7 +39,8 @@
39
39
  * The Packager class coordinates the classes that represent the
40
40
  * elements of the package and writes them into the XLSX file.
41
41
  *
42
- * Copyright 2014-2022, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
42
+ * SPDX-License-Identifier: BSD-2-Clause
43
+ * Copyright 2014-2026, John McNamara, jmcnamara@cpan.org.
43
44
  *
44
45
  */
45
46
 
@@ -49,13 +50,13 @@
49
50
  #include "xlsxwriter/hash_table.h"
50
51
  #include "xlsxwriter/utility.h"
51
52
 
52
- STATIC lxw_error _add_file_to_zip(lxw_packager *self, FILE * file,
53
+ STATIC lxw_error _add_file_to_zip(lxw_packager *self, FILE *file,
53
54
  const char *filename);
54
55
 
55
56
  STATIC lxw_error _add_buffer_to_zip(lxw_packager *self, const char *buffer,
56
57
  size_t buffer_size, const char *filename);
57
58
 
58
- STATIC lxw_error _add_to_zip(lxw_packager *self, FILE * file,
59
+ STATIC lxw_error _add_to_zip(lxw_packager *self, FILE *file,
59
60
  char **buffer, size_t *buffer_size,
60
61
  const char *filename);
61
62
 
@@ -382,9 +383,43 @@ _write_image_files(lxw_packager *self)
382
383
  else
383
384
  worksheet = sheet->u.worksheet;
384
385
 
385
- if (STAILQ_EMPTY(worksheet->image_props))
386
+ if (STAILQ_EMPTY(worksheet->image_props)
387
+ && STAILQ_EMPTY(worksheet->embedded_image_props))
386
388
  continue;
387
389
 
390
+ STAILQ_FOREACH(object_props, worksheet->embedded_image_props,
391
+ list_pointers) {
392
+
393
+ if (object_props->is_duplicate)
394
+ continue;
395
+
396
+ lxw_snprintf(filename, LXW_FILENAME_LENGTH,
397
+ "xl/media/image%d.%s", index++,
398
+ object_props->extension);
399
+
400
+ if (!object_props->is_image_buffer) {
401
+ /* Check that the image file exists and can be opened. */
402
+ image_stream = lxw_fopen(object_props->filename, "rb");
403
+ if (!image_stream) {
404
+ LXW_WARN_FORMAT1("Error adding image to xlsx file: file "
405
+ "doesn't exist or can't be opened: %s.",
406
+ object_props->filename);
407
+ return LXW_ERROR_CREATING_TMPFILE;
408
+ }
409
+
410
+ err = _add_file_to_zip(self, image_stream, filename);
411
+ fclose(image_stream);
412
+ }
413
+ else {
414
+ err = _add_buffer_to_zip(self,
415
+ object_props->image_buffer,
416
+ object_props->image_buffer_size,
417
+ filename);
418
+ }
419
+
420
+ RETURN_ON_ERROR(err);
421
+ }
422
+
388
423
  STAILQ_FOREACH(object_props, worksheet->image_props, list_pointers) {
389
424
 
390
425
  if (object_props->is_duplicate)
@@ -1052,6 +1087,10 @@ _write_metadata_file(lxw_packager *self)
1052
1087
  goto mem_error;
1053
1088
  }
1054
1089
 
1090
+ metadata->has_embedded_images = self->workbook->has_embedded_images;
1091
+ metadata->num_embedded_images = self->workbook->num_embedded_images;
1092
+ metadata->has_dynamic_functions = self->workbook->has_dynamic_functions;
1093
+
1055
1094
  lxw_metadata_assemble_xml_file(metadata);
1056
1095
 
1057
1096
  err = _add_to_zip(self, metadata->file, &buffer, &buffer_size,
@@ -1066,6 +1105,177 @@ mem_error:
1066
1105
  return err;
1067
1106
  }
1068
1107
 
1108
+ /*
1109
+ * Write the rdrichvalue.xml file.
1110
+ */
1111
+ STATIC lxw_error
1112
+ _write_rich_value_file(lxw_packager *self)
1113
+ {
1114
+ lxw_error err = LXW_NO_ERROR;
1115
+ lxw_rich_value *rich_value;
1116
+ char *buffer = NULL;
1117
+ size_t buffer_size = 0;
1118
+
1119
+ if (!self->workbook->has_embedded_images)
1120
+ return LXW_NO_ERROR;
1121
+
1122
+ rich_value = lxw_rich_value_new();
1123
+ if (!rich_value) {
1124
+ err = LXW_ERROR_MEMORY_MALLOC_FAILED;
1125
+ goto mem_error;
1126
+ }
1127
+
1128
+ rich_value->workbook = self->workbook;
1129
+
1130
+ rich_value->file =
1131
+ lxw_get_filehandle(&buffer, &buffer_size, self->tmpdir);
1132
+ if (!rich_value->file) {
1133
+ err = LXW_ERROR_CREATING_TMPFILE;
1134
+ goto mem_error;
1135
+ }
1136
+
1137
+ lxw_rich_value_assemble_xml_file(rich_value);
1138
+
1139
+ err = _add_to_zip(self, rich_value->file, &buffer, &buffer_size,
1140
+ "xl/richData/rdrichvalue.xml");
1141
+
1142
+ fclose(rich_value->file);
1143
+ free(buffer);
1144
+
1145
+ mem_error:
1146
+ lxw_rich_value_free(rich_value);
1147
+
1148
+ return err;
1149
+ }
1150
+
1151
+ /*
1152
+ * Write the richValueRel.xml file.
1153
+ */
1154
+ STATIC lxw_error
1155
+ _write_rich_value_rel_file(lxw_packager *self)
1156
+ {
1157
+ lxw_error err = LXW_NO_ERROR;
1158
+ lxw_rich_value_rel *rich_value_rel;
1159
+ char *buffer = NULL;
1160
+ size_t buffer_size = 0;
1161
+
1162
+ if (!self->workbook->has_embedded_images)
1163
+ return LXW_NO_ERROR;
1164
+
1165
+ rich_value_rel = lxw_rich_value_rel_new();
1166
+ if (!rich_value_rel) {
1167
+ err = LXW_ERROR_MEMORY_MALLOC_FAILED;
1168
+ goto mem_error;
1169
+ }
1170
+
1171
+ rich_value_rel->num_embedded_images = self->workbook->num_embedded_images;
1172
+
1173
+ rich_value_rel->file =
1174
+ lxw_get_filehandle(&buffer, &buffer_size, self->tmpdir);
1175
+ if (!rich_value_rel->file) {
1176
+ err = LXW_ERROR_CREATING_TMPFILE;
1177
+ goto mem_error;
1178
+ }
1179
+
1180
+ lxw_rich_value_rel_assemble_xml_file(rich_value_rel);
1181
+
1182
+ err = _add_to_zip(self, rich_value_rel->file, &buffer, &buffer_size,
1183
+ "xl/richData/richValueRel.xml");
1184
+
1185
+ fclose(rich_value_rel->file);
1186
+ free(buffer);
1187
+
1188
+ mem_error:
1189
+ lxw_rich_value_rel_free(rich_value_rel);
1190
+
1191
+ return err;
1192
+ }
1193
+
1194
+ /*
1195
+ * Write the rdRichValueTypes.xml file.
1196
+ */
1197
+ STATIC lxw_error
1198
+ _write_rich_value_types_file(lxw_packager *self)
1199
+ {
1200
+ lxw_error err = LXW_NO_ERROR;
1201
+ lxw_rich_value_types *rich_value_types;
1202
+ char *buffer = NULL;
1203
+ size_t buffer_size = 0;
1204
+
1205
+ if (!self->workbook->has_embedded_images)
1206
+ return LXW_NO_ERROR;
1207
+
1208
+ rich_value_types = lxw_rich_value_types_new();
1209
+ if (!rich_value_types) {
1210
+ err = LXW_ERROR_MEMORY_MALLOC_FAILED;
1211
+ goto mem_error;
1212
+ }
1213
+
1214
+ rich_value_types->file =
1215
+ lxw_get_filehandle(&buffer, &buffer_size, self->tmpdir);
1216
+ if (!rich_value_types->file) {
1217
+ err = LXW_ERROR_CREATING_TMPFILE;
1218
+ goto mem_error;
1219
+ }
1220
+
1221
+ lxw_rich_value_types_assemble_xml_file(rich_value_types);
1222
+
1223
+ err = _add_to_zip(self, rich_value_types->file, &buffer, &buffer_size,
1224
+ "xl/richData/rdRichValueTypes.xml");
1225
+
1226
+ fclose(rich_value_types->file);
1227
+ free(buffer);
1228
+
1229
+ mem_error:
1230
+ lxw_rich_value_types_free(rich_value_types);
1231
+
1232
+ return err;
1233
+ }
1234
+
1235
+ /*
1236
+ * Write the rdrichvaluestructure.xml file.
1237
+ */
1238
+ STATIC lxw_error
1239
+ _write_rich_value_structure_file(lxw_packager *self)
1240
+ {
1241
+ lxw_error err = LXW_NO_ERROR;
1242
+ lxw_rich_value_structure *rich_value_structure;
1243
+ char *buffer = NULL;
1244
+ size_t buffer_size = 0;
1245
+
1246
+ if (!self->workbook->has_embedded_images)
1247
+ return LXW_NO_ERROR;
1248
+
1249
+ rich_value_structure = lxw_rich_value_structure_new();
1250
+ if (!rich_value_structure) {
1251
+ err = LXW_ERROR_MEMORY_MALLOC_FAILED;
1252
+ goto mem_error;
1253
+ }
1254
+
1255
+ rich_value_structure->has_embedded_image_descriptions =
1256
+ self->workbook->has_embedded_image_descriptions;
1257
+
1258
+ rich_value_structure->file =
1259
+ lxw_get_filehandle(&buffer, &buffer_size, self->tmpdir);
1260
+ if (!rich_value_structure->file) {
1261
+ err = LXW_ERROR_CREATING_TMPFILE;
1262
+ goto mem_error;
1263
+ }
1264
+
1265
+ lxw_rich_value_structure_assemble_xml_file(rich_value_structure);
1266
+
1267
+ err = _add_to_zip(self, rich_value_structure->file, &buffer, &buffer_size,
1268
+ "xl/richData/rdrichvaluestructure.xml");
1269
+
1270
+ fclose(rich_value_structure->file);
1271
+ free(buffer);
1272
+
1273
+ mem_error:
1274
+ lxw_rich_value_structure_free(rich_value_structure);
1275
+
1276
+ return err;
1277
+ }
1278
+
1069
1279
  /*
1070
1280
  * Write the custom.xml file.
1071
1281
  */
@@ -1326,6 +1536,9 @@ _write_content_types_file(lxw_packager *self)
1326
1536
  if (workbook->has_metadata)
1327
1537
  lxw_ct_add_metadata(content_types);
1328
1538
 
1539
+ if (workbook->has_embedded_images)
1540
+ lxw_ct_add_rich_value(content_types);
1541
+
1329
1542
  lxw_content_types_assemble_xml_file(content_types);
1330
1543
 
1331
1544
  err = _add_to_zip(self, content_types->file, &buffer, &buffer_size,
@@ -1396,6 +1609,9 @@ _write_workbook_rels_file(lxw_packager *self)
1396
1609
  if (workbook->has_metadata)
1397
1610
  lxw_add_document_relationship(rels, "/sheetMetadata", "metadata.xml");
1398
1611
 
1612
+ if (workbook->has_embedded_images)
1613
+ lxw_add_rich_value_relationship(rels);
1614
+
1399
1615
  lxw_relationships_assemble_xml_file(rels);
1400
1616
 
1401
1617
  err = _add_to_zip(self, rels->file, &buffer, &buffer_size,
@@ -1714,6 +1930,75 @@ mem_error:
1714
1930
  return err;
1715
1931
  }
1716
1932
 
1933
+ /*
1934
+ * Write the richValueRel.xml.rels files for embedded images.
1935
+ */
1936
+ STATIC lxw_error
1937
+ _write_rich_value_rels_file(lxw_packager *self)
1938
+ {
1939
+ lxw_workbook *workbook = self->workbook;
1940
+ lxw_sheet *sheet;
1941
+ lxw_worksheet *worksheet;
1942
+ lxw_object_properties *object_props;
1943
+
1944
+ lxw_relationships *rels;
1945
+ char *buffer = NULL;
1946
+ size_t buffer_size = 0;
1947
+ char sheetname[LXW_FILENAME_LENGTH] = { 0 };
1948
+ char target[LXW_FILENAME_LENGTH] = { 0 };
1949
+ lxw_error err = LXW_NO_ERROR;
1950
+ uint32_t index = 1;
1951
+
1952
+ if (!workbook->has_embedded_images)
1953
+ return LXW_NO_ERROR;
1954
+
1955
+ rels = lxw_relationships_new();
1956
+
1957
+ rels->file = lxw_get_filehandle(&buffer, &buffer_size, self->tmpdir);
1958
+ if (!rels->file) {
1959
+ lxw_free_relationships(rels);
1960
+ return LXW_ERROR_CREATING_TMPFILE;
1961
+ }
1962
+
1963
+ STAILQ_FOREACH(sheet, workbook->sheets, list_pointers) {
1964
+ if (sheet->is_chartsheet)
1965
+ continue;
1966
+ else
1967
+ worksheet = sheet->u.worksheet;
1968
+
1969
+ if (STAILQ_EMPTY(worksheet->embedded_image_props))
1970
+ continue;
1971
+
1972
+ STAILQ_FOREACH(object_props, worksheet->embedded_image_props,
1973
+ list_pointers) {
1974
+
1975
+ if (object_props->is_duplicate)
1976
+ continue;
1977
+
1978
+ lxw_snprintf(target, LXW_FILENAME_LENGTH,
1979
+ "../media/image%d.%s", index++,
1980
+ object_props->extension);
1981
+
1982
+ lxw_add_document_relationship(rels, "/image", target);
1983
+
1984
+ }
1985
+
1986
+ }
1987
+
1988
+ lxw_snprintf(sheetname, LXW_FILENAME_LENGTH,
1989
+ "xl/richData/_rels/richValueRel.xml.rels");
1990
+
1991
+ lxw_relationships_assemble_xml_file(rels);
1992
+
1993
+ err = _add_to_zip(self, rels->file, &buffer, &buffer_size, sheetname);
1994
+
1995
+ fclose(rels->file);
1996
+ free(buffer);
1997
+ lxw_free_relationships(rels);
1998
+
1999
+ return err;
2000
+ }
2001
+
1717
2002
  /*
1718
2003
  * Write the _rels/.rels xml file.
1719
2004
  */
@@ -1770,7 +2055,7 @@ mem_error:
1770
2055
  ****************************************************************************/
1771
2056
 
1772
2057
  STATIC lxw_error
1773
- _add_file_to_zip(lxw_packager *self, FILE * file, const char *filename)
2058
+ _add_file_to_zip(lxw_packager *self, FILE *file, const char *filename)
1774
2059
  {
1775
2060
  int16_t error = ZIP_OK;
1776
2061
  size_t size_read;
@@ -1862,7 +2147,7 @@ _add_buffer_to_zip(lxw_packager *self, const char *buffer, size_t buffer_size,
1862
2147
  }
1863
2148
 
1864
2149
  STATIC lxw_error
1865
- _add_to_zip(lxw_packager *self, FILE * file, char **buffer,
2150
+ _add_to_zip(lxw_packager *self, FILE *file, char **buffer,
1866
2151
  size_t *buffer_size, const char *filename)
1867
2152
  {
1868
2153
  /* Flush to ensure buffer is updated when using a memory-backed file. */
@@ -1953,6 +2238,21 @@ lxw_create_package(lxw_packager *self)
1953
2238
  error = _write_metadata_file(self);
1954
2239
  RETURN_AND_ZIPCLOSE_ON_ERROR(error);
1955
2240
 
2241
+ error = _write_rich_value_file(self);
2242
+ RETURN_AND_ZIPCLOSE_ON_ERROR(error);
2243
+
2244
+ error = _write_rich_value_rel_file(self);
2245
+ RETURN_AND_ZIPCLOSE_ON_ERROR(error);
2246
+
2247
+ error = _write_rich_value_types_file(self);
2248
+ RETURN_AND_ZIPCLOSE_ON_ERROR(error);
2249
+
2250
+ error = _write_rich_value_structure_file(self);
2251
+ RETURN_AND_ZIPCLOSE_ON_ERROR(error);
2252
+
2253
+ error = _write_rich_value_rels_file(self);
2254
+ RETURN_AND_ZIPCLOSE_ON_ERROR(error);
2255
+
1956
2256
  error = _write_app_file(self);
1957
2257
  RETURN_AND_ZIPCLOSE_ON_ERROR(error);
1958
2258
 
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Used in conjunction with the libxlsxwriter library.
5
5
  *
6
- * Copyright 2014-2022, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
6
+ * SPDX-License-Identifier: BSD-2-Clause
7
+ * Copyright 2014-2026, John McNamara, jmcnamara@cpan.org.
7
8
  *
8
9
  */
9
10
 
@@ -243,3 +244,26 @@ lxw_add_worksheet_relationship(lxw_relationships *self, const char *type,
243
244
  {
244
245
  _add_relationship(self, LXW_SCHEMA_DOCUMENT, type, target, target_mode);
245
246
  }
247
+
248
+ /*
249
+ * Add a richValue relationship to sheet .rels xml files.
250
+ */
251
+ void
252
+ lxw_add_rich_value_relationship(lxw_relationships *self)
253
+ {
254
+ _add_relationship(self,
255
+ "http://schemas.microsoft.com/office/2022/10/relationships/",
256
+ "richValueRel", "richData/richValueRel.xml", NULL);
257
+ _add_relationship(self,
258
+ "http://schemas.microsoft.com/office/2017/06/relationships/",
259
+ "rdRichValue", "richData/rdrichvalue.xml", NULL);
260
+ _add_relationship(self,
261
+ "http://schemas.microsoft.com/office/2017/06/relationships/",
262
+ "rdRichValueStructure",
263
+ "richData/rdrichvaluestructure.xml", NULL);
264
+ _add_relationship(self,
265
+ "http://schemas.microsoft.com/office/2017/06/relationships/",
266
+ "rdRichValueTypes", "richData/rdRichValueTypes.xml",
267
+ NULL);
268
+
269
+ }
@@ -0,0 +1,191 @@
1
+ /*****************************************************************************
2
+ * rich_value - A library for creating Excel XLSX rich_value files.
3
+ *
4
+ * Used in conjunction with the libxlsxwriter library.
5
+ *
6
+ * Copyright 2014-2026, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
7
+ *
8
+ */
9
+
10
+ #include "xlsxwriter/xmlwriter.h"
11
+ #include "xlsxwriter/rich_value.h"
12
+ #include "xlsxwriter/utility.h"
13
+
14
+ /*
15
+ * Forward declarations.
16
+ */
17
+
18
+ /*****************************************************************************
19
+ *
20
+ * Private functions.
21
+ *
22
+ ****************************************************************************/
23
+
24
+ /*
25
+ * Create a new rich_value object.
26
+ */
27
+ lxw_rich_value *
28
+ lxw_rich_value_new(void)
29
+ {
30
+ lxw_rich_value *rich_value = calloc(1, sizeof(lxw_rich_value));
31
+ GOTO_LABEL_ON_MEM_ERROR(rich_value, mem_error);
32
+
33
+ return rich_value;
34
+
35
+ mem_error:
36
+ lxw_rich_value_free(rich_value);
37
+ return NULL;
38
+ }
39
+
40
+ /*
41
+ * Free a rich_value object.
42
+ */
43
+ void
44
+ lxw_rich_value_free(lxw_rich_value *rich_value)
45
+ {
46
+ if (!rich_value)
47
+ return;
48
+
49
+ free(rich_value);
50
+ }
51
+
52
+ /*****************************************************************************
53
+ *
54
+ * XML functions.
55
+ *
56
+ ****************************************************************************/
57
+
58
+ /*
59
+ * Write the XML declaration.
60
+ */
61
+ STATIC void
62
+ _rich_value_xml_declaration(lxw_rich_value *self)
63
+ {
64
+ lxw_xml_declaration(self->file);
65
+ }
66
+
67
+ /*****************************************************************************
68
+ *
69
+ * XML file assembly functions.
70
+ *
71
+ ****************************************************************************/
72
+
73
+ /*
74
+ * Write the <v> element.
75
+ */
76
+ STATIC void
77
+ _rich_value_write_v(lxw_rich_value *self, char *value)
78
+ {
79
+ lxw_xml_data_element(self->file, "v", value, NULL);
80
+
81
+ }
82
+
83
+ /*
84
+ * Write the <rv> element.
85
+ */
86
+ STATIC void
87
+ _rich_value_write_rv(lxw_rich_value *self)
88
+ {
89
+ struct xml_attribute_list attributes;
90
+ struct xml_attribute *attribute;
91
+
92
+ LXW_INIT_ATTRIBUTES();
93
+ LXW_PUSH_ATTRIBUTES_STR("s", "0");
94
+
95
+ lxw_xml_start_tag(self->file, "rv", &attributes);
96
+
97
+ LXW_FREE_ATTRIBUTES();
98
+ }
99
+
100
+ /*
101
+ * Write the metadata for each embedded image.
102
+ */
103
+ void
104
+ lxw_rich_value_write_images(lxw_rich_value *self)
105
+ {
106
+
107
+ lxw_workbook *workbook = self->workbook;
108
+ lxw_sheet *sheet;
109
+ lxw_worksheet *worksheet;
110
+ lxw_object_properties *object_props;
111
+ char value[LXW_UINT32_T_LENGTH];
112
+ uint32_t index = 0;
113
+ uint8_t type = 5;
114
+
115
+ STAILQ_FOREACH(sheet, workbook->sheets, list_pointers) {
116
+ if (sheet->is_chartsheet)
117
+ continue;
118
+ else
119
+ worksheet = sheet->u.worksheet;
120
+
121
+ STAILQ_FOREACH(object_props, worksheet->embedded_image_props,
122
+ list_pointers) {
123
+
124
+ if (object_props->is_duplicate)
125
+ continue;
126
+
127
+ if (object_props->decorative)
128
+ type = 6;
129
+
130
+ /* Write the rv element. */
131
+ _rich_value_write_rv(self);
132
+
133
+ /* Write the v element. */
134
+ lxw_snprintf(value, LXW_UINT32_T_LENGTH, "%u", index);
135
+ _rich_value_write_v(self, value);
136
+
137
+ lxw_snprintf(value, LXW_UINT32_T_LENGTH, "%u", type);
138
+ _rich_value_write_v(self, value);
139
+
140
+ if (object_props->description && *object_props->description)
141
+ _rich_value_write_v(self, object_props->description);
142
+
143
+ lxw_xml_end_tag(self->file, "rv");
144
+
145
+ index++;
146
+ }
147
+ }
148
+ }
149
+
150
+ /*
151
+ * Write the <rvData> element.
152
+ */
153
+ STATIC void
154
+ _rich_value_write_rv_data(lxw_rich_value *self)
155
+ {
156
+ struct xml_attribute_list attributes;
157
+ struct xml_attribute *attribute;
158
+ char xmlns[] =
159
+ "http://schemas.microsoft.com/office/spreadsheetml/2017/richdata";
160
+
161
+ LXW_INIT_ATTRIBUTES();
162
+ LXW_PUSH_ATTRIBUTES_STR("xmlns", xmlns);
163
+ LXW_PUSH_ATTRIBUTES_INT("count", self->workbook->num_embedded_images);
164
+
165
+ lxw_xml_start_tag(self->file, "rvData", &attributes);
166
+
167
+ LXW_FREE_ATTRIBUTES();
168
+ }
169
+
170
+ /*
171
+ * Assemble and write the XML file.
172
+ */
173
+ void
174
+ lxw_rich_value_assemble_xml_file(lxw_rich_value *self)
175
+ {
176
+ /* Write the XML declaration. */
177
+ _rich_value_xml_declaration(self);
178
+
179
+ /* Write the rvData element. */
180
+ _rich_value_write_rv_data(self);
181
+
182
+ lxw_rich_value_write_images(self);
183
+
184
+ lxw_xml_end_tag(self->file, "rvData");
185
+ }
186
+
187
+ /*****************************************************************************
188
+ *
189
+ * Public functions.
190
+ *
191
+ ****************************************************************************/