struct sheet_detail
{
xmlChar *name;
+
+ int start_col;
+ int stop_col;
+ int start_row;
+ int stop_row;
+
+ int maxcol;
+ int maxrow;
};
return gr->sheets[n].name;
}
+
+static void process_node (struct gnumeric_reader *r);
+
+
const char *
gnumeric_get_sheet_range (struct spreadsheet *s, int n)
{
+ int ret;
struct gnumeric_reader *gr = (struct gnumeric_reader *) s;
+
assert (n < s->sheets);
- return "I havent the fogiest idea";
-}
+ while (
+ (gr->sheets[n].stop_col == -1)
+ &&
+ (1 == (ret = xmlTextReaderRead (gr->xtr)))
+ )
+ {
+ process_node (gr);
+ }
-static void process_node (struct gnumeric_reader *r);
+ return create_cell_ref (
+ gr->sheets[n].start_col,
+ gr->sheets[n].start_row,
+ gr->sheets[n].stop_col,
+ gr->sheets[n].stop_row);
+}
static void
switch ( r->state)
{
case STATE_PRE_INIT:
+ r->sheet_index = -1;
if (0 == xmlStrcasecmp (name, _xml("gnm:SheetNameIndex")) &&
XML_READER_TYPE_ELEMENT == r->node_type)
{
if (0 == xmlStrcasecmp (name, _xml("gnm:SheetName")) &&
XML_READER_TYPE_ELEMENT == r->node_type)
{
+ struct sheet_detail *sd ;
r->spreadsheet.sheets++;
r->sheets = xrealloc (r->sheets, r->spreadsheet.sheets * sizeof *r->sheets);
+ sd = &r->sheets[r->spreadsheet.sheets - 1];
+ sd->start_col = sd->stop_col = sd->start_row = sd->stop_row = -1;
}
else if (0 == xmlStrcasecmp (name, _xml("gnm:SheetNameIndex")) &&
XML_READER_TYPE_END_ELEMENT == r->node_type)
{
r->state = STATE_INIT;
}
+ else if (0 == xmlStrcasecmp (name, _xml("gnm:Sheet")) &&
+ XML_READER_TYPE_END_ELEMENT == r->node_type)
+ {
+ r->state = STATE_INIT;
+ }
else if (XML_READER_TYPE_TEXT == r->node_type)
{
- if ( r->target_sheet != NULL)
+ if ( r->target_sheet != NULL)
{
xmlChar *value = xmlTextReaderValue (r->xtr);
if ( 0 == xmlStrcmp (value, r->target_sheet))
r->state = STATE_SHEET_FOUND;
free (value);
}
- else if (r->target_sheet_index == r->sheet_index)
+ else if (r->target_sheet_index == r->sheet_index + 1)
{
r->state = STATE_SHEET_FOUND;
}
else if (0 == xmlStrcasecmp (name, _xml("gnm:Sheet")) &&
XML_READER_TYPE_END_ELEMENT == r->node_type)
{
- r->state = STATE_INIT;
+ r->state = STATE_INIT;
}
break;
case STATE_MAXROW:
else if (r->node_type == XML_READER_TYPE_TEXT)
{
xmlChar *value = xmlTextReaderValue (r->xtr);
+ r->sheets[r->sheet_index].maxrow = _xmlchar_to_int (value);
xmlFree (value);
}
break;
else if (r->node_type == XML_READER_TYPE_TEXT)
{
xmlChar *value = xmlTextReaderValue (r->xtr);
+ r->sheets[r->sheet_index].maxcol = _xmlchar_to_int (value);
xmlFree (value);
}
break;
attr = xmlTextReaderGetAttribute (r->xtr, _xml ("Row"));
r->row = _xmlchar_to_int (attr);
free (attr);
+ if (r->sheets[r->sheet_index].start_row == -1)
+ {
+ r->sheets[r->sheet_index].start_row = r->row;
+ }
+
+ if (r->sheets[r->sheet_index].start_col == -1)
+ {
+ r->sheets[r->sheet_index].start_col = r->col;
+ }
}
else if (0 == xmlStrcasecmp (name, _xml("gnm:Cells")) &&
XML_READER_TYPE_END_ELEMENT == r->node_type)
- r->state = STATE_SHEET_NAME;
-
+ {
+ r->sheets[r->sheet_index].stop_col = r->col;
+ r->sheets[r->sheet_index].stop_row = r->row;
+ r->state = STATE_SHEET_NAME;
+ }
break;
case STATE_CELL:
if (0 == xmlStrcasecmp (name, _xml("gnm:Cell")) &&
r->stop_row = -1;
}
-
r->target_sheet = BAD_CAST opts->sheet_name;
r->target_sheet_index = opts->sheet_index;
r->row = r->col = -1;
- r->sheet_index = 0;
+ r->sheet_index = -1;
/* Advance to the start of the cells for the target sheet */
while ( (r->state != STATE_CELL || r->row < r->start_row )
free (value);
}
-
/* If a range has been given, then use that to calculate the number
of cases */
if ( opts->cell_range)