1 /*
2 * Tests for the libxlsxwriter library.
3 *
4 * Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
5 *
6 */
7
8 #include "../ctest.h"
9 #include "../helper.h"
10
11 #include "../../../include/xlsxwriter/worksheet.h"
12 #include "../../../include/xlsxwriter/shared_strings.h"
13
14 // Test assembling a complete Worksheet file.
CTEST(worksheet,worksheet_data_bar07)15 CTEST(worksheet, worksheet_data_bar07) {
16
17 char* got;
18 char exp[] =
19 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
20 "<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
21 "<dimension ref=\"A1\"/>"
22 "<sheetViews>"
23 "<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
24 "</sheetViews>"
25 "<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
26 "<sheetData/>"
27 "<conditionalFormatting sqref=\"A1\">"
28 "<cfRule type=\"dataBar\" priority=\"1\">"
29 "<dataBar>"
30 "<cfvo type=\"min\"/>"
31 "<cfvo type=\"max\"/>"
32 "<color rgb=\"FF638EC6\"/>"
33 "</dataBar>"
34 "<extLst>"
35 "<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
36 "<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
37 "</ext>"
38 "</extLst>"
39 "</cfRule>"
40 "</conditionalFormatting>"
41 "<conditionalFormatting sqref=\"A2:B2\">"
42 "<cfRule type=\"dataBar\" priority=\"2\">"
43 "<dataBar>"
44 "<cfvo type=\"min\"/>"
45 "<cfvo type=\"max\"/>"
46 "<color rgb=\"FF63C384\"/>"
47 "</dataBar>"
48 "<extLst>"
49 "<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
50 "<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
51 "</ext>"
52 "</extLst>"
53 "</cfRule>"
54 "</conditionalFormatting>"
55 "<conditionalFormatting sqref=\"A3:C3\">"
56 "<cfRule type=\"dataBar\" priority=\"3\">"
57 "<dataBar>"
58 "<cfvo type=\"min\"/>"
59 "<cfvo type=\"max\"/>"
60 "<color rgb=\"FFFF555A\"/>"
61 "</dataBar>"
62 "<extLst>"
63 "<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
64 "<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
65 "</ext>"
66 "</extLst>"
67 "</cfRule>"
68 "</conditionalFormatting>"
69 "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
70 "<extLst>"
71 "<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
72 "<x14:conditionalFormattings>"
73 "<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
74 "<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
75 "<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\" axisPosition=\"middle\">"
76 "<x14:cfvo type=\"autoMin\"/>"
77 "<x14:cfvo type=\"autoMax\"/>"
78 "<x14:borderColor rgb=\"FF638EC6\"/>"
79 "<x14:negativeFillColor rgb=\"FFFF0000\"/>"
80 "<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
81 "<x14:axisColor rgb=\"FF000000\"/>"
82 "</x14:dataBar>"
83 "</x14:cfRule>"
84 "<xm:sqref>A1</xm:sqref>"
85 "</x14:conditionalFormatting>"
86 "<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
87 "<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
88 "<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\" axisPosition=\"none\">"
89 "<x14:cfvo type=\"autoMin\"/>"
90 "<x14:cfvo type=\"autoMax\"/>"
91 "<x14:borderColor rgb=\"FF63C384\"/>"
92 "<x14:negativeFillColor rgb=\"FFFF0000\"/>"
93 "<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
94 "</x14:dataBar>"
95 "</x14:cfRule>"
96 "<xm:sqref>A2:B2</xm:sqref>"
97 "</x14:conditionalFormatting>"
98 "<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
99 "<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
100 "<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
101 "<x14:cfvo type=\"autoMin\"/>"
102 "<x14:cfvo type=\"autoMax\"/>"
103 "<x14:borderColor rgb=\"FFFF555A\"/>"
104 "<x14:negativeFillColor rgb=\"FFFF0000\"/>"
105 "<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
106 "<x14:axisColor rgb=\"FF0070C0\"/>"
107 "</x14:dataBar>"
108 "</x14:cfRule>"
109 "<xm:sqref>A3:C3</xm:sqref>"
110 "</x14:conditionalFormatting>"
111 "</x14:conditionalFormattings>"
112 "</ext>"
113 "</extLst>"
114 "</worksheet>";
115
116 FILE* testfile = lxw_tmpfile(NULL);
117
118 lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
119 worksheet->file = testfile;
120 worksheet_select(worksheet);
121
122 lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
123
124 conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
125 conditional_format->bar_axis_position = LXW_CONDITIONAL_BAR_AXIS_MIDPOINT;
126 worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
127 memset(conditional_format, 0, sizeof(lxw_conditional_format));
128
129 conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
130 conditional_format->bar_color = 0x63C384;
131 conditional_format->bar_axis_position = LXW_CONDITIONAL_BAR_AXIS_NONE;
132 worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
133 memset(conditional_format, 0, sizeof(lxw_conditional_format));
134
135 conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
136 conditional_format->bar_color = 0xFF555A;
137 conditional_format->bar_axis_color = 0x0070C0;
138 worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
139
140 free(conditional_format);
141 lxw_worksheet_assemble_xml_file(worksheet);
142
143 RUN_XLSX_STREQ_SHORT(exp, got);
144
145 lxw_worksheet_free(worksheet);
146 }
147