GnumericWorkbookPtr gnumeric_load(const char *fname) { GOIOContext *io_context = go_io_context_new (cc); char *uri = go_filename_to_uri (fname); //printf("Have uri %s\n", uri); WorkbookView *wbv = wb_view_new_from_uri (uri, NULL, io_context, NULL); g_free (uri); //printf("Have workbook view\n"); g_object_unref (io_context); return wbv; }
/** * gnm_app_workbook_get_by_name: * @name: the workbook name. * @ref_uri: * * Returns: (transfer none): the #Workbook or %NULL. **/ Workbook * gnm_app_workbook_get_by_name (char const *name, char const *ref_uri) { Workbook *wb; char *filename = NULL; if (name == NULL || *name == 0) return NULL; /* Try as URI. */ wb = gnm_app_workbook_get_by_uri (name); if (wb) goto out; filename = g_filename_from_utf8 (name, -1, NULL, NULL, NULL); /* Try as absolute filename. */ if (filename && g_path_is_absolute (filename)) { char *uri = go_filename_to_uri (filename); if (uri) { wb = gnm_app_workbook_get_by_uri (uri); g_free (uri); } if (wb) goto out; } if (filename && ref_uri) { char *rel_uri = go_url_encode (filename, 1); char *uri = go_url_resolve_relative (ref_uri, rel_uri); g_free (rel_uri); if (uri) { wb = gnm_app_workbook_get_by_uri (uri); g_free (uri); } if (wb) goto out; } out: g_free (filename); return wb; }
int gnumeric_save(GnumericWorkbookPtr workbook, const char *fname, const char *format) { WorkbookView *wbv = (WorkbookView *)workbook; int res = 0; GOFileSaver *fs = NULL; if (format!=NULL) { fs = go_file_saver_for_id(format); if (fs == NULL) { fs = go_file_saver_for_file_name (format); if (fs == NULL) { res = 1; g_printerr (_("Unknown exporter '%s'.\n"), format); return 1; } } } if (fs==NULL) { fs = go_file_saver_for_file_name (fname); if (fs == NULL) { res = 2; g_printerr (_("Unable to guess exporter to use for '%s'.\n" "Try --list-exporters to see a list of possibilities.\n"), fname); return 1; } } //g_print ("Using exporter %s\n", //go_file_saver_get_id (fs)); if (go_file_saver_get_save_scope (fs) != GO_FILE_SAVE_WORKBOOK) { g_printerr (_("Selected exporter (%s) does not support saving multiple sheets in one file.\n" "Only the current sheet will be saved.\n"), go_file_saver_get_id (fs)); } char *outfile = go_filename_to_uri (fname); if (fname[0]=='-') { res = !wb_view_save_as (wbv, fs, "fd://1", cc); } else { res = !wb_view_save_as (wbv, fs, outfile, cc); } g_free (outfile); return 0; }