mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
Initial work on set_row().
This commit is contained in:
parent
e262b8e9b2
commit
ac87b9e359
@ -58,6 +58,9 @@
|
||||
/** Default column width in Excel */
|
||||
#define LXW_DEF_COL_WIDTH 8.43
|
||||
|
||||
/** Default row height in Excel */
|
||||
#define LXW_DEF_ROW_HEIGHT 15
|
||||
|
||||
/** Error codes from `worksheet_write*()` functions. */
|
||||
enum lxw_write_error {
|
||||
LXW_WRITE_ERROR_NONE = 0,
|
||||
@ -161,6 +164,12 @@ typedef struct lxw_worksheet_init_data {
|
||||
/* Struct to represent a worksheet row. */
|
||||
typedef struct lxw_row {
|
||||
lxw_row_t row_num;
|
||||
double height;
|
||||
lxw_format *format;
|
||||
uint8_t hidden;
|
||||
uint8_t level;
|
||||
uint8_t collapsed;
|
||||
uint8_t changed;
|
||||
struct lxw_table_cells *cells;
|
||||
|
||||
/* List pointers for queue.h. */
|
||||
@ -449,6 +458,11 @@ int8_t worksheet_set_column(lxw_worksheet *self, lxw_col_t firstcol,
|
||||
lxw_col_t lastcol, double width,
|
||||
lxw_format *format, lxw_row_col_options *options);
|
||||
|
||||
int8_t worksheet_set_row(lxw_worksheet *self,
|
||||
lxw_row_t row_num,
|
||||
double height,
|
||||
lxw_format *format, lxw_row_col_options *options);
|
||||
|
||||
lxw_worksheet *_new_worksheet(lxw_worksheet_init_data *init_data);
|
||||
void _free_worksheet(lxw_worksheet *worksheet);
|
||||
void _worksheet_assemble_xml_file(lxw_worksheet *worksheet);
|
||||
|
@ -143,6 +143,7 @@ _new_row(lxw_row_t row_num)
|
||||
if (row) {
|
||||
row->row_num = row_num;
|
||||
row->cells = calloc(1, sizeof(struct lxw_table_cells));
|
||||
row->height = LXW_DEF_ROW_HEIGHT;
|
||||
|
||||
if (row->cells)
|
||||
TAILQ_INIT(row->cells);
|
||||
@ -528,6 +529,11 @@ _write_row(lxw_worksheet *self, lxw_row *row, char *spans)
|
||||
{
|
||||
struct xml_attribute_list attributes;
|
||||
struct xml_attribute *attribute;
|
||||
int32_t xf_index = 0;
|
||||
|
||||
if (row->format) {
|
||||
xf_index = _get_xf_index(row->format);
|
||||
}
|
||||
|
||||
_INIT_ATTRIBUTES();
|
||||
_PUSH_ATTRIBUTES_INT("r", row->row_num + 1);
|
||||
@ -535,6 +541,24 @@ _write_row(lxw_worksheet *self, lxw_row *row, char *spans)
|
||||
if (spans)
|
||||
_PUSH_ATTRIBUTES_STR("spans", spans);
|
||||
|
||||
if (xf_index)
|
||||
_PUSH_ATTRIBUTES_INT("s", xf_index);
|
||||
|
||||
if (row->format)
|
||||
_PUSH_ATTRIBUTES_STR("customFormat", "1");
|
||||
|
||||
if (row->height != LXW_DEF_ROW_HEIGHT)
|
||||
_PUSH_ATTRIBUTES_INT("ht", row->height);
|
||||
|
||||
if (row->hidden)
|
||||
_PUSH_ATTRIBUTES_STR("hidden", "1");
|
||||
|
||||
if (row->height != LXW_DEF_ROW_HEIGHT)
|
||||
_PUSH_ATTRIBUTES_STR("customHeight", "1");
|
||||
|
||||
if (row->collapsed)
|
||||
_PUSH_ATTRIBUTES_STR("collapsed", "1");
|
||||
|
||||
if (TAILQ_EMPTY(row->cells))
|
||||
_xml_empty_tag(self->file, "row", &attributes);
|
||||
else
|
||||
@ -1100,7 +1124,7 @@ worksheet_set_column(lxw_worksheet *self,
|
||||
|
||||
/* Store the col sizes for use when calculating image vertices taking
|
||||
* hidden columns into account. Also store the column formats. */
|
||||
if (options->hidden)
|
||||
if (options && options->hidden)
|
||||
width = 0;
|
||||
|
||||
for (col = firstcol; col <= lastcol; col++) {
|
||||
@ -1113,3 +1137,57 @@ worksheet_set_column(lxw_worksheet *self,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the properties of a row.
|
||||
*/
|
||||
int8_t
|
||||
worksheet_set_row(lxw_worksheet *self,
|
||||
lxw_row_t row_num,
|
||||
double height,
|
||||
lxw_format *format, lxw_row_col_options *options)
|
||||
{
|
||||
|
||||
lxw_col_t min_col;
|
||||
int8_t err;
|
||||
uint8_t hidden = LXW_FALSE;
|
||||
uint8_t level = 0;
|
||||
uint8_t collapsed = LXW_FALSE;
|
||||
lxw_row *row;
|
||||
|
||||
if (options) {
|
||||
hidden = options->hidden;
|
||||
level = options->level;
|
||||
collapsed = options->collapsed;
|
||||
}
|
||||
|
||||
/* Use minimum col in _check_dimensions(). */
|
||||
if (self->dim_colmin != LXW_COL_MAX)
|
||||
min_col = self->dim_colmin;
|
||||
else
|
||||
min_col = 0;
|
||||
|
||||
err = _check_dimensions(self, row_num, min_col, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* If the height is 0 the row is hidden and the height is the default. */
|
||||
if (height == 0) {
|
||||
hidden = LXW_TRUE;
|
||||
height = LXW_DEF_ROW_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
row = _get_row(self->table, row_num);
|
||||
|
||||
row->height = height;
|
||||
row->format = format;
|
||||
row->hidden = hidden;
|
||||
row->level = level;
|
||||
row->collapsed = collapsed;
|
||||
row->changed = LXW_TRUE;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ int main() {
|
||||
lxw_format *format1 = workbook_add_format(workbook);
|
||||
lxw_format *format2 = workbook_add_format(workbook);
|
||||
|
||||
worksheet_set_row(worksheet, 0, 30, NULL, NULL);
|
||||
|
||||
format_set_font_name(format1, "Arial");
|
||||
format_set_bold(format1);
|
||||
format_set_align(format1, LXW_ALIGN_LEFT);
|
||||
|
@ -17,8 +17,6 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
||||
self.run_exe_test('test_format01')
|
||||
|
||||
def test_format02(self):
|
||||
# TODO. Ignore row height for now until set_row is implemented.
|
||||
self.ignore_elements = {'xl/worksheets/sheet1.xml': ['<row']}
|
||||
self.run_exe_test('test_format02')
|
||||
|
||||
def test_format06(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user