{
struct spreadsheet spreadsheet;
struct zip_reader *zreader;
- int ref_cnt;
+
int target_sheet_index;
xmlChar *target_sheet_name;
};
void
-ods_destroy (struct spreadsheet *s)
+ods_unref (struct spreadsheet *s)
{
struct ods_reader *r = (struct ods_reader *) s;
- if (--r->ref_cnt == 0)
+ if (--s->ref_cnt == 0)
{
int i;
zip_reader_destroy (r->zreader);
free (r->sheets);
+
+ free (s->file_name);
free (r);
}
process_node (r, or);
}
- return create_cell_ref (
+ return create_cell_range (
r->sheets[n].start_col,
r->sheets[n].start_row,
r->sheets[n].stop_col,
r->target_sheet_name = NULL;
- ods_destroy (&r->spreadsheet);
+ ods_unref (&r->spreadsheet);
}
*/
static void
convert_xml_to_value (struct ccase *c, const struct variable *var,
- const struct xml_value *xmv)
+ const struct xml_value *xmv, int col, int row)
{
union value *v = case_data_rw (c, var);
const char *text = xmv->value ?
CHAR_CAST (const char *, xmv->value) : CHAR_CAST (const char *, xmv->text);
-
- free (data_in (ss_cstr (text), "UTF-8",
+ char *m = data_in (ss_cstr (text), "UTF-8",
fmt->type,
v,
var_get_width (var),
- "UTF-8"));
+ "UTF-8");
+
+ if (m)
+ {
+ char buf [FMT_STRING_LEN_MAX + 1];
+ char *cell = create_cell_ref (col, row);
+
+ msg (MW, _("Cannot convert the value in the spreadsheet cell %s to format (%s): %s"),
+ cell, fmt_to_string (fmt, buf), m);
+ free (cell);
+ }
+ free (m);
}
}
}
sheet_count = get_sheet_count (zr);
r->zreader = zr;
- r->ref_cnt = 1;
+ r->spreadsheet.ref_cnt = 1;
xtr = init_reader (r, report_errors);
if (xtr == NULL)
r->n_allocated_sheets = 0;
r->sheets = NULL;
- r->spreadsheet.file_name = filename;
+ r->spreadsheet.file_name = strdup (filename);
return &r->spreadsheet;
error:
assert (r);
r->read_names = opts->read_names;
ds_init_empty (&r->ods_errs);
- ++r->ref_cnt;
+ ++r->spreadsheet.ref_cnt;
xtr = init_reader (r, true);
if ( xtr == NULL)
{
const struct variable *var = dict_get_var (r->dict, i);
- convert_xml_to_value (r->first_case, var, &var_spec[i].firstval);
+ convert_xml_to_value (r->first_case, var, &var_spec[i].firstval,
+ r->rsd.col - n_var_specs + i,
+ r->rsd.row - 1);
}
/* Read in the first row of data */
struct xml_value *xmv = xzalloc (sizeof *xmv);
xmv->text = xmlTextReaderValue (r->rsd.xtr);
xmv->value = val_string;
- xmv->type = type;
val_string = NULL;
+ xmv->type = type;
+ type = NULL;
for (col = 0; col < r->rsd.col_span; ++col)
{
break;
var = dict_get_var (r->dict, idx);
- convert_xml_to_value (c, var, xmv);
+ convert_xml_to_value (c, var, xmv, idx + r->start_col, r->rsd.row - 1);
}
xmlFree (xmv->text);
break;
}
+ xmlFree (type);
+ xmlFree (val_string);
+
return c;
}
#endif