1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2007, 2009, 2010, 2011, 2013, 2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "spreadsheet-reader.h"
25 #include "data/gnumeric-reader.h"
26 #include "data/ods-reader.h"
27 #include "libpspp/assertion.h"
28 #include "libpspp/str.h"
30 #include "gl/xalloc.h"
31 #include "gl/c-xvasprintf.h"
32 #include "gl/intprops.h"
35 spreadsheet_ref (struct spreadsheet
*s
)
42 spreadsheet_unref (struct spreadsheet
*s
)
44 if (--s
->ref_cnt
== 0)
50 spreadsheet_make_reader (struct spreadsheet
*s
,
51 const struct spreadsheet_read_options
*opts
)
53 return s
->make_reader (s
, opts
);
57 spreadsheet_get_sheet_name (struct spreadsheet
*s
, int n
)
59 return s
->get_sheet_name (s
, n
);
64 spreadsheet_get_sheet_range (struct spreadsheet
*s
, int n
)
66 return s
->get_sheet_range (s
, n
);
70 spreadsheet_get_sheet_n_sheets (struct spreadsheet
*s
)
72 return s
->get_sheet_n_sheets (s
);
76 spreadsheet_get_sheet_n_rows (struct spreadsheet
*s
, int n
)
78 return s
->get_sheet_n_rows (s
, n
);
82 spreadsheet_get_sheet_n_columns (struct spreadsheet
*s
, int n
)
84 return s
->get_sheet_n_columns (s
, n
);
88 spreadsheet_get_cell (struct spreadsheet
*s
, int n
, int row
, int column
)
90 return s
->get_sheet_cell (s
, n
, row
, column
);
95 create_cell_ref (int col0
, int row0
)
97 if (col0
< 0 || row0
< 0)
100 char s
[F26ADIC_STRLEN_MAX
+ INT_STRLEN_BOUND (row0
) + 1];
101 str_format_26adic (col0
+ 1, true, s
, sizeof s
);
102 size_t len
= strlen (s
);
103 snprintf (s
+ len
, sizeof s
- len
, "%d", row0
+ 1);
109 create_cell_range (int col0
, int row0
, int coli
, int rowi
)
111 char *s0
= create_cell_ref (col0
, row0
);
112 char *si
= create_cell_ref (coli
, rowi
);
114 char *s
= c_xasprintf ("%s:%s", s0
, si
);
123 /* Convert a cell reference in the form "A1:B2", to
124 integers. A1 means column zero, row zero.
125 B1 means column 1 row 0. AA1 means column 26, row 0.
128 convert_cell_ref (const char *ref
,
129 int *col0
, int *row0
,
130 int *coli
, int *rowi
)
138 int n
= sscanf (ref
, "%4[a-zA-Z]%d:%4[a-zA-Z]%d",
144 *col0
= str_parse_26adic (startcol
);
145 *coli
= str_parse_26adic (stopcol
);
146 *row0
= startrow
- 1;
147 *rowi
= stoprow
- 1 ;