📄 xlhtml.c
字号:
int i; r = getShort(&working_buffer[0]); fc = getShort(&working_buffer[2]); lc = getShort(&working_buffer[last-2]); for (i=0; i<=(lc-fc); i++) { U32 t; S32 n2, n; /* Must be signed long !!! */ U16 f; F64 d; char temp[64]; f = getShort(&working_buffer[4+(i*6)]); n = getLong(&working_buffer[6+(i*6)]); t = n & 0x03; n2 = n>>2; switch (t) { case 0: RKtoDouble(n2, &d); sprintf(temp, "%.15g", d); break; case 1: RKtoDouble(n2, &d); sprintf(temp, "%.15g", d / 100.0); break; case 2: sprintf(temp, " %ld", (S32)n2); break; default: d = (F64) n2; sprintf(temp, "%.15g", d / 100.0 ); break; }/* printf("%08X %02X %s %d %d\n", n2, t, temp, r, fc+i); */ add_wb_array(r, fc+i, f, opcode, (U16)0, (U8 *)temp, (U16)strlen(temp), 0, 0); } } break; case 0xBE: /* MULBLANK */ working_buffer[bufidx++] = data; if (bufidx == last) { U16 r, fc, lc, j, f; r = getShort(&working_buffer[0]); fc = getShort(&working_buffer[2]); lc = getShort(&working_buffer[last-2]); for (j=0; j<=(lc-fc); j++) { /* This just stores format strings... */ f = getShort(&working_buffer[4+(j*2)]); add_wb_array(r, fc+j, f, opcode, (U16)0, (U8 *)0, (U16)0, 0, 0); } } break; case 0x18: /* Name UNI */ working_buffer[bufidx++] = data; if (bufidx == last) { char *ptr; working_buffer[bufidx] = 0; ptr = (char *)strstr((char *)&working_buffer[15], "LastUpdate"); if (ptr) { ptr += 13; lastUpdated = (char *)malloc(strlen(ptr)+1); if (lastUpdated) strcpy(lastUpdated, ptr); } else { ptr = (char *)strstr((char *)&working_buffer[15], "Title"); if (ptr) { ptr += 8; title = (char *)malloc(strlen(ptr)+1); if (title) strcpy(title, ptr); } } } break; case 0xE0: /* Extended format */ working_buffer[bufidx++] = data; if (bufidx == last) { 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; fnt_idx = getShort(&working_buffer[0]); fmt_idx = getShort(&working_buffer[2]); gen = getShort(&working_buffer[4]); align = getShort(&working_buffer[6]); indent = getShort(&working_buffer[8]); b_style = getShort(&working_buffer[10]); if (file_version == EXCEL95) { b_l_color = 0; b_t_color = 0; cell_color = (U16)(getShort(&working_buffer[12]) & (U16)0x1FFF); } else /* Excel 97 + */ { b_l_color = getShort(&working_buffer[12]); b_t_color = getLong(&working_buffer[14]); cell_color = getShort(&working_buffer[18]); } /* printf("XF:%02X FG:%02X BG:%02X\n", next_xf, cell_color&0x007F, (cell_color&0x1F80)>>7); */ /* printf("XF:%02X M:%02X b_t:%04X<br>\n", next_xf, indent, b_t_color); */ add_xf_array(fnt_idx, fmt_idx, gen, align, indent, b_style, b_l_color, b_t_color, cell_color); } break; case 0xE5: /* CELL MERGE INSTRUCTIONS */ working_buffer[bufidx++] = data; if (bufidx == last) { U16 num, fr, lr, fc, lc, i, j, k; ws_array[sheet_count]->spanned = 1; num = getShort(&working_buffer[0]); if (ws_array[sheet_count]->c_array == 0) return; for (i=0; i<num; i++) { cell *c; fr = getShort(&working_buffer[2+(i*8)]); lr = getShort(&working_buffer[4+(i*8)]); fc = getShort(&working_buffer[6+(i*8)]); lc = getShort(&working_buffer[8+(i*8)]); if (sheet_count < (int)max_worksheets) { if (ws_array[sheet_count] == 0) { if (ws_init(sheet_count)) return; } if (ws_array[sheet_count]->c_array) { if ((fr > lr)||(fr > ws_array[sheet_count]->biggest_row)||(lr > ws_array[sheet_count]->biggest_row)) lr = (U16)ws_array[sheet_count]->biggest_row; if ((fc > lc)||(fc > ws_array[sheet_count]->biggest_col)||(lc > ws_array[sheet_count]->biggest_col)) lc = ws_array[sheet_count]->biggest_col; for(j=fr; j<=lr; j++) { /* For each row */ for(k=fc; k<=lc; k++) { /* for each column */ c = ws_array[sheet_count]->c_array[(j*ws_array[sheet_count]->max_cols)+k]; if (c != 0) { c->spanned = 1; c->rowspan = 0; if (k == fc) c->colspan = (U16)((lc-fc)+1); else c->colspan = 0; }/* else { / Need to create one... printf("Bad One at:%d %d %d<br>\n", sheet_count, j, k); } */ } } } /* Now reset the first one... *//* printf("s:%d fr:%d fc:%d lr:%d lc:%d<br>\n", sheet_count, fr, fc, lr, lc); */ c = ws_array[sheet_count]->c_array[(fr*ws_array[sheet_count]->max_cols)+fc]; if (c != 0) { c->spanned = 0; c->rowspan = (U16)(lr-fr); c->colspan = (U16)(lc-fc); if (c->rowspan) c->rowspan++; if (c->colspan) c->colspan++; } } } } break; case 0xB8: /* Hyperlink */ working_buffer[bufidx++] = data; if (bufidx == last) { /* This is based on Office 97 info... */ U16 r, c, uni_type, off; U32 len; r = getShort(&working_buffer[0]); c = getShort(&working_buffer[4]); if (working_buffer[32] == 0xE0) { /* Unicode format */ len = getLong(&working_buffer[48]); off = 52; uni_type = 2; } else { /* Ascii format */ len = getLong(&working_buffer[50]); off = 54; uni_type = 0; } if (len > (U32)(bufidx - off)) { /* correct misidentified links */ if (uni_type == 0) { off = 36; uni_type = 2; len = getLong(&working_buffer[32]) * 2; } else len = bufidx - off; /* safety measure to make sure it doen't blow up */ } update_cell_hyperlink(r, c, &working_buffer[off], len, uni_type); } break; case 0x92: /* Color Palette */ working_buffer[bufidx++] = data; if (bufidx == last) { /* This is based on Office 97 info... */ int i; U8 red, green, blue; U16 cnt = getShort(&working_buffer[0]); numCustomColors = cnt; customColors = (U8 **)calloc(cnt+1, sizeof(char *)); for (i=0; i<cnt; i++) { char color_string[8]; red = (unsigned char)working_buffer[(4*i)+2]; green = (unsigned char)working_buffer[(4*i)+3]; blue = (unsigned char)working_buffer[(4*i)+4]; /* printf("%02X%02X%02X\n", (int)red, (int)green, (int)blue); */ sprintf(color_string, "%02X%02X%02X", (int)red, (int)green, (int)blue); customColors[i] = (U8 *)strdup(color_string); } } break; case 0x42: /* CodePage */ working_buffer[bufidx++] = data; if (bufidx == last) { CodePage = getShort(&working_buffer[0]); if (CodePage == 1200) CodePage = 0; /* Unicode inside, old behavior is OK */ } break; default: break; }}/*! returns 1 on error, 0 on success */int ws_init(int i){ U32 j; U16 k; if (i >= (int)max_worksheets) return 1; ws_array[i] = (work_sheet *)malloc(sizeof(work_sheet)); if (ws_array[i]) { ws_array[i]->spanned = 0; ws_array[i]->first_row = 0; ws_array[i]->biggest_row = -1; ws_array[i]->max_rows = ROWS_INCR; ws_array[i]->first_col = 0; ws_array[i]->biggest_col = -1; ws_array[i]->max_cols = COLS_INCR; uni_string_clear(&ws_array[i]->ws_title); ws_array[i]->c_array = (cell **)malloc(ROWS_INCR*COLS_INCR*sizeof(cell *)); if (ws_array[i]->c_array == 0) return 1; for (j=0; j<ROWS_INCR; j++) for (k=0; k<COLS_INCR; k++) ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k] = 0; } else return 1; return 0;}/*! returns 1 on error, 0 on success */int add_more_worksheet_ptrs(void){ work_sheet **tws_array; int pages; if (MaxWorksheetsExceeded) return 1; if (sheet_count > (int)max_worksheets) pages = (((sheet_count - max_worksheets)/WORKSHEETS_INCR) + 1) * WORKSHEETS_INCR; else pages = WORKSHEETS_INCR; tws_array = (work_sheet **)realloc(ws_array, (max_worksheets + pages) * sizeof(work_sheet *)); if (tws_array == NULL) { MaxWorksheetsExceeded = 1; return 1; } else { /* Next init the array... */ unsigned int i; ws_array = tws_array; for (i=max_worksheets; i<max_worksheets+pages; i++) ws_array[i] = 0; max_worksheets += pages; last_sheet = max_worksheets - 1; } return 0;}int resize_c_array(work_sheet *ws, U32 new_rows, U16 new_cols){ cell **tc_array; if (ws == 0) return 1; if (ws->c_array == 0) return 1; tc_array = (cell **)malloc((ws->max_rows+new_rows)*(ws->max_cols+new_cols)*sizeof(cell *)); if (tc_array == NULL) return 1; else { U32 j; U16 k; memset(tc_array, 0, (ws->max_rows+new_rows)*(ws->max_cols+new_cols)*sizeof(cell *)); for (j=0; j<(ws->max_rows); j++) { for (k=0; k<ws->max_cols; k++) tc_array[(j*(ws->max_cols+new_cols))+k] = ws->c_array[(j*ws->max_cols)+k]; } ws->max_cols += new_cols; ws->max_rows += new_rows; free(ws->c_array); ws->c_array = tc_array; } return 0;}void add_wb_array(U16 r, U16 c, U16 xf, U16 type, U8 uni, U8 *str, U16 len, U16 crun_cnt, U8 *fmt_run){ 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; } ws = ws_array[sheet_count]; if (r >= ws->max_rows) { if (MaxRowExceeded) return; else { int diff = ((r-ws->max_rows)/ROWS_INCR)+1; if(resize_c_array(ws, ROWS_INCR*diff, 0)) { MaxRowExceeded = 1; return; } } } if (c >= ws->max_cols) { if (MaxColExceeded) return; else { U16 diff = (U16)(((c-ws->max_cols)/COLS_INCR)+1); if(resize_c_array(ws, 0, (U16)(COLS_INCR*diff))) { MaxColExceeded = 1; return; } } } if (ws->c_array[(r*ws->max_cols)+c] == 0) { 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] = (cell *)malloc(sizeof(cell)); if (ws->c_array[(r*ws->max_cols)+c]) { if (str) { ws->c_array[(r*ws->max_cols)+c]->ustr.str = (U8 *)malloc(len+1); if (ws->c_array[(r*ws->max_cols)+c]->ustr.str) { memcpy(ws->c_array[(r*ws->max_cols)+c]->ustr.str, str, len); ws->c_array[(r*ws->max_cols)+c]->ustr.str[len] = 0; } ws->c_array[(r*ws->max_cols)+c]->ustr.uni = uni; ws->c_array[(r*ws->max_cols)+c]->ustr.len = len; if (fmt_run && crun_cnt) { int rlen = crun_cnt*4; ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run = malloc(rlen); if (ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run) { memcpy(ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run, fmt_run, rlen); ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = crun_cnt; } else ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = 0; } else { ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run = 0; ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = 0; } } else 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 = type; 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 /* Default attributes already copied */ { 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; if (str) { /* Check if a place holder is there and free it */ if (ws->c_array[(r*ws->max_cols)+c]->ustr.str != 0) free(ws->c_array[(r*ws->max_cols)+c]->ustr.str); ws->c_array[(r*ws->max_cols)+c]->ustr.str = (U8 *)malloc(len+1); if (ws->c_array[(r*ws->max_cols)+c]->ustr.str) { memcpy(ws->c_array[(r*ws->max_cols)+c]->ustr.str, str, len); ws->c_array[(r*ws->max_cols)+c]->ustr.str[len] = 0; } ws->c_array[(r*ws->max_cols)+c]->ustr.len = len; ws->c_array[(r*ws->max_cols)+c]->ustr.uni = uni; if (fmt_run && crun_cnt) { int rlen = crun_cnt*4; ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run = malloc(rlen); if (ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run) { memcpy(ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run, fmt_run, rlen); ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = crun_cnt; } else ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = 0; } else { ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run = 0; ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = 0; } } else { if (ws->c_array[(r*ws->max_cols)+c]->ustr.str == 0) { ws->c_array[(r*ws->max_cols)+c]->ustr.len = 0; ws->c_array[(r*ws->max_cols)+c]->ustr.uni = 0; ws->c_array[(r*ws->max_cols)+c]->ustr.fmt_run = 0; ws->c_array[(r*ws->max_cols)+c]->ustr.crun_cnt = 0; } } ws->c_array[(r*ws->max_cols)+c]->xfmt = xf; ws->c_array[(r*ws->max_cols)+c]->type = type; 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -