fast_excel 0.2.6 → 0.3.0

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +2 -0
  3. data/.gitignore +3 -0
  4. data/.travis.yml +18 -6
  5. data/CHANGELOG.md +14 -1
  6. data/Dockerfile.test +16 -0
  7. data/Gemfile +1 -1
  8. data/Gemfile.lock +21 -21
  9. data/Makefile +13 -2
  10. data/README.md +148 -38
  11. data/Rakefile +2 -0
  12. data/examples/example.rb +3 -3
  13. data/examples/example_filters.rb +36 -0
  14. data/examples/example_formula.rb +1 -3
  15. data/examples/example_hyperlink.rb +20 -0
  16. data/fast_excel.gemspec +1 -1
  17. data/lib/fast_excel.rb +36 -12
  18. data/lib/fast_excel/binding.rb +31 -21
  19. data/lib/fast_excel/binding/chart.rb +20 -1
  20. data/lib/fast_excel/binding/workbook.rb +10 -2
  21. data/lib/fast_excel/binding/worksheet.rb +44 -27
  22. data/libxlsxwriter/.gitignore +1 -0
  23. data/libxlsxwriter/.indent.pro +5 -0
  24. data/libxlsxwriter/CMakeLists.txt +1 -11
  25. data/libxlsxwriter/CONTRIBUTING.md +1 -1
  26. data/libxlsxwriter/Changes.txt +84 -0
  27. data/libxlsxwriter/LICENSE.txt +1 -1
  28. data/libxlsxwriter/Makefile +7 -5
  29. data/libxlsxwriter/Readme.md +1 -1
  30. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +1 -0
  31. data/libxlsxwriter/include/xlsxwriter.h +2 -2
  32. data/libxlsxwriter/include/xlsxwriter/app.h +2 -2
  33. data/libxlsxwriter/include/xlsxwriter/chart.h +56 -6
  34. data/libxlsxwriter/include/xlsxwriter/chartsheet.h +544 -0
  35. data/libxlsxwriter/include/xlsxwriter/common.h +27 -6
  36. data/libxlsxwriter/include/xlsxwriter/content_types.h +5 -2
  37. data/libxlsxwriter/include/xlsxwriter/core.h +2 -2
  38. data/libxlsxwriter/include/xlsxwriter/custom.h +2 -2
  39. data/libxlsxwriter/include/xlsxwriter/drawing.h +3 -2
  40. data/libxlsxwriter/include/xlsxwriter/format.h +3 -3
  41. data/libxlsxwriter/include/xlsxwriter/hash_table.h +1 -1
  42. data/libxlsxwriter/include/xlsxwriter/packager.h +13 -8
  43. data/libxlsxwriter/include/xlsxwriter/relationships.h +2 -2
  44. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +5 -3
  45. data/libxlsxwriter/include/xlsxwriter/styles.h +9 -4
  46. data/libxlsxwriter/include/xlsxwriter/theme.h +2 -2
  47. data/libxlsxwriter/include/xlsxwriter/utility.h +26 -2
  48. data/libxlsxwriter/include/xlsxwriter/workbook.h +232 -55
  49. data/libxlsxwriter/include/xlsxwriter/worksheet.h +264 -53
  50. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +3 -1
  51. data/libxlsxwriter/libxlsxwriter.podspec +1 -1
  52. data/libxlsxwriter/src/Makefile +3 -3
  53. data/libxlsxwriter/src/app.c +2 -2
  54. data/libxlsxwriter/src/chart.c +41 -5
  55. data/libxlsxwriter/src/chartsheet.c +508 -0
  56. data/libxlsxwriter/src/content_types.c +12 -4
  57. data/libxlsxwriter/src/core.c +2 -2
  58. data/libxlsxwriter/src/custom.c +2 -2
  59. data/libxlsxwriter/src/drawing.c +114 -17
  60. data/libxlsxwriter/src/format.c +3 -3
  61. data/libxlsxwriter/src/hash_table.c +1 -1
  62. data/libxlsxwriter/src/packager.c +369 -65
  63. data/libxlsxwriter/src/relationships.c +2 -2
  64. data/libxlsxwriter/src/shared_strings.c +18 -4
  65. data/libxlsxwriter/src/styles.c +56 -9
  66. data/libxlsxwriter/src/theme.c +2 -2
  67. data/libxlsxwriter/src/utility.c +53 -6
  68. data/libxlsxwriter/src/workbook.c +372 -56
  69. data/libxlsxwriter/src/worksheet.c +425 -76
  70. data/libxlsxwriter/src/xmlwriter.c +17 -8
  71. data/libxlsxwriter/third_party/minizip/ioapi.c +10 -0
  72. data/libxlsxwriter/third_party/minizip/zip.c +2 -0
  73. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +2 -2
  74. data/libxlsxwriter/version.txt +1 -1
  75. data/test/tmpfile_test.rb +1 -0
  76. data/test/validations_test.rb +26 -6
  77. data/test/worksheet_test.rb +43 -0
  78. metadata +9 -6
  79. data/libxlsxwriter/.drone.yml +0 -27
  80. data/libxlsxwriter/appveyor.yml +0 -65
  81. data/libxlsxwriter/cmake/FindZLIB.cmake +0 -123
@@ -20,6 +20,7 @@ TAGS
20
20
  *.bak
21
21
  !test/functional/xlsx_files/*.xlsx
22
22
  *.pyc
23
+ .pytest_cache/
23
24
  .cproject
24
25
  .project
25
26
  .pydevproject
@@ -50,6 +50,7 @@
50
50
  -T lxw_chart
51
51
  -T lxw_chart_axis
52
52
  -T lxw_chart_axis_display_unit
53
+ -T lxw_chart_axis_label_alignment
53
54
  -T lxw_chart_axis_label_position
54
55
  -T lxw_chart_axis_tick_mark
55
56
  -T lxw_chart_axis_tick_position
@@ -77,6 +78,8 @@
77
78
  -T lxw_chart_title
78
79
  -T lxw_chart_trendline_type
79
80
  -T lxw_chart_type
81
+ -T lxw_chartsheet
82
+ -T lxw_chartsheet_name
80
83
  -T lxw_col_options
81
84
  -T lxw_col_t
82
85
  -T lxw_color_t
@@ -110,6 +113,7 @@
110
113
  -T lxw_relationships
111
114
  -T lxw_repeat_cols
112
115
  -T lxw_repeat_rows
116
+ -T lxw_rich_string_tuple
113
117
  -T lxw_row
114
118
  -T lxw_row_col_options
115
119
  -T lxw_row_t
@@ -117,6 +121,7 @@
117
121
  -T lxw_series_data_point
118
122
  -T lxw_series_error_bars
119
123
  -T lxw_series_range
124
+ -T lxw_sheet
120
125
  -T lxw_sst
121
126
  -T lxw_styles
122
127
  -T lxw_theme
@@ -216,16 +216,6 @@ target_include_directories(${PROJECT_NAME}
216
216
  PUBLIC include include/xlsxwriter
217
217
  )
218
218
 
219
- if(MSVC)
220
- if (NOT BUILD_SHARED_LIBS)
221
- add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
222
- COMMAND ${CMAKE_COMMAND} -E rename
223
- ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb
224
- $<TARGET_FILE_DIR:${PROJECT_NAME}>/${PROJECT_NAME}.pdb
225
- )
226
- endif()
227
- endif()
228
-
229
219
  # TESTS
230
220
  # -----
231
221
 
@@ -329,7 +319,7 @@ if(MSVC)
329
319
  RUNTIME DESTINATION "bin/${MSVC_FOLDER_PREFIX}/\${CMAKE_INSTALL_CONFIG_NAME}"
330
320
  )
331
321
  if (NOT BUILD_SHARED_LIBS)
332
- install(FILES $<TARGET_FILE_DIR:${PROJECT_NAME}>/${PROJECT_NAME}.pdb
322
+ install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb
333
323
  DESTINATION "lib/${MSVC_FOLDER_PREFIX}/\${CMAKE_INSTALL_CONFIG_NAME}"
334
324
  )
335
325
  endif()
@@ -24,7 +24,7 @@ the `xlsxwriter.h` header file or by adding the following to your program:
24
24
 
25
25
  int main() {
26
26
 
27
- printf("Libxlsxwriter version = %s\n", LXW_VERSION);
27
+ printf("Libxlsxwriter version = %s\n", lxw_version());
28
28
 
29
29
  return 0;
30
30
  }
@@ -1,6 +1,90 @@
1
1
  /**
2
2
  @page changes Changes
3
3
 
4
+ ## 0.8.6 April 7 2019
5
+
6
+ - Fixed issue where images that started in hidden rows/columns weren't placed
7
+ correctly in the worksheet.
8
+
9
+ - Fixed the mime-type reported by system `file(1)`. The mime-type reported
10
+ by "file --mime-type"/magic was incorrect for XlsxWriter files since it
11
+ expected the `[Content_types]` to be the first file in the zip container.
12
+
13
+
14
+ ## 0.8.5 February 10 2019
15
+
16
+ - Fix compile-time warnings with strict prototypes enabled.
17
+ Issue [#208][gh_208].
18
+
19
+ [gh_208]: https://github.com/jmcnamara/libxlsxwriter/issues/208
20
+
21
+ - Make py.test name configurable.
22
+ Pull request [#206][gh_206].
23
+
24
+ [gh_206]: https://github.com/jmcnamara/libxlsxwriter/pull/206
25
+
26
+
27
+ ## 0.8.4 November 10 2018
28
+
29
+ - Fix for issue when hashing number formats.
30
+ Issue [#203][gh_203].
31
+
32
+ [gh_203]: https://github.com/jmcnamara/libxlsxwriter/issues/203
33
+
34
+
35
+ ## 0.8.3 October 1 2018
36
+
37
+ - Added `worksheet_write_rich_string()` function to allow writing of
38
+ multi-format rich strings. See @ref rich_strings.c
39
+ Feature request [#37][gh_37].
40
+
41
+ [gh_37]: https://github.com/jmcnamara/libxlsxwriter/issues/37
42
+
43
+
44
+ ## 0.8.2 September 16 2018
45
+
46
+ - Added new chartsheet functionality: `chartsheet_set_tab_color()`, and
47
+ `chartsheet_set_zoom()`.
48
+
49
+
50
+ ## 0.8.1 September 15 2018
51
+
52
+ - Fix for chartsheet and worksheet ordering issue.
53
+
54
+ - Added new chartsheet functionality: `chartsheet_protect()`,
55
+ `chartsheet_hide()`, `chartsheet_select()` and
56
+ `chartsheet_set_first_sheet()`.
57
+
58
+
59
+ ## 0.8.0 September 12 2018
60
+
61
+ - Added chartsheet support. A chartsheet is a type of worksheet that only
62
+ contains a chart. See the @ref chartsheet.h "Chartsheet" object and @ref
63
+ chartsheet.c.
64
+
65
+
66
+ ## 0.7.9 September 1 2018
67
+
68
+ - Added `chart_axis_set_label_align()` function to set the alignment of chart
69
+ category axis labels.
70
+ Feature request [#186][gh_186].
71
+
72
+ [gh_186]: https://github.com/jmcnamara/libxlsxwriter/issues/186
73
+
74
+ - Added `lxw_version()` function to get the library version.
75
+ Feature request [#194][gh_194].
76
+
77
+ [gh_194]: https://github.com/jmcnamara/libxlsxwriter/pull/194
78
+
79
+
80
+ ## 0.7.8 August 30 2018
81
+
82
+ - Added `worksheet_insert_image_buffer()` function to insert images from
83
+ memory buffers. See @ref image_buffer.c.
84
+ Feature request [#125][gh_125].
85
+
86
+ [gh_125]: https://github.com/jmcnamara/libxlsxwriter/issues/125
87
+
4
88
 
5
89
  ## 0.7.7 May 16 2018
6
90
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  Libxlsxwriter is released under a FreeBSD license:
6
6
 
7
- Copyright 2014-2018, John McNamara <jmcnamara@cpan.org>
7
+ Copyright 2014-2019, John McNamara <jmcnamara@cpan.org>
8
8
  All rights reserved.
9
9
 
10
10
  Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Makefile for libxlsxwriter library.
4
4
  #
5
- # Copyright 2014-2018, John McNamara, jmcnamara@cpan.org
5
+ # Copyright 2014-2019, John McNamara, jmcnamara@cpan.org
6
6
  #
7
7
 
8
8
  # Keep the output quiet by default.
@@ -13,6 +13,8 @@ endif
13
13
 
14
14
  INSTALL_DIR ?= /usr/local
15
15
 
16
+ PYTEST ?= py.test
17
+
16
18
  .PHONY: docs tags examples
17
19
 
18
20
  # Build the libs.
@@ -32,9 +34,9 @@ examples :
32
34
  # Clean src and test directories.
33
35
  clean :
34
36
  $(Q)$(MAKE) clean -C src
35
- $(Q)$(MAKE) clean -C test/unit
36
- $(Q)$(MAKE) clean -C test/functional/src
37
- $(Q)$(MAKE) clean -C examples
37
+ # $(Q)$(MAKE) clean -C test/unit
38
+ # $(Q)$(MAKE) clean -C test/functional/src
39
+ # $(Q)$(MAKE) clean -C examples
38
40
  $(Q)rm -rf docs/html
39
41
  $(Q)rm -rf test/functional/__pycache__
40
42
  $(Q)rm -f test/functional/*.pyc
@@ -58,7 +60,7 @@ test_const : all
58
60
  # Run the functional tests.
59
61
  test_functional : all
60
62
  $(Q)$(MAKE) -C test/functional/src
61
- $(Q)py.test test/functional -v
63
+ $(Q)$(PYTEST) test/functional -v
62
64
 
63
65
  # Run all tests.
64
66
  test_unit :
@@ -59,7 +59,7 @@ int main() {
59
59
  /* Text with formatting. */
60
60
  worksheet_write_string(worksheet, 1, 0, "World", format);
61
61
 
62
- /* Writer some numbers. */
62
+ /* Write some numbers. */
63
63
  worksheet_write_number(worksheet, 2, 0, 123, NULL);
64
64
  worksheet_write_number(worksheet, 3, 0, 123.456, NULL);
65
65
 
@@ -3,6 +3,7 @@
3
3
  #import "../xlsxwriter.h"
4
4
  #import "app.h"
5
5
  #import "chart.h"
6
+ #import "chartsheet.h"
6
7
  #import "common.h"
7
8
  #import "content_types.h"
8
9
  #import "core.h"
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libxlsxwriter
3
3
  *
4
- * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
4
+ * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5
5
  */
6
6
 
7
7
  /**
@@ -18,6 +18,6 @@
18
18
  #include "xlsxwriter/format.h"
19
19
  #include "xlsxwriter/utility.h"
20
20
 
21
- #define LXW_VERSION "0.7.7"
21
+ #define LXW_VERSION "0.8.6"
22
22
 
23
23
  #endif /* __LXW_XLSXWRITER_H__ */
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libxlsxwriter
3
3
  *
4
- * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
4
+ * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5
5
  *
6
6
  * app - A libxlsxwriter library for creating Excel XLSX app files.
7
7
  *
