Commit c511136b authored by Michael Meeks's avatar Michael Meeks

Fixes to number parsing to allow 1.156E-7 in a cell :-)

Added PTG_AREA_N, Added PTG_ARRAY bits ( untested ),
Standardised number transfer fixing some problems.
parent 809d8e5e
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/cell.c (cell_set_text_simple): Fix for 1.234E-07
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
......
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/cell.c (cell_set_text_simple): Fix for 1.234E-07
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
......
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/cell.c (cell_set_text_simple): Fix for 1.234E-07
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
......
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/cell.c (cell_set_text_simple): Fix for 1.234E-07
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
......
......@@ -102,6 +102,8 @@ GNOME Spread Sheet task list
Add collation of BIFF continuation records to the
previous record, to save many checks in the code.
Get correct RK values for _tiny_ floats coming through.
* Formulae
Sort out PtgRefN family, convert to correct posn.
......@@ -116,7 +118,6 @@ GNOME Spread Sheet task list
* Sheets
When adding a sheet or renaming a sheet, should we reparse everything?
<<<<<<< TODO
* Clipboard
......@@ -124,12 +125,3 @@ Perhaps make a global clipboard and remove all the hacks in the
current clipboard code to find the clipboard.=======
>>>>>>> 1.45
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* ms-formula.c (ms_excel_parse_formula): PTG_AREAN added,
and PTG_AREA updated to include 'shared' flag.
(ms_excel_parse_formula): Added PTG_ARRAY code.
* ms-formula.h (FORMULA_PTG_ARRAY): Added PTG_ARRAY
* ms-excel.c (ms_excel_read_cell): Added more sensible
floating point printing throught.
* ms-excel.h (MS_EXCEL_DOUBLE_FORMAT): Created to
standardise number transfer.
1999-04-14 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* ms-formula.h: Updated ms_excel_parse_formula prototype.
......
......@@ -1544,14 +1544,16 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
break ;
case BIFF_NUMBER:
{
char buf[65];
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
double num = BIFF_GETDOUBLE (q->data + 6); /*
* FIXME GETDOUBLE is not endian independant
*/
/* dump (q->data, q->length);
snprintf (buf, 64, "NUM %f", num); */
snprintf (buf, 64, "%f", num);
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), buf);
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, num);
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), buf);
break;
}
case BIFF_COLINFO: /* FIXME: See: S59D67.HTM */
......@@ -1584,19 +1586,20 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
}
case BIFF_RK: /* See: S59DDA.HTM */
{
char buf[65];
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
/* printf ("RK number : 0x%x, length 0x%x\n", q->opcode, q->length);
dump (q->data, q->length);*/
snprintf (buf, 64, "%f", biff_get_rk(q->data+6));
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(q->data+6));
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), buf);
break;
}
case BIFF_MULRK: /* S59DA8.HTM */
{
guint32 col, row, lastcol ;
char buf[65] ;
guint8 *ptr = q->data ;
guint32 col, row, lastcol;
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
guint8 *ptr = q->data;
/* printf ("MULRK\n") ;
dump (q->data, q->length) ; */
......@@ -1609,7 +1612,8 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
g_assert (lastcol>=col) ;
while (col<=lastcol)
{ /* 2byte XF, 4 byte RK */
snprintf (buf, 64, "%f", biff_get_rk(ptr+2)) ;
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(ptr+2)) ;
ms_excel_sheet_insert(sheet, BIFF_GETWORD(ptr), col, row, buf) ;
col++ ;
ptr+= 6 ;
......
......@@ -106,6 +106,9 @@ typedef struct _MS_EXCEL_WORKBOOK
Workbook *gnum_wb ;
} MS_EXCEL_WORKBOOK ;
#define MS_EXCEL_DOUBLE_FORMAT "%.16G"
#define MS_EXCEL_DOUBLE_FORMAT_LEN 65
extern char* biff_get_externsheet_name (MS_EXCEL_WORKBOOK *wb, guint16 idx, gboolean get_first) ;
extern char* biff_get_text (BYTE *ptr, guint32 length, guint32 *byte_length) ;
extern const char* biff_get_error_text (const guint8 err) ;
......
......@@ -1544,14 +1544,16 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
break ;
case BIFF_NUMBER:
{
char buf[65];
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
double num = BIFF_GETDOUBLE (q->data + 6); /*
* FIXME GETDOUBLE is not endian independant
*/
/* dump (q->data, q->length);
snprintf (buf, 64, "NUM %f", num); */
snprintf (buf, 64, "%f", num);
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), buf);
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, num);
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), buf);
break;
}
case BIFF_COLINFO: /* FIXME: See: S59D67.HTM */
......@@ -1584,19 +1586,20 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
}
case BIFF_RK: /* See: S59DDA.HTM */
{
char buf[65];
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
/* printf ("RK number : 0x%x, length 0x%x\n", q->opcode, q->length);
dump (q->data, q->length);*/
snprintf (buf, 64, "%f", biff_get_rk(q->data+6));
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(q->data+6));
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), buf);
break;
}
case BIFF_MULRK: /* S59DA8.HTM */
{
guint32 col, row, lastcol ;
char buf[65] ;
guint8 *ptr = q->data ;
guint32 col, row, lastcol;
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
guint8 *ptr = q->data;
/* printf ("MULRK\n") ;
dump (q->data, q->length) ; */
......@@ -1609,7 +1612,8 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
g_assert (lastcol>=col) ;
while (col<=lastcol)
{ /* 2byte XF, 4 byte RK */
snprintf (buf, 64, "%f", biff_get_rk(ptr+2)) ;
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(ptr+2)) ;
ms_excel_sheet_insert(sheet, BIFF_GETWORD(ptr), col, row, buf) ;
col++ ;
ptr+= 6 ;
......
......@@ -106,6 +106,9 @@ typedef struct _MS_EXCEL_WORKBOOK
Workbook *gnum_wb ;
} MS_EXCEL_WORKBOOK ;
#define MS_EXCEL_DOUBLE_FORMAT "%.16G"
#define MS_EXCEL_DOUBLE_FORMAT_LEN 65
extern char* biff_get_externsheet_name (MS_EXCEL_WORKBOOK *wb, guint16 idx, gboolean get_first) ;
extern char* biff_get_text (BYTE *ptr, guint32 length, guint32 *byte_length) ;
extern const char* biff_get_error_text (const guint8 err) ;
......
......@@ -886,9 +886,6 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
}
break ;
case FORMULA_PTG_AREAN:
printf ("REFN\n") ;
error = 1 ;
break ;
case FORMULA_PTG_AREA:
{
CellRef *first, *last ;
......@@ -896,15 +893,15 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
if (sheet->ver == eBiffV8)
{
first = getRefV8(sheet, BIFF_GETBYTE(cur+0), BIFF_GETWORD(cur+4),
fn_col, fn_row, 0) ;
fn_col, fn_row, shared) ;
last = getRefV8(sheet, BIFF_GETBYTE(cur+2), BIFF_GETWORD(cur+6),
fn_col, fn_row, 0) ;
fn_col, fn_row, shared) ;
ptg_length = 8 ;
}
else
{
first = getRefV7(sheet, BIFF_GETBYTE(cur+4), BIFF_GETWORD(cur+0), fn_col, fn_row, 0) ;
last = getRefV7(sheet, BIFF_GETBYTE(cur+5), BIFF_GETWORD(cur+2), fn_col, fn_row, 0) ;
first = getRefV7(sheet, BIFF_GETBYTE(cur+4), BIFF_GETWORD(cur+0), fn_col, fn_row, shared) ;
last = getRefV7(sheet, BIFF_GETBYTE(cur+5), BIFF_GETWORD(cur+2), fn_col, fn_row, shared) ;
ptg_length = 6 ;
}
fstr = cellref_name (first, sheet->gnum_sheet, fn_col, fn_row) ;
......@@ -920,8 +917,43 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
g_free (lstr) ;
g_free (first) ;
g_free (last) ;
break ;
}
case FORMULA_PTG_ARRAY:
{
guint16 cols=BIFF_GETBYTE(cur+0);
guint16 rows=BIFF_GETWORD(cur+1);
guint16 lpx,lpy;
guint8 *data=cur+3;
GString *ans = g_string_new ("{");
ptg_length = 3;
if (cols==0) cols=256;
for (lpy=0;lpy<rows;lpy++) {
for (lpx=0;lpx<cols;lpx++) {
guint8 opts=BIFF_GETBYTE(data);
if (opts == 1) {
g_string_sprintfa (ans, MS_EXCEL_DOUBLE_FORMAT,
BIFF_GETDOUBLE(data+1));
data+=9;
ptg_length+=9;
} else if (opts == 2) {
guint32 len;
g_string_append (ans, biff_get_text (data+2, BIFF_GETBYTE(data+1), &len));
g_string_append (ans, ",");
data+=len+2;
ptg_length+=2+len;
} else {
printf ("Duff type\n");
break;
}
g_string_append (ans, ";");
}
}
g_string_append (ans, "}");
parse_list_push_raw (stack, ans->str, NO_PRECEDENCE);
g_string_free (ans, FALSE);
break;
}
break ;
case FORMULA_PTG_FUNC:
{
if (!make_function (stack, BIFF_GETWORD(cur), -1)) error = 1 ;
......
......@@ -31,7 +31,7 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
#define FORMULA_PTG_BOOL 0x1d
#define FORMULA_PTG_INT 0x1e
#define FORMULA_PTG_NUM 0x1f /* 8 byte IEEE floating point number */
#define FORMULA_PTG_ARRAY 0x20
#define FORMULA_PTG_FUNC 0x21
#define FORMULA_PTG_FUNC_VAR 0x22
#define FORMULA_PTG_NAME 0x23
......
......@@ -886,9 +886,6 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
}
break ;
case FORMULA_PTG_AREAN:
printf ("REFN\n") ;
error = 1 ;
break ;
case FORMULA_PTG_AREA:
{
CellRef *first, *last ;
......@@ -896,15 +893,15 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
if (sheet->ver == eBiffV8)
{
first = getRefV8(sheet, BIFF_GETBYTE(cur+0), BIFF_GETWORD(cur+4),
fn_col, fn_row, 0) ;
fn_col, fn_row, shared) ;
last = getRefV8(sheet, BIFF_GETBYTE(cur+2), BIFF_GETWORD(cur+6),
fn_col, fn_row, 0) ;
fn_col, fn_row, shared) ;
ptg_length = 8 ;
}
else
{
first = getRefV7(sheet, BIFF_GETBYTE(cur+4), BIFF_GETWORD(cur+0), fn_col, fn_row, 0) ;
last = getRefV7(sheet, BIFF_GETBYTE(cur+5), BIFF_GETWORD(cur+2), fn_col, fn_row, 0) ;
first = getRefV7(sheet, BIFF_GETBYTE(cur+4), BIFF_GETWORD(cur+0), fn_col, fn_row, shared) ;
last = getRefV7(sheet, BIFF_GETBYTE(cur+5), BIFF_GETWORD(cur+2), fn_col, fn_row, shared) ;
ptg_length = 6 ;
}
fstr = cellref_name (first, sheet->gnum_sheet, fn_col, fn_row) ;
......@@ -920,8 +917,43 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
g_free (lstr) ;
g_free (first) ;
g_free (last) ;
break ;
}
case FORMULA_PTG_ARRAY:
{
guint16 cols=BIFF_GETBYTE(cur+0);
guint16 rows=BIFF_GETWORD(cur+1);
guint16 lpx,lpy;
guint8 *data=cur+3;
GString *ans = g_string_new ("{");
ptg_length = 3;
if (cols==0) cols=256;
for (lpy=0;lpy<rows;lpy++) {
for (lpx=0;lpx<cols;lpx++) {
guint8 opts=BIFF_GETBYTE(data);
if (opts == 1) {
g_string_sprintfa (ans, MS_EXCEL_DOUBLE_FORMAT,
BIFF_GETDOUBLE(data+1));
data+=9;
ptg_length+=9;
} else if (opts == 2) {
guint32 len;
g_string_append (ans, biff_get_text (data+2, BIFF_GETBYTE(data+1), &len));
g_string_append (ans, ",");
data+=len+2;
ptg_length+=2+len;
} else {
printf ("Duff type\n");
break;
}
g_string_append (ans, ";");
}
}
g_string_append (ans, "}");
parse_list_push_raw (stack, ans->str, NO_PRECEDENCE);
g_string_free (ans, FALSE);
break;
}
break ;
case FORMULA_PTG_FUNC:
{
if (!make_function (stack, BIFF_GETWORD(cur), -1)) error = 1 ;
......
......@@ -31,7 +31,7 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
#define FORMULA_PTG_BOOL 0x1d
#define FORMULA_PTG_INT 0x1e
#define FORMULA_PTG_NUM 0x1f /* 8 byte IEEE floating point number */
#define FORMULA_PTG_ARRAY 0x20
#define FORMULA_PTG_FUNC 0x21
#define FORMULA_PTG_FUNC_VAR 0x22
#define FORMULA_PTG_NAME 0x23
......
......@@ -601,8 +601,10 @@ cell_set_text_simple (Cell *cell, char *text)
/* falldown */
case 'E': case 'e': case '+': case ':': case '.': case ',':
if (*p == 'e' || *p == 'E')
if (*p == 'e' || *p == 'E') {
seen_exp = TRUE;
if (*(p+1)=='-') p++; /* Lookahead */
}
if (*p == ',' || *p == '.')
if (*lconv->decimal_point != *p){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment