Commit f1da2c90 authored by Michael Meeks's avatar Michael Meeks

Registered Excel file types,

Fixed silly bugs in OLE creation,
Removed duff Array stuff,
parent 83447b57
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
new types; works round bug in selection.
* src/expr.c (eval_cell_value): Fix sillyness of top left
corner stuff.
* src/expr.h: Added const to value_dump
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
new types; works round bug in selection.
* src/expr.c (eval_cell_value): Fix sillyness of top left
corner stuff.
* src/expr.h: Added const to value_dump
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
new types; works round bug in selection.
* src/expr.c (eval_cell_value): Fix sillyness of top left
corner stuff.
* src/expr.h: Added const to value_dump
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
new types; works round bug in selection.
* src/expr.c (eval_cell_value): Fix sillyness of top left
corner stuff.
* src/expr.h: Added const to value_dump
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......
1999-05-15 Michael Meeks <michael@imaginator.com>
* ms-formula.c (ms_excel_parse_formula): Cleaned debug.
* boot.c (excel_init): Added write hooks.
(excel_save_95, excel_save_98, excel_save): Created.
1999-05-14 Michael Meeks <michael@imaginator.com>
* ms-formula.c (ms_excel_parse_formula): Finaly got the ARRAY
......
......@@ -16,6 +16,8 @@
#include <ctype.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "main.h"
#include "sheet.h"
#include "file.h"
......@@ -59,11 +61,65 @@ excel_load (const char *filename)
return wb;
}
static int
excel_save (Workbook *wb, const char *filename, eBiff_version ver)
{
MS_OLE *f;
int ans;
struct stat s;
if ((stat (filename, &s) != -1)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Saving over old files disabled for safety"));
return 0;
}
f = ms_ole_create (filename);
if (!f) {
char *str = g_strdup_printf ("%s %s",
_("Can't open"),
filename);
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR, str);
g_free (str);
return 0;
}
ans = ms_excel_write_workbook (f, wb, ver);
ms_ole_destroy (f);
if (ans)
printf ("Written successfully\n");
else
printf ("Error whilst writing\n");
return ans;
}
static int
excel_save_98 (Workbook *wb, const char *filename)
{
return excel_save (wb, filename, eBiffV8);
}
static int
excel_save_95 (Workbook *wb, const char *filename)
{
return excel_save (wb, filename, eBiffV7);
}
void
excel_init (void)
{
char *desc = _("Microsoft(R) Excel file format");
char *descr = _("Microsoft(R) Excel file format");
char *descr2 = _("Excel(R) 98 file format");
char *descr3 = _("Excel(R) 95 file format");
/* We register Excel format with a precendence of 100 */
file_format_register_open (100, desc, excel_probe, excel_load);
file_format_register_open (100, descr, excel_probe, excel_load);
if (gnumeric_debugging > 0) {
file_format_register_save (".xls", descr2, excel_save_98);
file_format_register_save (".xls", descr3, excel_save_95);
}
}
1999-05-15 Michael Meeks <michael@imaginator.com>
* ms-ole.c (ms_ole_create): Fixed stupid bug; created
ole file was opened read-only; also set mode = 'w'
Major re-working / bug-fixing...
1999-05-14 Michael Meeks <michael@imaginator.com>
* ms-ole.h: Updated types to forward references.
......
......@@ -442,7 +442,7 @@ ms_ole_create (const char *name)
guint32 sbd_startblock = 0, zero = 0;
char title[] ="Root Entry";
if ((file = open (name, O_RDONLY|O_CREAT|O_TRUNC|O_NONBLOCK,
if ((file = open (name, O_RDWR|O_CREAT|O_TRUNC|O_NONBLOCK,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) == -1)
{
printf ("Can't create file '%s'\n", name);
......@@ -457,10 +457,11 @@ ms_ole_create (const char *name)
}
f = g_new0 (MS_OLE, 1);
f->header.sbd_list = 0;
f->header.sbf_list = 0;
f->header.sbd_list = 0;
f->header.sbf_list = 0;
f->header.root_list = 0;
f->file_descriptor = file;
f->file_descriptor = file;
f->mode = 'w';
fstat(file, &st);
f->length = st.st_size;
if (f->length%BB_BLOCK_SIZE)
......@@ -493,17 +494,23 @@ ms_ole_create (const char *name)
SET_NUM_BBD_BLOCKS(f, 1);
SET_BBD_LIST(f, 0, 1);
/* the first BBD block : 1 */
for (lp=0;lp<BB_BLOCK_SIZE/4;lp++)
SET_GUINT32(GET_BB_START_PTR(f,1) + lp*4, END_OF_CHAIN);
SET_GUINT32(GET_BB_CHAIN_PTR(f,1), SPECIAL_BLOCK); /* Itself */
SET_GUINT32(GET_BB_CHAIN_PTR(f,2), END_OF_CHAIN); /* SBD chain */
SET_GUINT32(GET_BB_CHAIN_PTR(f,3), END_OF_CHAIN); /* SBF stream */
f->header.root_startblock = 0;
f->header.sbd_startblock = 2;
f->header.sbf_startblock = 3;
SET_ROOT_STARTBLOCK(f, f->header.root_startblock);
SET_SBD_STARTBLOCK (f, f->header.sbd_startblock);
/* The first PPS block : 0 */
/* f->header.root_list = g_array_new (0, 0, BBPtr);
g_array_append_val (f->header.root_list, 0); */
read_root_list (f);
/* The first PPS block : 0 */
lp = 0;
ptr = f->mem + BB_BLOCK_SIZE;
while (title[lp])
......@@ -521,15 +528,6 @@ ms_ole_create (const char *name)
PPS_SET_PREV(f, PPS_ROOT_BLOCK, PPS_END_OF_CHAIN);
PPS_SET_SIZE(f, PPS_ROOT_BLOCK, 0);
/* the first BBD block : 1 */
for (lp=0;lp<BB_BLOCK_SIZE/4;lp++)
SET_GUINT32(GET_BB_START_PTR(f,1) + lp*4, END_OF_CHAIN);
SET_GUINT32(GET_BB_CHAIN_PTR(f,1), SPECIAL_BLOCK); /* Itself */
SET_GUINT32(GET_BB_CHAIN_PTR(f,2), END_OF_CHAIN); /* SBD chain */
SET_GUINT32(GET_BB_CHAIN_PTR(f,3), END_OF_CHAIN); /* SBF stream */
/* the first SBD block : 2 */
for (lp=0;lp<(BB_BLOCK_SIZE/4);lp++)
SET_GUINT32(GET_BB_START_PTR(f,2) + lp*4, UNUSED_BLOCK);
......
......@@ -39,6 +39,8 @@ ms_excel_write_workbook (MS_OLE *file, Workbook *wb,
MS_OLE_STREAM *str;
BIFF_PUT *bp;
g_return_val_if_fail (wb, 0);
g_return_val_if_fail (file, 0);
g_return_val_if_fail (ver>=eBiffV7, 0);
if (!file || !wb) {
......
......@@ -902,7 +902,9 @@ ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
}
if (str) {
set_val = value_new_string (str);
#if FORMULA_DEBUG > 0
printf ("String '%s'\n", str);
#endif
g_free (str);
} else
set_val = value_new_string ("");
......
......@@ -902,7 +902,9 @@ ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
}
if (str) {
set_val = value_new_string (str);
#if FORMULA_DEBUG > 0
printf ("String '%s'\n", str);
#endif
g_free (str);
} else
set_val = value_new_string ("");
......
......@@ -469,6 +469,7 @@ value_array_resize (Value *v, guint width, guint height)
Value *newval;
Value ***tmp;
g_warning ("Totally untested");
g_return_if_fail (v);
g_return_if_fail (v->type == VALUE_ARRAY);
......@@ -645,9 +646,7 @@ eval_cell_value (Sheet *sheet, Value *value)
break;
case VALUE_ARRAY:
g_warning ("Check VALUE_ARRAY handling in eval_cell_value vs. Excel\n");
/* Return top left corner... */
res = value_duplicate (value->v.array.vals[0][0]);
res = value_duplicate (value);
break;
case VALUE_CELLRANGE:
......
......@@ -195,7 +195,7 @@ float_t value_get_as_float (const Value *v);
int value_get_as_int (const Value *v);
char *value_get_as_string (const Value *value);
void value_dump (Value *value);
void value_dump (const Value *value);
/* Area functions ( works on VALUE_RANGE or VALUE_ARRAY */
guint value_area_get_width (Value *v);
......
......@@ -94,7 +94,7 @@ file_format_register_save (char *extension, char *format_description, FileFormat
fs->format_description = format_description;
fs->save = save_fn;
gnumeric_file_savers = g_list_prepend (gnumeric_file_savers, fs);
gnumeric_file_savers = g_list_append (gnumeric_file_savers, fs);
}
/**
......
......@@ -639,7 +639,7 @@ forget_tree (ExprTree *tree)
}
void
value_dump (Value *value)
value_dump (const Value *value)
{
switch (value->type){
case VALUE_STRING:
......@@ -658,14 +658,14 @@ value_dump (Value *value)
int x, y;
printf ("Array: { ");
for (x = 0; x < value->v.array.x; x++)
for (y = 0; y < value->v.array.y; y++)
value_dump (&value->v.array.vals [x][y]);
for (y = 0; y < value->v.array.y; y++)
for (x = 0; x < value->v.array.x; x++)
value_dump (value->v.array.vals [x][y]);
printf ("}\n");
break;
}
case VALUE_CELLRANGE: {
CellRef *c = &value->v.cell_range.cell_a;
const CellRef *c = &value->v.cell_range.cell_a;
printf ("CellRange\n");
printf ("%p: %d,%d rel? %d,%d\n", c->sheet, c->col, c->row,
c->col_relative, c->row_relative);
......
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