changeset 12088:1e4dd5562145 octave-forge

gnumeric read support added for OCT interface
author prnienhuis
date Tue, 01 Oct 2013 21:50:53 +0000
parents 46e8ff7a04d9
children f3a0a3ba223d
files main/io/inst/xls2oct.m main/io/inst/xlsclose.m main/io/inst/xlsfinfo.m main/io/inst/xlsopen.m
diffstat 4 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/main/io/inst/xls2oct.m	Tue Oct 01 21:50:17 2013 +0000
+++ b/main/io/inst/xls2oct.m	Tue Oct 01 21:50:53 2013 +0000
@@ -200,7 +200,13 @@
     [rawarr, xls, rstatus] = __UNO_spsh2oct__ (xls, wsh, datrange, spsh_opts);
   elseif (strcmp (xls.xtype, "OCT"))
     ## Read xls file tru native Octave
-    [rawarr, xls, rstatus] = __OCT_xlsx2oct__ (xls, wsh, datrange, spsh_opts);
+    if (strcmpi (xls.app, 'xlsx'))
+      [rawarr, xls, rstatus] = __OCT_xlsx2oct__ (xls, wsh, datrange, spsh_opts);
+    elseif (strcmpi (xls.app, 'gnumeric'))
+      [rawarr, xls, rstatus] = __OCT_gnm2oct__ (xls, wsh, datrange);
+    elseif (strcmpi (xls.app, 'ods'))
+      [rawarr, xls, rstatus] = __OCT_ods2oct__ (xls, wsh, datrange, spsh_opts);
+    endif
   ##elseif ---- <Other interfaces here>
     ## Call to next interface
   else
--- a/main/io/inst/xlsclose.m	Tue Oct 01 21:50:17 2013 +0000
+++ b/main/io/inst/xlsclose.m	Tue Oct 01 21:50:53 2013 +0000
@@ -79,9 +79,15 @@
 ## 2012-10-24 Style fixes
 ## 2012-12-18 Improved error/warning messages
 ## 2013-09-30 OCT interface added
+## 2013-10-01 Warn for empty struct input
 
 function [ xls ] = xlsclose (xls, varargs)
 
+  if (isempty (xls))
+    warning ("xlsclose: file pointer struct was already closed");
+    return
+  endif
+
   force = 0;
 
   if (nargin > 1)
--- a/main/io/inst/xlsfinfo.m	Tue Oct 01 21:50:17 2013 +0000
+++ b/main/io/inst/xlsfinfo.m	Tue Oct 01 21:50:53 2013 +0000
@@ -1,4 +1,4 @@
-## Copyright (C) 2009,2010,2011,2012 Philip Nienhuis <pr.nienhuis at users.sf.net>
+## Copyright (C) 2009,2010,2011,2012,2013 Philip Nienhuis <pr.nienhuis at users.sf.net>
 ##
 ## This program is free software; you can redistribute it and/or modify it under
 ## the terms of the GNU General Public License as published by the Free Software
@@ -88,6 +88,7 @@
 ## 2012-02-25 Added info on occupied ranges to sh_names outarg for all interfaces
 ## 2012-10-12 Moved all interface-specific code into ./private subfuncs
 ## 2012-10-24 Style fixes
+## 2013-10-01 OCT interface added for gnumeric
 
 function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[])
 
@@ -118,6 +119,9 @@
   elseif (strcmp (xls.xtype, "UNO"))
     [sh_names] = __UNO_spsh_info__ (xls);
 
+  elseif (strcmp (xls.xtype, "OCT"))
+    [sh_names] = __OCT_spsh_info__ (xls);
+
 ##elseif   <Other Excel interfaces below>
 
   else
--- a/main/io/inst/xlsopen.m	Tue Oct 01 21:50:17 2013 +0000
+++ b/main/io/inst/xlsopen.m	Tue Oct 01 21:50:53 2013 +0000
@@ -126,6 +126,7 @@
 ##     ''     Fixed wrong error message about OXS and UNO not being supported
 ## 2013-09-30 Native Octave interface ("OCT") for reading .xlsx
 ##     ''     Adapted header to OCT (also Excel 2013 is supported)
