4
4
* openoffice-read.c : import open/star calc files
6
* Copyright (C) 2002-2005 Jody Goldberg (jody@gnome.org)
6
* Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
7
7
* Copyright (C) 2006 Luciano Miguel Wolf (luciano.wolf@indt.org.br)
9
9
* This program is free software; you can redistribute it and/or
568
568
oo_cellref_parse (GnmCellRef *ref, char const *start, GnmParsePos const *pp)
570
570
char const *tmp1, *tmp2, *ptr = start;
571
/* sheet name cannot contain '.' a '\'' or a '\"' */
572
572
if (*ptr != '.') {
576
if (*ptr == '$') /* ignore abs vs rel sheet name */
578
tmp1 = strchr (ptr, '.');
581
if ((*ptr == '\'' || *ptr == '\"') && *ptr == tmp1[-1]) {
575
/* ignore abs vs rel for sheets */
580
* SheetName ::= [^\. ']+ | "'" ([^'] | "''")+ "'" */
584
/* missing close paren */
585
if (NULL == (tmp1 = strchr (tmp1, '\'')))
588
/* two in a row is the escape for a single */
589
if (tmp1[1] == '\'') {
594
/* If a name is quoted the entire named must be quoted */
598
accum = name = g_alloca (tmp1-ptr+1);
600
if ('\'' == (*accum++ = *ptr++))
605
if (NULL == (tmp1 = strchr (ptr, '.')))
607
name = g_alloca (tmp1-ptr+1);
608
strncpy (name, ptr, tmp1-ptr);
609
name[tmp1-ptr] = '\0';
587
name = g_alloca (tmp1-ptr+1);
588
strncpy (name, ptr, tmp1-ptr);
590
ptr = tmp1 + 1 + offset;
592
613
/* OpenCalc does not pre-declare its sheets, but it does have a
593
614
* nice unambiguous format. So if we find a name that has not
594
* been added yet add it. Reorder below.
615
* been added yet add it. Reorder below. */
596
616
ref->sheet = workbook_sheet_by_name (pp->wb, name);
597
617
if (ref->sheet == NULL) {
598
618
ref->sheet = sheet_new (pp->wb, name);
658
678
gboolean bool_val;
659
679
gnm_float float_val = 0;
660
680
int array_cols = -1, array_rows = -1;
661
int merge_cols = -1, merge_rows = -1;
681
int merge_cols = 1, merge_rows = 1;
662
682
GnmStyle *style = NULL;
663
683
char const *expr_string;
730
750
val = value_new_int (d_serial);
733
} else if (gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "time-value")) {
753
} else if (gsf_xml_in_namecmp (xin, attrs[0],
754
(state->ver == OOO_VER_OPENDOC) ? OO_NS_OFFICE : OO_NS_TABLE,
734
756
unsigned h, m, s;
735
if (3 == sscanf (attrs[1], "PT%uH%uM%uS", &h, &m, &s))
736
val = value_new_float (h + ((double)m / 60.) + ((double)s / 3600.));
757
if (3 == sscanf (attrs[1], "PT%uH%uM%uS", &h, &m, &s)) {
758
unsigned secs = h * 3600 + m * 60 + s;
759
val = value_new_float (secs / (gnm_float)86400);
737
761
} else if (gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "string-value"))
738
762
val = value_new_string (attrs[1]);
739
763
else if (oo_attr_float (xin, attrs,
756
780
if (style != NULL) {
757
781
gnm_style_ref (style);
758
782
if (state->col_inc > 1 || state->row_inc > 1) {
760
state->pos.eval.col, state->pos.eval.row,
761
state->pos.eval.col + state->col_inc - 1,
762
state->pos.eval.row + state->row_inc - 1);
783
range_init_cellpos_size (&tmp, &state->pos.eval,
784
state->col_inc, state->row_inc);
763
785
sheet_style_set_range (state->pos.sheet, &tmp, style);
764
} else if (merge_cols > 0 || merge_rows > 0) {
767
state->pos.eval.col, state->pos.eval.row,
768
state->pos.eval.col + merge_cols - 1,
769
state->pos.eval.row + merge_rows - 1);
786
} else if (merge_cols > 1 || merge_rows > 1) {
787
range_init_cellpos_size (&tmp, &state->pos.eval,
788
merge_cols, merge_rows);
770
789
sheet_style_set_range (state->pos.sheet, &tmp, style);
772
791
sheet_style_set_pos (state->pos.sheet,
779
798
state->pos.eval.col, state->pos.eval.row);
781
800
if (array_cols > 0 || array_rows > 0) {
782
if (array_cols < 0) {
801
if (array_cols <= 0) {
784
803
oo_warning (xin, _("Invalid array expression does not specify number of columns."));
785
} else if (array_rows < 0) {
804
} else if (array_rows <= 0) {
787
806
oo_warning (xin, _("Invalid array expression does not specify number of rows."));
814
833
/* store the content as a string */
815
834
state->simple_content = TRUE;
817
if (merge_cols > 0 && merge_rows > 0) {
820
state->pos.eval.col, state->pos.eval.row,
821
state->pos.eval.col + merge_cols - 1,
822
state->pos.eval.row + merge_rows - 1);
823
sheet_merge_add (state->pos.sheet, &r, FALSE,
836
if (merge_cols > 1 || merge_rows > 1) {
837
range_init_cellpos_size (&tmp, &state->pos.eval,
838
merge_cols, merge_rows);
839
sheet_merge_add (state->pos.sheet, &tmp, FALSE, NULL);
1551
1566
frame_offset[2] = (width/col->size_pts);
1552
1567
frame_offset[3] = (height/row->size_pts);
1554
sheet_object_anchor_init (&state->cur_frame.anchor, &cell_base, frame_offset, NULL, SO_DIR_DOWN_RIGHT);
1569
sheet_object_anchor_init (&state->cur_frame.anchor, &cell_base, frame_offset, NULL, GOD_ANCHOR_DIR_DOWN_RIGHT);
2440
2455
state.cur_frame.has_legend = FALSE;
2442
2457
if (state.ver == OOO_VER_OPENDOC) {
2443
GsfInput *meta_file =
2444
meta_file = gsf_infile_child_by_name (zip, "meta.xml");
2445
if (meta_file != NULL) {
2458
GsfInput *meta_file = gsf_infile_child_by_name (zip, "meta.xml");
2459
if (NULL != meta_file) {
2446
2460
meta_data = gsf_doc_meta_data_new ();
2447
2461
err = gsf_opendoc_metadata_read (meta_file, meta_data);
2448
2462
if (NULL != err) {
2459
if (styles != NULL) {
2473
if (NULL != styles) {
2460
2474
GsfXMLInDoc *doc = gsf_xml_in_doc_new (styles_dtd, gsf_ooo_ns);
2461
2475
gsf_xml_in_doc_parse (doc, styles, &state);
2462
2476
gsf_xml_in_doc_free (doc);