1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 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/>. */
26 #include <data/spreadsheet-reader.h>
27 #include <data/gnumeric-reader.h>
28 #include <data/ods-reader.h>
38 static const struct option long_opts[] =
40 {"refcheck", no_argument, NULL, OPT_REFCHECK},
41 {"reverse", no_argument, NULL, OPT_REVERSE},
42 {"sheet", required_argument, NULL, OPT_SHEET},
43 {"metadata", no_argument, NULL, OPT_METADATA},
48 main (int argc, char **argv)
50 set_program_name (argv[0]);
52 bool refcheck = false;
55 bool get_n_sheets = false;
57 while ((opt = getopt_long (argc, argv, "", long_opts, NULL)) != -1)
71 sheet = atoi (optarg);
74 fprintf (stderr, "Usage: spreadsheet-test [opts] file\n");
81 fprintf (stderr, "Usage: spreadsheet-test [-s n] file\n");
85 struct spreadsheet *ss = NULL;
87 char *ext = strrchr (argv[optind], '.');
90 if (0 == strcmp (ext, ".ods"))
91 ss = ods_probe (argv[optind], true);
92 else if (0 == strcmp (ext, ".gnumeric"))
93 ss = gnumeric_probe (argv[optind], true);
100 int n_sheets = spreadsheet_get_sheet_n_sheets (ss);
101 printf ("Number of sheets: %d\n", n_sheets);
104 int rows = spreadsheet_get_sheet_n_rows (ss, sheet);
105 int columns = spreadsheet_get_sheet_n_columns (ss, sheet);
107 printf ("Rows %d; Columns %d\n", rows, columns);
108 for (int r_ = 0; r_ < rows; r_++)
110 int r = reverse ? (rows - r_ - 1) : r_;
111 for (int c_ = 0; c_ < columns; c_++)
113 int c = reverse ? (columns - c_ - 1) : c_ ;
114 char *s = spreadsheet_get_cell (ss, sheet, r, c);
118 sscanf (s, "%d:%d", &row, &col);
124 fputs (s ? s : "", stdout);
125 if (c_ < columns - 1)
138 rows = spreadsheet_get_sheet_n_rows (ss, sheet);
139 columns = spreadsheet_get_sheet_n_columns (ss, sheet);
142 spreadsheet_unref (ss);