libxlsxwriter
hide_row_col.c
<< comments2.c panes.c >>

Example of hiding rows and columns in an Excel worksheet.

/*
* 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
* 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.
*
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
/* Create a new workbook and add a worksheet. */
lxw_workbook *workbook = workbook_new("hide_row_col.xlsx");
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. */
/* Set the height of empty rows that we want to display even if it is */
/* the default height. */
for (row = 1; row <= 6; row++)
worksheet_set_row(worksheet, row, 15, NULL);
/* Columns can be hidden explicitly. This doesn't increase the file size. */
lxw_row_col_options options = {.hidden = 1};
worksheet_set_column_opt(worksheet, COLS("G:XFD"), 8.43, NULL, &options);
workbook_close(workbook);
return 0;
}
lxw_row_col_options
Options for rows and columns.
Definition: worksheet.h:716
worksheet_set_default_row
void worksheet_set_default_row(lxw_worksheet *worksheet, double height, uint8_t hide_unused_rows)
Set the default row properties.
workbook_close
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
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:1603
LXW_TRUE
@ LXW_TRUE
Definition: common.h:53
COLS
#define COLS(cols)
Convert an Excel A:B column range into a (col1, col2) pair.
Definition: utility.h:63
worksheet_set_column_opt
lxw_error worksheet_set_column_opt(lxw_worksheet *worksheet, lxw_col_t first_col, lxw_col_t last_col, double width, lxw_format *format, lxw_row_col_options *options)
Set the properties for one or more columns of cells with options.
lxw_row_col_options::hidden
uint8_t hidden
Definition: worksheet.h:718
lxw_workbook
Struct to represent an Excel workbook.
Definition: workbook.h:273
lxw_row_t
uint32_t lxw_row_t
Definition: common.h:40
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_row
lxw_error worksheet_set_row(lxw_worksheet *worksheet, lxw_row_t row, double height, lxw_format *format)
Set the properties for a row of cells.
workbook_add_worksheet
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.