📄 xlhtml.c
字号:
}void update_cell_xf(U16 r, U16 c, U16 xf){ work_sheet *ws; if ((sheet_count < 0)||(r > HARD_MAX_ROWS)||(c > HARD_MAX_COLS)) return; if (sheet_count >= (int)max_worksheets) { if (add_more_worksheet_ptrs()) return; } if (ws_array[sheet_count] == 0) { if (ws_init(sheet_count)) return; } if (r >= ws_array[sheet_count]->max_rows) { if (MaxRowExceeded) return; else { int diff = ((r-ws_array[sheet_count]->max_rows)/ROWS_INCR)+1; if(resize_c_array(ws_array[sheet_count], ROWS_INCR*diff, 0)) { MaxRowExceeded = 1; return; } } } if (c >= ws_array[sheet_count]->max_cols) { if (MaxColExceeded) return; else { int diff = ((c-ws_array[sheet_count]->max_cols)/COLS_INCR)+1; if (resize_c_array(ws_array[sheet_count], 0, (U16)(COLS_INCR*diff))) { MaxColExceeded = 1; return; } } } ws = ws_array[sheet_count]; if (ws->c_array[(r*ws->max_cols)+c] == 0) { ws->c_array[(r*ws->max_cols)+c] = (cell *)malloc(sizeof(cell)); if (ws->c_array[(r*ws->max_cols)+c]) { uni_string_clear(&ws->c_array[(r*ws->max_cols)+c]->ustr); ws->c_array[(r*ws->max_cols)+c]->xfmt = xf; ws->c_array[(r*ws->max_cols)+c]->type = 1; /* This is the Blank Cell type */ if (r > ws_array[sheet_count]->biggest_row) ws_array[sheet_count]->biggest_row = r; if (c > ws_array[sheet_count]->biggest_col) ws_array[sheet_count]->biggest_col = c; ws->c_array[(r*ws->max_cols)+c]->spanned = 0; ws->c_array[(r*ws->max_cols)+c]->rowspan = 0; ws->c_array[(r*ws->max_cols)+c]->colspan = 0; uni_string_clear(&ws->c_array[(r*ws->max_cols)+c]->h_link); } }/* else { printf("R:%02X C:%02X XF:%02X is:%02X\n", r, c, xf, ws->c_array[r][c]->xfmt); } */}void update_cell_hyperlink(U16 r, U16 c, U8 *hyperlink, int len, U16 uni){ work_sheet *ws; if (sheet_count < 0) /* Used to do a "0 <" check on r & c */ return; if (sheet_count >= (int)max_worksheets) { if (add_more_worksheet_ptrs()) return; } if (ws_array[sheet_count] == 0) { if (ws_init(sheet_count)) return; } if (r >= ws_array[sheet_count]->max_rows) { if (MaxRowExceeded) return; else { int diff = ((r-ws_array[sheet_count]->max_rows)/ROWS_INCR)+1; if(resize_c_array(ws_array[sheet_count], ROWS_INCR*diff, 0)) { MaxRowExceeded = 1; return; } } } if (c >= ws_array[sheet_count]->max_cols) { if (MaxColExceeded) return; else { int diff = ((c-ws_array[sheet_count]->max_cols)/COLS_INCR)+1; if(resize_c_array(ws_array[sheet_count], 0, (U16)(COLS_INCR*diff))) { MaxColExceeded = 1; return; } } } ws = ws_array[sheet_count]; if (ws->c_array[(r*ws->max_cols)+c] == 0) { /* should not get here, but just in case */ return; } if (ws->c_array[(r*ws->max_cols)+c]->h_link.str == 0) { ws->c_array[(r*ws->max_cols)+c]->h_link.str = (U8 *)malloc(len); if (ws->c_array[(r*ws->max_cols)+c]->h_link.str) memcpy(ws->c_array[(r*ws->max_cols)+c]->h_link.str, hyperlink, len); ws->c_array[(r*ws->max_cols)+c]->h_link.uni = uni; if (len) { if (uni < 2) ws->c_array[(r*ws->max_cols)+c]->h_link.len = (U16)(len-1); else ws->c_array[(r*ws->max_cols)+c]->h_link.len = (U16)(len-2); } }/* else { printf("R:%02X C:%02X XF:%02X is:%s\n", r, c, xf, ws->c_array[r][c]->h_link.str); } */}void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt){ if ((str == 0)||(len == 0)) { next_string++; /* increment for empty strings, too */ return; } if (next_string >= max_strings) { uni_string **tstr_array; size_t new_size = (max_strings + STRINGS_INCR) * sizeof(uni_string *); tstr_array = (uni_string **)realloc(str_array, new_size); if (tstr_array == NULL) { MaxStringsExceeded = 1;/* fprintf(stderr, "%s: cannot allocate %d bytes for string storage %d: %s", PRGNAME, new_size, errno, strerror(errno)); */ return; } else { unsigned long i; str_array = tstr_array; /* Clear the new string slots */ for (i=max_strings; i<(max_strings + STRINGS_INCR); i++) str_array[i] = 0; max_strings += STRINGS_INCR; } } if (str_array[next_string] == 0) { str_array[next_string] = (uni_string *)malloc(sizeof(uni_string)); if (str_array[next_string]) { str_array[next_string]->str = (U8 *)malloc(len+1); if (str_array[next_string]->str) { memcpy(str_array[next_string]->str, str, len); str_array[next_string]->str[len] = 0; str_array[next_string]->len = len; str_array[next_string]->uni = uni; if (fmt_run && crun_cnt) { int rlen = crun_cnt*4; str_array[next_string]->fmt_run = malloc(rlen); if (str_array[next_string]->fmt_run) { memcpy(str_array[next_string]->fmt_run, fmt_run, rlen); str_array[next_string]->crun_cnt = crun_cnt; } else str_array[next_string]->crun_cnt = 0; } else { str_array[next_string]->fmt_run = 0; str_array[next_string]->crun_cnt = 0; } } } } next_string++;}void add_font(U16 size, U16 attr, U16 c_idx, U16 bold, U16 super, U8 underline, U16 uni, U8 *n, U16 len){ if (n == 0) return; if (next_font >= max_fonts) { font_attr **tfont_array; fnt_cnt *tf_cnt; tfont_array = (font_attr **)realloc(font_array, (max_fonts * FONTS_INCR) * sizeof(font_attr *)); tf_cnt = (fnt_cnt *)realloc(f_cnt, (max_fonts * FONTS_INCR) * sizeof(fnt_cnt)); if ((tf_cnt == NULL) || (tfont_array == NULL)) { MaxFontsExceeded = 1; return; } else { /* Next init the array... */ unsigned int i; font_array = tfont_array; f_cnt = tf_cnt; for (i=max_fonts; i<max_fonts+FONTS_INCR; i++) { font_array[i] = 0; f_cnt[i].name = 0; } max_fonts += FONTS_INCR; } } if (font_array[next_font] == 0) { font_array[next_font] = (font_attr *)malloc(sizeof(font_attr)); if (font_array[next_font]) { font_array[next_font]->name.str = (U8 *)malloc(len+1); if (font_array[next_font]->name.str) { font_array[next_font]->attr = attr; font_array[next_font]->c_idx = c_idx; font_array[next_font]->bold = bold; font_array[next_font]->super = super; font_array[next_font]->underline = underline; font_array[next_font]->name.uni = uni; memcpy(font_array[next_font]->name.str, n, len); font_array[next_font]->name.str[len] = 0; font_array[next_font]->name.len = len; font_array[next_font]->name.fmt_run = 0; font_array[next_font]->name.crun_cnt = 0; /* We will "pre-digest" the font size.. */ if (size >= 0x02D0) /* 36 pts */ font_array[next_font]->size = 7; else if (size >= 0x01E0) /* 24 pts */ font_array[next_font]->size = 6; else if (size >= 0x0168) /* 18 pts */ font_array[next_font]->size = 5; else if (size >= 0x00F0) /* 12 pts */ font_array[next_font]->size = 4; else if (size >= 0x00C8) /* 10 pts */ font_array[next_font]->size = 3; else if (size >= 0x00A0) /* 8 pts */ font_array[next_font]->size = 2; else font_array[next_font]->size = 1; } } } next_font++; if (next_font == 4) /* Per the doc's - number 4 doesn't exist. */ next_font++;}void add_ws_title(U16 uni, U8 *n, U16 len){ if (n == 0) return; if (next_ws_title >= max_worksheets) { if (add_more_worksheet_ptrs()) return; } if (ws_array[next_ws_title] == 0) { if (ws_init(next_ws_title)) return; } if (ws_array[next_ws_title]->ws_title.str == 0) { ws_array[next_ws_title]->ws_title.str = (U8 *)malloc(len+1); if (ws_array[next_ws_title]->ws_title.str) { ws_array[next_ws_title]->ws_title.uni = uni; memcpy(ws_array[next_ws_title]->ws_title.str, n, len); ws_array[next_ws_title]->ws_title.str[len] = 0; ws_array[next_ws_title]->ws_title.len = len; ws_array[next_ws_title]->ws_title.crun_cnt = 0; ws_array[next_ws_title]->ws_title.fmt_run = 0; } } next_ws_title++;}void add_xf_array(U16 fnt_idx, U16 fmt_idx, U16 gen, U16 align, U16 indent, U16 b_style, U16 b_l_color, U32 b_t_color, U16 cell_color){ if (next_xf >= max_xformats) { xf_attr **txf_array; txf_array = (xf_attr **)realloc(xf_array, (max_xformats + XFORMATS_INCR) * sizeof(xf_attr *)); if (txf_array == NULL) { MaxXFExceeded = 1; return; } else { unsigned int i; xf_array = txf_array; for (i=max_xformats; i<(max_xformats + XFORMATS_INCR); i++) xf_array[i] = 0; max_xformats += XFORMATS_INCR; } } if (xf_array[next_xf] == 0) { xf_array[next_xf] = (xf_attr *)malloc(sizeof(xf_attr)); if (xf_array[next_xf]) { xf_array[next_xf]->fnt_idx = fnt_idx; xf_array[next_xf]->fmt_idx = fmt_idx; xf_array[next_xf]->gen = gen; xf_array[next_xf]->align = align; xf_array[next_xf]->indent = indent; xf_array[next_xf]->b_style = b_style; xf_array[next_xf]->b_l_color = b_l_color; xf_array[next_xf]->b_t_color = b_t_color; xf_array[next_xf]->cell_color = cell_color; } next_xf++; }}void decodeBoolErr(U16 value, U16 flag, char *str){ if (str == 0) return; if (flag == 0) { if (value == 1) strcpy(str, "TRUE"); else strcpy(str, "FALSE"); } else { switch(value) { case 0x00: strcpy(str, "#NULL!"); break; case 0x07: strcpy(str, "#DIV/0!"); break; case 0x0F: strcpy(str, "#VALUE!"); break; case 0x17: strcpy(str, "#REF!"); break; case 0x1D: strcpy(str, "#NAME?"); break; case 0x24: strcpy(str, "#NUM!"); break; case 0x2A: strcpy(str, "#N/A"); break; default: strcpy(str, "#ERR"); break; } }}int IsCellNumeric(cell *c){ int ret_val = 0; switch (c->type & 0x00FF) { case 0x02: /* Int */ case 0x03: /* Float */ /* case 0x06: */ /* Formula */ /* case 0x08: */ case 0x7E: /* RK */ /* case 0xBC: */ /* case 0x21: */ case 0xBD: /* MulRK */ ret_val = 1; break; default: break; } return ret_val;}/*! \retval 0 not safe at all. \retval 1 extended format is OK \retval 2 Fonts OK */int IsCellSafe(cell *c){ int safe = 0; if (c->xfmt < next_xf) { if (xf_array[c->xfmt]) { safe = 1; if (xf_array[c->xfmt]->fnt_idx < next_font) { if (font_array[xf_array[c->xfmt]->fnt_idx]) safe = 2; } } } return safe;}int IsCellFormula(cell *c){ if ((c->type > 0x0100)||(c->type == 0x0006)) return 1; else return 0;}void output_cell(cell *c, int xml){ html_attr h; if (c == NULL) printf( xml ? "" : "<TD> "); else if (c->spanned != 0) return; else { /* Determine whether or not its of numeric origin.. */ int numeric = IsCellNumeric(c); /* 0=Text 1=Numeric */ html_flag_init(&h); if (c->xfmt == 0) { /* Unknown format... */ printf( xml ? "" : "<TD>"); /* This section doesn't use Unicode */ if (c->ustr.str) OutputString(&(c->ustr)); else printf( xml ? "" : " "); } else { /* This is the BIFF7 & 8 stuff... */ int safe; int nullString = 1; safe = IsCellSafe(c); if (c->ustr.str) { if (c->ustr.uni < 2) /* UNI? */ nullString = null_string(c->ustr.str); else nullString = 0; } /* First take care of text color & alignment */ printf( xml ? "" : "<TD"); if ((c->rowspan != 0)||(c->colspan != 0)) { if (c->colspan) printf( xml ? "<colspan>%d</colspan>" : " COLSPAN=\"%d\"",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -