{
if ( r->target_sheet != NULL)
{
- printf ("%s:%d\n", __FILE__, __LINE__);
xmlChar *value = xmlTextReaderValue (r->xtr);
if ( 0 == xmlStrcmp (value, r->target_sheet))
r->state = STATE_SHEET_FOUND;
}
else if (r->target_sheet_index == r->sheet_index)
{
- printf ("%s:%d %d\n", __FILE__, __LINE__, r->sheet_index);
r->state = STATE_SHEET_FOUND;
}
}
struct file *file = &ia->file;
struct separators_page *sepp = &ia->separators;
- int col;
int rows = 0;
- struct ccase *c;
-
- sepp->column_cnt = dict_get_var_cnt (ssp->dict);
- sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
- for (col = 0; col < sepp->column_cnt ; ++col)
+ if (ssp->dict)
{
- const struct variable *var = dict_get_var (ssp->dict, col);
- sepp->columns[col].name = xstrdup (var_get_name (var));
- sepp->columns[col].contents = NULL;
- }
+ struct ccase *c;
+ int col;
- for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
- {
- rows++;
+ sepp->column_cnt = dict_get_var_cnt (ssp->dict);
+ sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
for (col = 0; col < sepp->column_cnt ; ++col)
{
- char *ss;
const struct variable *var = dict_get_var (ssp->dict, col);
+ sepp->columns[col].name = xstrdup (var_get_name (var));
+ sepp->columns[col].contents = NULL;
+ }
- sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
- sizeof (struct substring) * rows);
+ for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
+ {
+ rows++;
+ for (col = 0; col < sepp->column_cnt ; ++col)
+ {
+ char *ss;
+ const struct variable *var = dict_get_var (ssp->dict, col);
- ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict),
- var_get_print_format (var));
+ sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
+ sizeof (struct substring) * rows);
- sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
- }
+ ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict),
+ var_get_print_format (var));
- if (rows > MAX_PREVIEW_LINES)
- {
- case_unref (c);
- break;
+ sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
+ }
+
+ if (rows > MAX_PREVIEW_LINES)
+ {
+ case_unref (c);
+ break;
+ }
}
}
-
+
file->line_cnt = rows;
casereader_destroy (ssp->reader);
ssp->reader = NULL;
ia->file.type = FTYPE_ODS;
}
- if (creader)
+ if (creader && dict)
{
struct sheet_spec_page *ssp = &ia->sheet_spec;
ssp->dict = dict;
void
post_sheet_spec_page (struct import_assistant *ia)
{
- char col_start[10];
- char col_stop[10];
int row_start = -1;
int row_stop = -1;
+ int col_start = -1;
+ int col_stop = -1;
GtkBuilder *builder = ia->asst.builder;
struct file *file = &ia->file;
struct sheet_spec_page *ssp = &ia->sheet_spec;
- struct casereader *creader;
- struct dictionary *dict;
+ struct casereader *creader = NULL;
+ struct dictionary *dict = NULL;
GtkWidget *sheet_entry = get_widget_assert (builder, "sheet-entry");
GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
gint num = atoi (gtk_entry_get_text (GTK_ENTRY (sheet_entry)));
const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry));
-
- sscanf (range, "%[a-zA-Z]%d:%[a-zA-Z]%d", col_start, &row_start, col_stop, &row_stop);
+
+
+ if ( num < 1 )
+ num = 1;
ssp->opts.sheet_name = NULL;
- ssp->opts.cell_range = NULL;
+ ssp->opts.cell_range = range;
ssp->opts.sheet_index = num;
- if ( row_start > 0 && row_stop > 0)
- ssp->opts.cell_range = xasprintf ("%s%d:%s%d", col_start, row_start, col_stop, row_stop);
+ if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop))
+ {
+ ssp->opts.cell_range = range;
+ }
ssp->sri.file_name = file->file_name;
ssp->sri.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox));
ssp->dict = dict;
ssp->reader = creader;
- update_assistant (ia);
+ if (creader && dict)
+ {
+ update_assistant (ia);
+ }
+ else
+ {
+ GtkWidget * dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("An error occurred reading the spreadsheet file."));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
}
return;
}
- printf ("%s:%d %s\n", __FILE__, __LINE__, ia->file.file_name);
-
init_assistant (ia, parent_window);
if ( ia->file.type == FTYPE_TEXT)
{