+## 2013-10-01 Some adaptations for gnumeric
 
 function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[])
 
@@ -207,11 +208,11 @@
   ## Supported interfaces determined; Excel file type check moved to separate interfaces.
   chk1 = strcmpi (filename(end-3:end), ".xls");       ## Regular (binary) BIFF 
   chk2 = strcmpi (filename(end-4:end-1), ".xls");     ## Zipped XML / OOXML
-  chk5 = strcmpi (filename(end-9:end), "gnumeric");   ## Zipped XML / gnumeric
+  chk5 = strcmpi (filename(end-8:end), ".gnumeric");  ## Zipped XML / gnumeric
 
   ## Check if Excel file exists. First check for file name suffix
   has_suffix = 1;
-  sfxpos = regexp (filnam, '(\.xls|\.gnumeric)');
+  sfxpos = regexp (filename, '(\.xls|\.gnumeric)');
   if (! isempty (sfxpos))
     ## .xls or .xls[x,m,b] is there, but at the right(most) position?
     if (! sfxpos(end) >= length (filename) - 4)
@@ -285,14 +286,14 @@
   xlssupport = 0;
 
   ## Interface preference order is defined below: currently COM -> POI -> JXL -> OXS -> UNO -> OCT
-  ## chk1 & chk2 (xls file type) are conveyed depending on interface capabilities
+  ## chk1, chk2  (xls file type) and chk5 (gnumeric) are conveyed depending on interface capabilities
 
-  if ((! xlssupport) && xlsinterfaces.COM)
+  if ((! xlssupport) && xlsinterfaces.COM && (! chk5))
     ## Excel functioning has been tested above & file exists, so we just invoke it.
     [ xls, xlssupport, lastintf ] = __COM_spsh_open__ (xls, xwrite, filename, xlssupport);
   endif
 
-  if ((! xlssupport) && xlsinterfaces.POI)
+  if ((! xlssupport) && xlsinterfaces.POI && (! chk5))
     if (chk1 || chk2)
       [ xls, xlssupport, lastintf ] = __POI_spsh_open__ (xls, xwrite, filename, xlssupport, chk1, chk2, xlsinterfaces);
     else
@@ -300,7 +301,7 @@
     endif
   endif
 
-  if ((! xlssupport) && xlsinterfaces.JXL)
+  if ((! xlssupport) && xlsinterfaces.JXL && (! chk5))
     if (chk1)
       [ xls, xlssupport, lastintf ] = __JXL_spsh_open__ (xls, xwrite, filename, xlssupport, chk1);
     else
@@ -308,7 +309,7 @@
     endif
   endif
 
-  if ((! xlssupport) && xlsinterfaces.OXS)
+  if ((! xlssupport) && xlsinterfaces.OXS && (! chk5))
     if (chk1)
       [ xls, xlssupport, lastintf ] = __OXS_spsh_open__ (xls, xwrite, filename, xlssupport, chk1);
     else
@@ -316,14 +317,14 @@
     endif
   endif
 
-  if ((! xlssupport) && xlsinterfaces.UNO)
+  if ((! xlssupport) && xlsinterfaces.UNO && (! chk5))
     [ xls, xlssupport, lastintf ] = __UNO_spsh_open__ (xls, xwrite, filename, xlssupport);
   endif
 
 
   if ((! xlssupport) && xlsinterfaces.OCT)
-    if (chk2)
-      [ xls, xlssupport, lastintf ] = __OCT_spsh_open__ (xls, xwrite, filename, xlssupport, chk2);
+    if (chk2 || chk5)
+      [ xls, xlssupport, lastintf ] = __OCT_spsh_open__ (xls, xwrite, filename, xlssupport, chk2, 0, chk5);
     else
       error ("xlsopen.m: unsupported file format for OCT / native Octave")
     endif