COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libgnumeric/test_gnumeric.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 #include <coopy/Dbg.h>
00005 #include <coopy/CsvSheet.h>
00006 #include <coopy/GnumericSheet.h>
00007 
00008 extern "C" {
00009 #include "coopy/gnumeric_link.h"
00010 }
00011 
00012 using namespace coopy::store;
00013 using namespace coopy::store::gnumeric;
00014 using namespace std;
00015 
00016 int main_alt() {
00017   gnumeric_init();
00018   GnumericWorkbookPtr book2 = gnumeric_create();
00019   GnumericSheetPtr sheet2 = gnumeric_add_sheet(book2,"bob");
00020   gnumeric_sheet_set_cell_as_string(sheet2,0,0,"10.5");
00021   GnumericStylePtr p = gnumeric_sheet_get_style(sheet2,0,0);
00022   gnumeric_style_set_font_bold(p,1);
00023   gnumeric_sheet_set_style(sheet2,p,0,0);
00024   gnumeric_save(book2,"book2.xls",NULL);
00025   gnumeric_free(book2);
00026   gnumeric_fini();
00027 
00028   return 0;
00029 }
00030 
00031 int main(int argc, char *argv[]) {
00032   if (argc>1) {
00033     if (string(argv[1])=="--verbose") {
00034       coopy_set_verbose(true);
00035       argc--;
00036       argv++;
00037     }
00038   }
00039 
00040   if (argc<3) {
00041     printf("Call as:\n");
00042     printf("  test_gnumeric template.xls target.xls\n");
00043     return main_alt();
00044   }
00045   const char *template_name = argv[1];
00046   const char *target_name = argv[2];
00047 
00048   gnumeric_init();
00049 
00050   GnumericWorkbookPtr book = gnumeric_load(template_name);
00051   CsvSheet data;
00052   data.addField("1",false);
00053   data.addField("2",false);
00054   data.addRecord();
00055   data.addField("3",false);
00056   data.addField("4",false);
00057   data.addRecord();
00058   SheetStyle style;
00059   string sdata = data.encode(style);
00060   char *start = (char*)(sdata.c_str());
00061   char *stop = (char*)(start+sdata.length());
00062   gnumeric_overlay_csv(book,start,stop);
00063 
00064   GnumericSheet sheet(gnumeric_get_sheet(book,0));
00065   for (int y=0; y<sheet.height(); y++) {
00066     for (int x=0; x<sheet.width(); x++) {
00067       printf("[%s] ", sheet.cellString(x,y).c_str());
00068     }
00069     printf("\n");
00070   }
00071   printf("\n");
00072   // try the following, with one column formated as text, the other as number
00073   sheet.cellString(0,0,"00100");
00074   sheet.cellString(1,0,"00100");
00075   for (int y=0; y<sheet.height(); y++) {
00076     for (int x=0; x<sheet.width(); x++) {
00077       printf("[%s] ", sheet.cellString(x,y).c_str());
00078     }
00079     printf("\n");
00080   }
00081   printf("\n");
00082   gnumeric_move_column(gnumeric_get_sheet(book,0),0,1);
00083   for (int y=0; y<sheet.height(); y++) {
00084     for (int x=0; x<sheet.width(); x++) {
00085       printf("[%s] ", sheet.cellString(x,y).c_str());
00086     }
00087     printf("\n");
00088   }
00089   gnumeric_save(book,target_name,NULL);
00090   gnumeric_free(book);
00091 
00092   gnumeric_fini();
00093 
00094   return 0;
00095 }
00096 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines