struct wbookctx *wbook_new_ex(struct xl_io_handler io_handler, char *filename, int store_in_memory) { struct wbookctx *wbook; wbook = malloc(sizeof(struct wbookctx)); wbook->biff = bw_new(); wbook->OLEwriter = ow_new_ex(io_handler,filename); if (wbook->OLEwriter == NULL) { free(wbook); return NULL; } wbook->store_in_memory = store_in_memory; wbook->epoch1904 = 0; wbook->activesheet = 0; wbook->firstsheet = 0; wbook->xf_index = 16; /* 15 style XF's and 1 cell XF. */ wbook->fileclosed = 0; wbook->biffsize = 0; wbook->sheetname = "Sheet"; wbook->tmp_format = fmt_new(0); wbook->url_format = NULL; wbook->codepage = 0x04E4; /* 1252 */ wbook->sheets = NULL; wbook->sheetcount = 0; wbook->formats = NULL; wbook->formatcount = 0; /* Add the default format for hyperlinks */ wbook->url_format = wbook_addformat(wbook); fmt_set_fg_color(wbook->url_format, "blue"); fmt_set_underline(wbook->url_format, 1); return wbook; }
fmt_t *fmt_new_alloc( const char *s, int len, fmt_type_t type ) { fmt_t *res = (fmt_t *)malloc( sizeof(fmt_t) ); if ( res == NULL ) return NULL; if ( fmt_new( s, len, type, res ) ) { free( res ); return NULL; } res->type = type; return res; }
/* Add a new format to the Excel workbook. This adds an XF record and * a FONT record. TODO: add a FORMAT record. */ struct xl_format *wbook_addformat(struct wbookctx *wbook) { int index; struct xl_format *fmt; index = wbook->formatcount; if (wbook->formats == NULL) wbook->formats = malloc(sizeof(struct xl_format *)); else wbook->formats = realloc(wbook->formats, sizeof(struct xl_format *) * (index + 1)); fmt = fmt_new(wbook->xf_index); wbook->xf_index += 1; wbook->formats[index] = fmt; wbook->formatcount++; return fmt; }