2015-12-22 00:59:45 +00:00
|
|
|
/*
|
|
|
|
* An example of how to hide rows and columns using the libxlsxwriter
|
|
|
|
* library.
|
|
|
|
*
|
|
|
|
* In order to hide rows without setting each one, (of approximately 1 million
|
2018-02-11 00:13:26 +00:00
|
|
|
* rows), Excel uses an optimization to hide all rows that don't have data. In
|
|
|
|
* Libxlsxwriter we replicate that using the worksheet_set_default_row()
|
|
|
|
* function.
|
2015-12-22 00:59:45 +00:00
|
|
|
*
|
2025-02-11 00:03:36 +00:00
|
|
|
* Copyright 2014-2025, John McNamara, jmcnamara@cpan.org
|
2015-12-22 00:59:45 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xlsxwriter.h"
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
/* Create a new workbook and add a worksheet. */
|
2016-01-04 19:48:16 +00:00
|
|
|
lxw_workbook *workbook = workbook_new("hide_row_col.xlsx");
|
2015-12-22 00:59:45 +00:00
|
|
|
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
|
|
|
lxw_row_t row;
|
|
|
|
|
|
|
|
/* Write some data. */
|
|
|
|
worksheet_write_string(worksheet, 0, 3, "Some hidden columns.", NULL);
|
|
|
|
worksheet_write_string(worksheet, 7, 0, "Some hidden rows.", NULL);
|
|
|
|
|
|
|
|
/* Hide all rows without data. */
|
|
|
|
worksheet_set_default_row(worksheet, 15, LXW_TRUE);
|
|
|
|
|
2018-02-11 00:13:26 +00:00
|
|
|
/* Set the height of empty rows that we want to display even if it is */
|
2015-12-22 00:59:45 +00:00
|
|
|
/* the default height. */
|
|
|
|
for (row = 1; row <= 6; row++)
|
2016-01-04 00:18:38 +00:00
|
|
|
worksheet_set_row(worksheet, row, 15, NULL);
|
2015-12-22 00:59:45 +00:00
|
|
|
|
|
|
|
/* Columns can be hidden explicitly. This doesn't increase the file size. */
|
|
|
|
lxw_row_col_options options = {.hidden = 1};
|
2016-01-04 00:01:00 +00:00
|
|
|
worksheet_set_column_opt(worksheet, COLS("G:XFD"), 8.43, NULL, &options);
|
2015-12-22 00:59:45 +00:00
|
|
|
|
|
|
|
workbook_close(workbook);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|