[GH-ISSUE #393] A bug in documentation #314

Closed
opened 2026-05-05 12:08:31 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @Horseechen on GitHub (Feb 14, 2023).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/393

There is a confusing error in the 7th example in the following code(http://libxlsxwriter.github.io/data_validate_8c-example.html ): data_validation->validate should be assigned with a value of LXW_VALIDATION_TYPE_LIST_FORMULA rather than LXW_VALIDATION_TYPE_LIST.

original code:

    /*
     * Example 7. Limiting input to a value in a dropdown list.
     */
    worksheet_write_string(worksheet,
                           CELL("A15"),
                           "Select a value from a drop down list (using a cell range)",
                           NULL);
 
    data_validation->validate     = LXW_VALIDATION_TYPE_LIST;
    data_validation->value_formula = "=$E$4:$G$4";
 
    worksheet_data_validation_cell(worksheet, CELL("B15"), data_validation);

it should be

    /*
     * Example 7. Limiting input to a value in a dropdown list.
     */
    worksheet_write_string(worksheet,
                           CELL("A15"),
                           "Select a value from a drop down list (using a cell range)",
                           NULL);
 
    data_validation->validate     = LXW_VALIDATION_TYPE_LIST_FORMULA;
    data_validation->value_formula = "=$E$4:$G$4";
 
    worksheet_data_validation_cell(worksheet, CELL("B15"), data_validation);
Originally created by @Horseechen on GitHub (Feb 14, 2023). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/393 There is a confusing error in the 7th example in the following code(http://libxlsxwriter.github.io/data_validate_8c-example.html ): `data_validation->validate` should be assigned with a value of `LXW_VALIDATION_TYPE_LIST_FORMULA` rather than `LXW_VALIDATION_TYPE_LIST`. original code: ```cpp /* * Example 7. Limiting input to a value in a dropdown list. */ worksheet_write_string(worksheet, CELL("A15"), "Select a value from a drop down list (using a cell range)", NULL); data_validation->validate = LXW_VALIDATION_TYPE_LIST; data_validation->value_formula = "=$E$4:$G$4"; worksheet_data_validation_cell(worksheet, CELL("B15"), data_validation); ``` it should be ```cpp /* * Example 7. Limiting input to a value in a dropdown list. */ worksheet_write_string(worksheet, CELL("A15"), "Select a value from a drop down list (using a cell range)", NULL); data_validation->validate = LXW_VALIDATION_TYPE_LIST_FORMULA; data_validation->value_formula = "=$E$4:$G$4"; worksheet_data_validation_cell(worksheet, CELL("B15"), data_validation); ```
Author
Owner

@jmcnamara commented on GitHub (Feb 14, 2023):

The member name for data_validation->value_formula is a little bit confusing but the example is correct. The data validation list comes from a range in the spreadsheet:

Screenshot 2023-02-14 at 14 25 31

Probably the member should be called something like value_range or value_source but I was trying to reuse/minimise the number of fields.

<!-- gh-comment-id:1429835184 --> @jmcnamara commented on GitHub (Feb 14, 2023): The member name for `data_validation->value_formula` is a little bit confusing but the example is correct. The data validation list comes from a range in the spreadsheet: ![Screenshot 2023-02-14 at 14 25 31](https://user-images.githubusercontent.com/94267/218766788-e66fe7cc-499b-4dc4-b633-609244ddb520.png) Probably the member should be called something like `value_range` or `value_source` but I was trying to reuse/minimise the number of fields.
Author
Owner

@Horseechen commented on GitHub (Feb 14, 2023):

No, the example is incorrect. The parameter in Example 6 works in Example 7. You get the "right" result just by chance. You may try to change the value in reference cells then you will find that truth. Or you may comment Example 6's code, if you do so, the program will return a warning message.
2

<!-- gh-comment-id:1429946755 --> @Horseechen commented on GitHub (Feb 14, 2023): No, the example is incorrect. The parameter in Example 6 works in Example 7. You get the "right" result just by chance. You may try to change the value in reference cells then you will find that truth. Or you may comment Example 6's code, if you do so, the program will return a warning message. ![2](https://user-images.githubusercontent.com/19280960/218786606-c97c41b9-c1f1-4356-9e5e-27c1e21a6759.png)
Author
Owner

@Horseechen commented on GitHub (Feb 14, 2023):

By the way, in this page http://libxlsxwriter.github.io/working_with_data_validation.html
data_validation->validate is assigned with LXW_VALIDATION_TYPE_LIST_FORMULA
image

Just check it, I believe that the example code is incorrect.
I followed the http://libxlsxwriter.github.io/working_with_data_validation.html page and got the right result.

<!-- gh-comment-id:1429971759 --> @Horseechen commented on GitHub (Feb 14, 2023): By the way, in this page http://libxlsxwriter.github.io/working_with_data_validation.html `data_validation->validate` is assigned with `LXW_VALIDATION_TYPE_LIST_FORMULA` ![image](https://user-images.githubusercontent.com/19280960/218788613-09661f20-d0ae-4543-ae74-529fac236d7d.png) Just check it, I believe that the example code is incorrect. I followed the http://libxlsxwriter.github.io/working_with_data_validation.html page and got the right result.
Author
Owner

@jmcnamara commented on GitHub (Feb 14, 2023):

Ok, thanks. I get it now.

You are right the example is incorrect. The validation type should be LXW_VALIDATION_TYPE_LIST_FORMULA. I will fix it.

<!-- gh-comment-id:1429989576 --> @jmcnamara commented on GitHub (Feb 14, 2023): Ok, thanks. I get it now. You are right the example is incorrect. The validation type should be `LXW_VALIDATION_TYPE_LIST_FORMULA`. I will fix it.
Author
Owner

@Horseechen commented on GitHub (Feb 14, 2023):

I would like to say thank you because the libxlsxwriter is really useful. Thank you for your sharing.

<!-- gh-comment-id:1429996246 --> @Horseechen commented on GitHub (Feb 14, 2023): I would like to say thank you because the libxlsxwriter is really useful. Thank you for your sharing.
Author
Owner

@jmcnamara commented on GitHub (Feb 14, 2023):

Fixed on main and the documentation has been updated. Thanks for the report.

<!-- gh-comment-id:1430018436 --> @jmcnamara commented on GitHub (Feb 14, 2023): Fixed on main and the documentation has been updated. Thanks for the report.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#314
No description provided.