@@ -56,7 +56,7 @@ extern "C" {
56
56
  #endif
57
57
  /* *INDENT-ON* */
58
58
 
59
- lxw_app *lxw_app_new();
59
+ lxw_app *lxw_app_new(void);
60
60
  void lxw_app_free(lxw_app *app);
61
61
  void lxw_app_assemble_xml_file(lxw_app *self);
62
62
  void lxw_app_add_part_name(lxw_app *self, const char *name);
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libxlsxwriter
3
3
  *
4
- * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
4
+ * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5
5
  *
6
6
  * chart - A libxlsxwriter library for creating Excel XLSX chart files.
7
7
  *
@@ -172,11 +172,17 @@ typedef enum lxw_chart_legend_position {
172
172
  /** Chart legend positioned at bottom. */
173
173
  LXW_CHART_LEGEND_BOTTOM,
174
174
 
175
+ /** Chart legend positioned at top right. */
176
+ LXW_CHART_LEGEND_TOP_RIGHT,
177
+
175
178
  /** Chart legend overlaid at right side. */
176
179
  LXW_CHART_LEGEND_OVERLAY_RIGHT,
177
180
 
178
181
  /** Chart legend overlaid at left side. */
179
- LXW_CHART_LEGEND_OVERLAY_LEFT
182
+ LXW_CHART_LEGEND_OVERLAY_LEFT,
183
+
184
+ /** Chart legend overlaid at top right. */
185
+ LXW_CHART_LEGEND_OVERLAY_TOP_RIGHT
180
186
  } lxw_chart_legend_position;
181
187
 
182
188
  /**
@@ -523,6 +529,20 @@ typedef enum lxw_chart_axis_label_position {
523
529
  LXW_CHART_AXIS_LABEL_POSITION_NONE
524
530
  } lxw_chart_axis_label_position;
525
531
 
532
+ /**
533
+ * @brief Axis label alignments.
534
+ */
535
+ typedef enum lxw_chart_axis_label_alignment {
536
+ /** Chart axis label alignment: center. */
537
+ LXW_CHART_AXIS_LABEL_ALIGN_CENTER,
538
+
539
+ /** Chart axis label alignment: left. */
540
+ LXW_CHART_AXIS_LABEL_ALIGN_LEFT,
541
+
542
+ /** Chart axis label alignment: right. */
543
+ LXW_CHART_AXIS_LABEL_ALIGN_RIGHT
544
+ } lxw_chart_axis_label_alignment;
545
+
526
546
  /**
527
547
  * @brief Display units for chart value axis.
528
548
  */
@@ -981,6 +1001,7 @@ typedef struct lxw_chart_axis {
981
1001
  uint8_t axis_position;
982
1002
  uint8_t position_axis;
983
1003
  uint8_t label_position;
1004
+ uint8_t label_align;
984
1005
  uint8_t hidden;
985
1006
  uint8_t reverse;
986
1007
 
@@ -1048,6 +1069,7 @@ typedef struct lxw_chart {
1048
1069
  uint8_t in_use;
1049
1070
  uint8_t chart_group;
1050
1071
  uint8_t cat_has_num_fmt;
1072
+ uint8_t is_chartsheet;
1051
1073
 
1052
1074
  uint8_t has_horiz_cat_axis;
1053
1075
  uint8_t has_horiz_val_axis;
@@ -1103,6 +1125,7 @@ typedef struct lxw_chart {
1103
1125
  lxw_chart_fill *down_bar_fill;
1104
1126
 
1105
1127
  uint8_t default_label_position;
1128
+ uint8_t is_protected;
1106
1129
 
1107
1130
  STAILQ_ENTRY (lxw_chart) ordered_list_pointers;
1108
1131
  STAILQ_ENTRY (lxw_chart) list_pointers;
@@ -1284,7 +1307,7 @@ void chart_series_set_values(lxw_chart_series *series, const char *sheetname,
1284
1307
  * @code
1285
1308
  * lxw_chart_series *series = chart_add_series(chart, NULL, "=Sheet1!$B$2:$B$7");
1286
1309
  *
1287
- * chart_series_set_name(series, "=Sheet1!$B1$1");
1310
+ * chart_series_set_name(series, "=Sheet1!$B$1");
1288
1311
  * @endcode
1289
1312
  *
1290
1313
  * See also the `chart_series_set_name_range()` function to see how to set the
@@ -2275,7 +2298,7 @@ lxw_chart_axis *chart_axis_get(lxw_chart *chart,
2275
2298
  * a cell in the workbook that contains the name:
2276
2299
  *
2277
2300
  * @code
2278
- * chart_axis_set_name(chart->x_axis, "=Sheet1!$B1$1");
2301
+ * chart_axis_set_name(chart->x_axis, "=Sheet1!$B$1");
2279
2302
  * @endcode
2280
2303
  *
2281
2304
  * See also the `chart_axis_set_name_range()` function to see how to set the
@@ -2567,7 +2590,7 @@ void chart_axis_set_position(lxw_chart_axis *axis, uint8_t position);
2567
2590
  *
2568
2591
  * @code
2569
2592
  * chart_axis_set_label_position(chart->x_axis, LXW_CHART_AXIS_LABEL_POSITION_HIGH);
2570
- chart_axis_set_label_position(chart->y_axis, LXW_CHART_AXIS_LABEL_POSITION_HIGH);
2593
+ * chart_axis_set_label_position(chart->y_axis, LXW_CHART_AXIS_LABEL_POSITION_HIGH);
2571
2594
  * @endcode
2572
2595
  *
2573
2596
  * @image html chart_label_position2.png
@@ -2590,6 +2613,31 @@ void chart_axis_set_position(lxw_chart_axis *axis, uint8_t position);
2590
2613
  */
2591
2614
  void chart_axis_set_label_position(lxw_chart_axis *axis, uint8_t position);
2592
2615
 
2616
+ /**
2617
+ * @brief Set the alignment of the axis labels.
2618
+ *
2619
+ * @param axis A pointer to a chart #lxw_chart_axis object.
2620
+ * @param align A #lxw_chart_axis_label_alignment value.
2621
+ *
2622
+ * Position the category axis labels for the chart. The labels are the
2623
+ * numbers, or strings or dates, on the axis that indicate the categories
2624
+ * of the axis.
2625
+ *
2626
+ * The allowable values:
2627
+ *
2628
+ * - #LXW_CHART_AXIS_LABEL_ALIGN_CENTER - Align label center (default).
2629
+ * - #LXW_CHART_AXIS_LABEL_ALIGN_LEFT - Align label left.
2630
+ * - #LXW_CHART_AXIS_LABEL_ALIGN_RIGHT - Align label right.
2631
+ *
2632
+ * @code
2633
+ * chart_axis_set_label_align(chart->x_axis, LXW_CHART_AXIS_LABEL_ALIGN_RIGHT);
2634
+ * @endcode
2635
+ *
2636
+ * **Axis types**: This function is applicable to category axes only.
2637
+ * See @ref ww_charts_axes.
2638
+ */
2639
+ void chart_axis_set_label_align(lxw_chart_axis *axis, uint8_t align);
2640
+
2593
2641
  /**
2594
2642
  * @brief Set the minimum value for a chart axis.
2595
2643
  *
@@ -2958,7 +3006,7 @@ void chart_axis_minor_gridlines_set_line(lxw_chart_axis *axis,
2958
3006
  * a cell in the workbook that contains the name:
2959
3007
  *
2960
3008
  * @code
2961
- * chart_title_set_name(chart, "=Sheet1!$B1$1");
3009
+ * chart_title_set_name(chart, "=Sheet1!$B$1");
2962
3010
  * @endcode
2963
3011
  *
2964
3012
  * See also the `chart_title_set_name_range()` function to see how to set the
@@ -3040,8 +3088,10 @@ void chart_title_off(lxw_chart *chart);
3040
3088
  * LXW_CHART_LEGEND_LEFT
3041
3089
  * LXW_CHART_LEGEND_TOP
3042
3090
  * LXW_CHART_LEGEND_BOTTOM
3091
+ * LXW_CHART_LEGEND_TOP_RIGHT
3043
3092
  * LXW_CHART_LEGEND_OVERLAY_RIGHT
3044
3093
  * LXW_CHART_LEGEND_OVERLAY_LEFT
3094
+ * LXW_CHART_LEGEND_OVERLAY_TOP_RIGHT
3045
3095
  *
3046
3096
  * For example:
3047
3097
  *
@@ -0,0 +1,544 @@
1
+ /*
2
+ * libxlsxwriter
3
+ *
4
+ * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5
+ *
6
+ * chartsheet - A libxlsxwriter library for creating Excel XLSX chartsheet files.
7
+ *
8
+ */
9
+
10
+ /**
11
+ * @page chartsheet_page The Chartsheet object
12
+ *
13
+ * The Chartsheet object represents an Excel chartsheet, which is a type of
14
+ * worksheet that only contains a chart. The Chartsheet object handles
15
+ * operations such as adding a chart and setting the page layout.
16
+ *
17
+ * See @ref chartsheet.h for full details of the functionality.
18
+ *
19
+ * @file chartsheet.h
20
+ *
21
+ * @brief Functions related to adding data and formatting to a chartsheet.
22
+ *
23
+ * The Chartsheet object represents an Excel chartsheet. It handles operations
24
+ * such as adding a chart and setting the page layout.
25
+ *
26
+ * A Chartsheet object isn't created directly. Instead a chartsheet is created
27
+ * by calling the workbook_add_chartsheet() function from a Workbook object. A
28
+ * chartsheet object functions as a worksheet and not as a chart. In order to
29
+ * have it display data a #lxw_chart object must be created and added to the
30
+ * chartsheet:
31
+ *
32
+ * @code
33
+ * #include "xlsxwriter.h"
34
+ *
35
+ * int main() {
36
+ *
37
+ * lxw_workbook *workbook = new_workbook("chartsheet.xlsx");
38
+ * lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
39
+ * lxw_chartsheet *chartsheet = workbook_add_chartsheet(workbook, NULL);
40
+ * lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);
41
+ *
42
+ * //... Set up the chart.
43
+ *
44
+ * // Add the chart to the chartsheet.
45
+ * return workbook_close(workbook);
46
+ *
47
+ * }
48
+ * @endcode
49
+ *
50
+ * @image html chartsheet.png
51
+ *
52
+ * The data for the chartsheet chart must be contained on a separate
53
+ * worksheet. That is why it is always created in conjunction with at least
54
+ * one data worksheet, as shown above.
55
+ */
56
+
57
+ #ifndef __LXW_CHARTSHEET_H__
58
+ #define __LXW_CHARTSHEET_H__
59
+
60
+ #include <stdint.h>
61
+
62
+ #include "common.h"
63
+ #include "worksheet.h"
64
+ #include "drawing.h"
65
+ #include "utility.h"
66
+
67
+ /**
68
+ * @brief Struct to represent an Excel chartsheet.
69
+ *
70
+ * The members of the lxw_chartsheet struct aren't modified directly. Instead
71
+ * the chartsheet properties are set by calling the functions shown in
72
+ * chartsheet.h.
73
+ */
74
+ typedef struct lxw_chartsheet {
75
+
76
+ FILE *file;
77
+ lxw_worksheet *worksheet;
78
+ lxw_chart *chart;
79
+
80
+ struct lxw_protection protection;
81
+ uint8_t is_protected;
82
+
83
+ char *name;
84
+ char *quoted_name;
85
+ char *tmpdir;
86
+ uint32_t index;
87
+ uint8_t active;
88
+ uint8_t selected;
89
+ uint8_t hidden;
90
+ uint16_t *active_sheet;
91
+ uint16_t *first_sheet;
92
+ uint16_t rel_count;
93
+
94
+ STAILQ_ENTRY (lxw_chartsheet) list_pointers;
95
+
96
+ } lxw_chartsheet;
97
+
98
+
99
+ /* *INDENT-OFF* */
100
+ #ifdef __cplusplus
101
+ extern "C" {
102
+ #endif
103
+ /* *INDENT-ON* */
104
+
105
+ /**
106
+ * @brief Insert a chart object into a chartsheet.
107
+ *
108
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
109
+ * @param chart A #lxw_chart object created via workbook_add_chart().
110
+ *
111
+ * @return A #lxw_error code.
112
+ *
113
+ * The `%chartsheet_set_chart()` function can be used to insert a chart into a
114
+ * chartsheet. The chart object must be created first using the
115
+ * `workbook_add_chart()` function and configured using the @ref chart.h
116
+ * functions.
117
+ *
118
+ * @code
119
+ * // Create the chartsheet.
120
+ * lxw_chartsheet *chartsheet = workbook_add_chartsheet(workbook, NULL);
121
+ *
122
+ * // Create a chart object.
123
+ * lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
124
+ *
125
+ * // Add a data series to the chart.
126
+ * chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$6");
127
+ *
128
+ * // Insert the chart into the chartsheet.
129
+ * chartsheet_set_chart(chartsheet, chart);
130
+ * @endcode
131
+ *
132
+ * @image html chartsheet2.png
133
+ *
134
+ * **Note:**
135
+ *
136
+ * A chart may only be inserted once into a chartsheet or a worksheet. If
137
+ * several similar charts are required then each one must be created
138
+ * separately.
139
+ *
140
+ */
141
+ lxw_error chartsheet_set_chart(lxw_chartsheet *chartsheet, lxw_chart *chart);
142
+
143
+ /* Not currently required since scale options aren't useful in a chartsheet. */
144
+ lxw_error chartsheet_set_chart_opt(lxw_chartsheet *chartsheet,
145
+ lxw_chart *chart,
146
+ lxw_image_options *user_options);
147
+
148
+ /**
149
+ * @brief Make a chartsheet the active, i.e., visible chartsheet.
150
+ *
151
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
152
+ *
153
+ * The `%chartsheet_activate()` function is used to specify which chartsheet
154
+ * is initially visible in a multi-sheet workbook:
155
+ *
156
+ * @code
157
+ * lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
158
+ * lxw_chartsheet *chartsheet1 = workbook_add_chartsheet(workbook, NULL);
159
+ * lxw_chartsheet *chartsheet2 = workbook_add_chartsheet(workbook, NULL);
160
+ * lxw_chartsheet *chartsheet3 = workbook_add_chartsheet(workbook, NULL);
161
+ *
162
+ * chartsheet_activate(chartsheet3);
163
+ * @endcode
164
+ *
165
+ * @image html chartsheet_activate.png
166
+ *
167
+ * More than one chartsheet can be selected via the `chartsheet_select()`
168
+ * function, see below, however only one chartsheet can be active.
169
+ *
170
+ * The default active chartsheet is the first chartsheet.
171
+ *
172
+ * See also `worksheet_activate()`.
173
+ *
174
+ */
175
+ void chartsheet_activate(lxw_chartsheet *chartsheet);
176
+
177
+ /**
178
+ * @brief Set a chartsheet tab as selected.
179
+ *
180
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
181
+ *
182
+ * The `%chartsheet_select()` function is used to indicate that a chartsheet
183
+ * is selected in a multi-sheet workbook:
184
+ *
185
+ * @code
186
+ * chartsheet_activate(chartsheet1);
187
+ * chartsheet_select(chartsheet2);
188
+ * chartsheet_select(chartsheet3);
189
+ *
190
+ * @endcode
191
+ *
192
+ * A selected chartsheet has its tab highlighted. Selecting chartsheets is a
193
+ * way of grouping them together so that, for example, several chartsheets
194
+ * could be printed in one go. A chartsheet that has been activated via the
195
+ * `chartsheet_activate()` function will also appear as selected.
196
+ *
197
+ * See also `worksheet_select()`.
198
+ *
199
+ */
200
+ void chartsheet_select(lxw_chartsheet *chartsheet);
201
+
202
+ /**
203
+ * @brief Hide the current chartsheet.
204
+ *
205
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
206
+ *
207
+ * The `%chartsheet_hide()` function is used to hide a chartsheet:
208
+ *
209
+ * @code
210
+ * chartsheet_hide(chartsheet2);
211
+ * @endcode
212
+ *
213
+ * You may wish to hide a chartsheet in order to avoid confusing a user with
214
+ * intermediate data or calculations.
215
+ *
216
+ * @image html hide_sheet.png
217
+ *
218
+ * A hidden chartsheet can not be activated or selected so this function is
219
+ * mutually exclusive with the `chartsheet_activate()` and
220
+ * `chartsheet_select()` functions. In addition, since the first chartsheet
221
+ * will default to being the active chartsheet, you cannot hide the first
222
+ * chartsheet without activating another sheet:
223
+ *
224
+ * @code
225
+ * chartsheet_activate(chartsheet2);
226
+ * chartsheet_hide(chartsheet1);
227
+ * @endcode
228
+ *
229
+ * See also `worksheet_hide()`.
230
+ *
231
+ */
232
+ void chartsheet_hide(lxw_chartsheet *chartsheet);
233
+
234
+ /**
235
+ * @brief Set current chartsheet as the first visible sheet tab.
236
+ *
237
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
238
+ *
239
+ * The `chartsheet_activate()` function determines which chartsheet is
240
+ * initially selected. However, if there are a large number of chartsheets the
241
+ * selected chartsheet may not appear on the screen. To avoid this you can
242
+ * select the leftmost visible chartsheet tab using
243
+ * `%chartsheet_set_first_sheet()`:
244
+ *
245
+ * @code
246
+ * chartsheet_set_first_sheet(chartsheet19); // First visible chartsheet tab.
247
+ * chartsheet_activate(chartsheet20); // First visible chartsheet.
248
+ * @endcode
249
+ *
250
+ * This function is not required very often. The default value is the first
251
+ * chartsheet.
252
+ *
253
+ * See also `worksheet_set_first_sheet()`.
254
+ *
255
+ */
256
+ void chartsheet_set_first_sheet(lxw_chartsheet *chartsheet);
257
+
258
+ /**
259
+ * @brief Set the color of the chartsheet tab.
260
+ *
261
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
262
+ * @param color The tab color.
263
+ *
264
+ * The `%chartsheet_set_tab_color()` function is used to change the color of
265
+ * the chartsheet tab:
266
+ *
267
+ * @code
268
+ * chartsheet_set_tab_color(chartsheet1, LXW_COLOR_RED);
269
+ * chartsheet_set_tab_color(chartsheet2, LXW_COLOR_GREEN);
270
+ * chartsheet_set_tab_color(chartsheet3, 0xFF9900); // Orange.
271
+ * @endcode
272
+ *
273
+ * The color should be an RGB integer value, see @ref working_with_colors.
274
+ *
275
+ * See also `worksheet_set_tab_color()`.
276
+ */
277
+ void chartsheet_set_tab_color(lxw_chartsheet *chartsheet, lxw_color_t color);
278
+
279
+ /**
280
+ * @brief Protect elements of a chartsheet from modification.
281
+ *
282
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
283
+ * @param password A chartsheet password.
284
+ * @param options Chartsheet elements to protect.
285
+ *
286
+ * The `%chartsheet_protect()` function protects chartsheet elements from
287
+ * modification:
288
+ *
289
+ * @code
290
+ * chartsheet_protect(chartsheet, "Some Password", options);
291
+ * @endcode
292
+ *
293
+ * The `password` and lxw_protection pointer are both optional:
294
+ *
295
+ * @code
296
+ * chartsheet_protect(chartsheet2, NULL, my_options);
297
+ * chartsheet_protect(chartsheet3, "password", NULL);
298
+ * chartsheet_protect(chartsheet4, "password", my_options);
299
+ * @endcode
300
+ *
301
+ * Passing a `NULL` password is the same as turning on protection without a
302
+ * password. Passing a `NULL` password and `NULL` options had no effect on
303
+ * chartsheets.
304
+ *
305
+ * You can specify which chartsheet elements you wish to protect by passing a
306
+ * lxw_protection pointer in the `options` argument. In Excel chartsheets only
307
+ * have two protection options:
308
+ *
309
+ * no_content
310
+ * no_objects
311
+ *
312
+ * All parameters are off by default. Individual elements can be protected as
313
+ * follows:
314
+ *
315
+ * @code
316
+ * lxw_protection options = {
317
+ * .no_content = 1,
318
+ * .no_objects = 1,
319
+ * };
320
+ *
321
+ * chartsheet_protect(chartsheet, NULL, &options);
322
+ *
323
+ * @endcode
324
+ *
325
+ * See also worksheet_protect().
326
+ *
327
+ * **Note:** Sheet level passwords in Excel offer **very** weak
328
+ * protection. They don't encrypt your data and are very easy to
329
+ * deactivate. Full workbook encryption is not supported by `libxlsxwriter`
330
+ * since it requires a completely different file format.
331
+ */
332
+ void chartsheet_protect(lxw_chartsheet *chartsheet, const char *password,
333
+ lxw_protection *options);
334
+
335
+ /**
336
+ * @brief Set the chartsheet zoom factor.
337
+ *
338
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
339
+ * @param scale Chartsheet zoom factor.
340
+ *
341
+ * Set the chartsheet zoom factor in the range `10 <= zoom <= 400`:
342
+ *
343
+ * @code
344
+ * chartsheet_set_zoom(chartsheet, 75);
345
+ * @endcode
346
+ *
347
+ * The default zoom factor is 100. It isn't possible to set the zoom to
348
+ * "Selection" because it is calculated by Excel at run-time.
349
+ *
350
+ * See also `worksheet_set_zoom()`.
351
+ */
352
+ void chartsheet_set_zoom(lxw_chartsheet *chartsheet, uint16_t scale);
353
+
354
+ /**
355
+ * @brief Set the page orientation as landscape.
356
+ *
357
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
358
+ *
359
+ * This function is used to set the orientation of a chartsheet's printed page
360
+ * to landscape. The default chartsheet orientation is landscape, so this
361
+ * function isn't generally required:
362
+ *
363
+ * @code
364
+ * chartsheet_set_landscape(chartsheet);
365
+ * @endcode
366
+ */
367
+ void chartsheet_set_landscape(lxw_chartsheet *chartsheet);
368
+
369
+ /**
370
+ * @brief Set the page orientation as portrait.
371
+ *
372
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
373
+ *
374
+ * This function is used to set the orientation of a chartsheet's printed page
375
+ * to portrait:
376
+ *
377
+ * @code
378
+ * chartsheet_set_portrait(chartsheet);
379
+ * @endcode
380
+ */
381
+ void chartsheet_set_portrait(lxw_chartsheet *chartsheet);
382
+
383
+ /**
384
+ * @brief Set the paper type for printing.
385
+ *
386
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
387
+ * @param paper_type The Excel paper format type.
388
+ *
389
+ * This function is used to set the paper format for the printed output of a
390
+ * chartsheet:
391
+ *
392
+ * @code
393
+ * chartsheet_set_paper(chartsheet1, 1); // US Letter
394
+ * chartsheet_set_paper(chartsheet2, 9); // A4
395
+ * @endcode
396
+ *
397
+ * If you do not specify a paper type the chartsheet will print using the
398
+ * printer's default paper style.
399
+ *
400
+ * See `worksheet_set_paper()` for a full list of available paper sizes.
401
+ */
402
+ void chartsheet_set_paper(lxw_chartsheet *chartsheet, uint8_t paper_type);
403
+
404
+ /**
405
+ * @brief Set the chartsheet margins for the printed page.
406
+ *
407
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
408
+ * @param left Left margin in inches. Excel default is 0.7.
409
+ * @param right Right margin in inches. Excel default is 0.7.
410
+ * @param top Top margin in inches. Excel default is 0.75.
411
+ * @param bottom Bottom margin in inches. Excel default is 0.75.
412
+ *
413
+ * The `%chartsheet_set_margins()` function is used to set the margins of the
414
+ * chartsheet when it is printed. The units are in inches. Specifying `-1` for
415
+ * any parameter will give the default Excel value as shown above.
416
+ *
417
+ * @code
418
+ * chartsheet_set_margins(chartsheet, 1.3, 1.2, -1, -1);
419
+ * @endcode
420
+ *
421
+ */
422
+ void chartsheet_set_margins(lxw_chartsheet *chartsheet, double left,
423
+ double right, double top, double bottom);
424
+
425
+ /**
426
+ * @brief Set the printed page header caption.
427
+ *
428
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
429
+ * @param string The header string.
430
+ *
431
+ * @return A #lxw_error code.
432
+ *
433
+ * Headers and footers are generated using a string which is a combination of
434
+ * plain text and control characters
435
+ *
436
+ * @code
437
+ * chartsheet_set_header(chartsheet, "&LHello");
438
+ *
439
+ * // ---------------------------------------------------------------
440
+ * // | |
441
+ * // | Hello |
442
+ * // | |
443
+ *
444
+ *
445
+ * chartsheet_set_header(chartsheet, "&CHello");
446
+ *
447
+ * // ---------------------------------------------------------------
448
+ * // | |
449
+ * // | Hello |
450
+ * // | |
451
+ *
452
+ *
453
+ * chartsheet_set_header(chartsheet, "&RHello");
454
+ *
455
+ * // ---------------------------------------------------------------
456
+ * // | |
457
+ * // | Hello |
458
+ * // | |
459
+ *
460
+ *
461
+ * @endcode
462
+ *
463
+ * See `worksheet_set_header()` for a full explanation of the syntax of
464
+ * Excel's header formatting and control characters.
465
+ *
466
+ */
467
+ lxw_error chartsheet_set_header(lxw_chartsheet *chartsheet,
468
+ const char *string);
469
+
470
+ /**
471
+ * @brief Set the printed page footer caption.
472
+ *
473
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
474
+ * @param string The footer string.
475
+ *
476
+ * @return A #lxw_error code.
477
+ *
478
+ * The syntax of this function is the same as chartsheet_set_header().
479
+ *
480
+ */
481
+ lxw_error chartsheet_set_footer(lxw_chartsheet *chartsheet,
482
+ const char *string);
483
+
484
+ /**
485
+ * @brief Set the printed page header caption with additional options.
486
+ *
487
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
488
+ * @param string The header string.
489
+ * @param options Header options.
490
+ *
491
+ * @return A #lxw_error code.
492
+ *
493
+ * The syntax of this function is the same as chartsheet_set_header() with an
494
+ * additional parameter to specify options for the header.
495
+ *
496
+ * Currently, the only available option is the header margin:
497
+ *
498
+ * @code
499
+ *
500
+ * lxw_header_footer_options header_options = { 0.2 };
501
+ *
502
+ * chartsheet_set_header_opt(chartsheet, "Some text", &header_options);
503
+ *
504
+ * @endcode
505
+ *
506
+ */
507
+ lxw_error chartsheet_set_header_opt(lxw_chartsheet *chartsheet,
508
+ const char *string,
509
+ lxw_header_footer_options *options);
510
+
511
+ /**
512
+ * @brief Set the printed page footer caption with additional options.
513
+ *
514
+ * @param chartsheet Pointer to a lxw_chartsheet instance to be updated.
515
+ * @param string The footer string.
516
+ * @param options Footer options.
517
+ *
518
+ * @return A #lxw_error code.
519
+ *
520
+ * The syntax of this function is the same as chartsheet_set_header_opt().
521
+ *
522
+ */
523
+ lxw_error chartsheet_set_footer_opt(lxw_chartsheet *chartsheet,
524
+ const char *string,
525
+ lxw_header_footer_options *options);
526
+
527
+ lxw_chartsheet *lxw_chartsheet_new(lxw_worksheet_init_data *init_data);
528
+ void lxw_chartsheet_free(lxw_chartsheet *chartsheet);
529
+ void lxw_chartsheet_assemble_xml_file(lxw_chartsheet *chartsheet);
530
+
531
+ /* Declarations required for unit testing. */
532
+ #ifdef TESTING
533
+
534
+ STATIC void _chartsheet_xml_declaration(lxw_chartsheet *chartsheet);
535
+ STATIC void _chartsheet_write_sheet_protection(lxw_chartsheet *chartsheet);
536
+ #endif /* TESTING */
537
+
538
+ /* *INDENT-OFF* */
539
+ #ifdef __cplusplus
540
+ }
541
+ #endif
542
+ /* *INDENT-ON* */
543
+
544
+ #endif /* __LXW_CHARTSHEET_H__ */