changeset 12407:eb45107f2930 octave-forge

Fix regexp for reading strings from sharedStrings.xml
author prnienhuis
date Tue, 18 Mar 2014 22:35:21 +0000
parents b93aabf83e77
children b169673b4d96
files main/io/inst/private/__OCT_xlsx2oct__.m
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/main/io/inst/private/__OCT_xlsx2oct__.m	Tue Mar 18 22:34:38 2014 +0000
+++ b/main/io/inst/private/__OCT_xlsx2oct__.m	Tue Mar 18 22:35:21 2014 +0000
@@ -1,5 +1,5 @@
-## Copyright (C) 2013 Markus Bergholz
-## Parts Copyright (C) 2013 Philip Nienhuis
+## Copyright (C) 2013,2014 Markus Bergholz
+## Parts Copyright (C) 2013,2014 Philip Nienhuis
 ## 
 ## 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
@@ -47,7 +47,8 @@
 ## 2013-12-14 (PRN) Adapt regexpr for values (include "n" as value type)
 ##     ''     Fix regexpr for strings ( <v>\d? => <v>\d+ )
 ##     ''     Add isfinite() check before attempt to process fixed strings
-## 2013-12-19 (MB) Replace call to __col_str_to_number with __OCT_cc__
+## 2013-12-19 (MB) Replace call to __col_str_to_number with __OCT_cc__
+## 2014-03-18 (PRN) Fix regexp for reading strings from sharedStrings.xml
 
 function [ raw, xls, rstatus ] = __OCT_xlsx2oct__ (xls, wsh, crange='', spsh_opts)
 
@@ -69,7 +70,7 @@
       if (isempty (id))
         error ("xls2oct: cannot find sheet '%s' in file %s", wsh, xls.filename);
       else
-        wsh = xls.sheets.rid(id);
+        wsh = xls.sheets.sheetid(id);
       endif
     # endif
   elseif (wsh > numel (xls.sheets.sh_names))
@@ -92,7 +93,9 @@
     catch
       ## No sharedStrings.xml; implies no "fixed" strings (computed strings can still be there)
       strings = "";
-    end_try_catch
+    end_try_catch
+  else
+    error ("Couldn't open worksheet xml file sheet%d.xml\n", wsh);
   endif
   rstatus = 0;
 
@@ -160,7 +163,9 @@
       endif
     endif
     ## Turn strings into numbers
-    val = num2cell (str2double (val)); 
+    if (! isempty (val))
+      val = num2cell (str2double (val));
+    endif
 
     ## 2. String / text formulas (cached results are in this sheet; fixed strings in <sharedStrings.xml>)
     ## Formulas
@@ -223,7 +228,7 @@
     ## 3. Strings
     if (! isempty (strings))
       ## Extract string values. May be much more than present in current sheet
-      ctext = cell2mat (regexp (strings, '<si><t(?:>(.+?)</t>|(.*)/>)</si>', "tokens"));
+      ctext = cell2mat (regexp (strings, '<si><t(?:>(.*?)</t>|(.*)/>)</si>', "tokens"));
       ## Pointers into sharedStrings.xml. "Hard" (fixed) strings have 't="s"' attribute
       ## For reasons known only to M$ those pointers are zero-based, so:
       vals = str2double (cell2mat (regexp (rawdata, '<c r="\w+"(?: s="\d")? t="s"><v>(\d+)</v>', "tokens"))) + 1;