libxlsxwriter
worksheet_protection.c

Example of setting Excel worksheet protection. /*
* Example of cell locking and formula hiding in an Excel worksheet using
* libxlsxwriter.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("protection.xlsx");
/* Widen the first column to make the text clearer. */
worksheet_set_column(worksheet, 0, 0, 40, NULL);
/* Turn worksheet protection on without a password. */
worksheet_protect(worksheet, NULL, NULL);
/* Write a locked, unlocked and hidden cell. */
worksheet_write_string(worksheet, 0, 0, "B1 is locked. It cannot be edited.", NULL);
worksheet_write_string(worksheet, 1, 0, "B2 is unlocked. It can be edited.", NULL);
worksheet_write_string(worksheet, 2, 0, "B3 is hidden. The formula isn't visible.", NULL);
worksheet_write_formula(worksheet, 0, 1, "=1+2", NULL); /* Locked by default. */
worksheet_write_formula(worksheet, 1, 1, "=1+2", unlocked);
worksheet_write_formula(worksheet, 2, 1, "=1+2", hidden);
workbook_close(workbook);
return 0;
}
workbook_close
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
format_set_unlocked
void format_set_unlocked(lxw_format *format)
Set the cell unlocked state.
worksheet_write_formula
lxw_error worksheet_write_formula(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *formula, lxw_format *format)
Write a formula to a worksheet cell.
workbook_new
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_worksheet
Struct to represent an Excel worksheet.
Definition: worksheet.h:2107
lxw_format
Struct to represent the formatting properties of an Excel format.
Definition: format.h:358
worksheet_protect
void worksheet_protect(lxw_worksheet *worksheet, const char *password, lxw_protection *options)
Protect elements of a worksheet from modification.
lxw_workbook
Struct to represent an Excel workbook.
Definition: workbook.h:292
worksheet_write_string
lxw_error worksheet_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)
Write a string to a worksheet cell.
worksheet_set_column
lxw_error worksheet_set_column(lxw_worksheet *worksheet, lxw_col_t first_col, lxw_col_t last_col, double width, lxw_format *format)
Set the properties for one or more columns of cells.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5005076,"math_prob":0.57281923,"size":1545,"snap":"2023-14-2023-23","text_gpt3_token_len":377,"char_repetition_ratio":0.23166774,"word_repetition_ratio":0.04494382,"special_character_ratio":0.21423948,"punctuation_ratio":0.17094018,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9757966,"pos_list":[0,1,2],"im_url_duplicate_count":[null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-31T20:34:17Z\",\"WARC-Record-ID\":\"<urn:uuid:421954d6-e2f8-4eb0-a55b-7500f5d4e2d9>\",\"Content-Length\":\"13274\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4bd0ad05-48b6-465c-bf47-44dcd1d893f0>\",\"WARC-Concurrent-To\":\"<urn:uuid:76b78743-55d5-48d3-a62a-f70fc2d994ea>\",\"WARC-IP-Address\":\"185.199.108.153\",\"WARC-Target-URI\":\"https://libxlsxwriter.github.io/worksheet_protection_8c-example.html\",\"WARC-Payload-Digest\":\"sha1:CUPPBC5ZWN27TCOR2MY3G3HP7OQSTQ3H\",\"WARC-Block-Digest\":\"sha1:PKUMYP2MMGJ7URQ6GRT5MRX62EL7ILI2\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224647409.17_warc_CC-MAIN-20230531182033-20230531212033-00679.warc.gz\"}"}