From: <prn...@us...> - 2011-09-08 17:35:43
|
Revision: 8512 http://octave.svn.sourceforge.net/octave/?rev=8512&view=rev Author: prnienhuis Date: 2011-09-08 17:35:32 +0000 (Thu, 08 Sep 2011) Log Message: ----------- Style, layout + copyright updates and minor bug fixes Modified Paths: -------------- trunk/octave-forge/main/io/inst/getusedrange.m trunk/octave-forge/main/io/inst/object2json.m trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/odsclose.m trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/odsread.m trunk/octave-forge/main/io/inst/odswrite.m trunk/octave-forge/main/io/inst/parsecell.m trunk/octave-forge/main/io/inst/spsh_chkrange.m trunk/octave-forge/main/io/inst/spsh_prstype.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsclose.m trunk/octave-forge/main/io/inst/xlsfinfo.m trunk/octave-forge/main/io/inst/xlsopen.m trunk/octave-forge/main/io/inst/xlsread.m trunk/octave-forge/main/io/inst/xlswrite.m Modified: trunk/octave-forge/main/io/inst/getusedrange.m =================================================================== --- trunk/octave-forge/main/io/inst/getusedrange.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/getusedrange.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -31,7 +31,7 @@ ## only be obtained using UNO interface. ## For the ActiveX (COM) interface the underlying Visual Basic call relies ## on cached range values and counts empty cells with only formatting too, -## so COM returns only approximate (but usually too big) range values. +## so COM returns only approximate (but then usually too big) range values. ## ## Examples: ## @@ -65,6 +65,7 @@ ## 2010-10-07 Added COM support (at last!) ## 2011-05-06 Experimental support for Java/UNO bridge ## 2011-06-13 OpenXLS support added +## 2011-09-08 Style & layout updates ## ## Last subfunc update: 2011-06-29 (OXS) @@ -94,7 +95,7 @@ endfunction -## Copyright (C) 2010 Philip Nienhuis, pr.nienhuis -at- users.sf.net +## Copyright (C) 2010,2011 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 @@ -158,7 +159,7 @@ # Get leftmost cell column number lcell = row.getFirstChild (); cl_char = char (lcell); - # Swap the following lines into comment to catch a jOpenDocument bug + # Swap the following lines into comment to catch a jOpenDocument bug which foobars OTK # (JOD doesn't set <office:value-type='string'> attribute when writing strings #if (isempty (findstr ('office:value-type', cl_char)) || isempty (findstr ('<text:', cl_char))) if (isempty (findstr ('office:value-type', cl_char))) @@ -602,7 +603,7 @@ sh = xls.workbook.getWorkSheet (wsh - 1); try - # Intriguing: sh.first<> is off by one, sh.getLast<> = OK... + # Intriguing: sh.getFirst<> is off by one, sh.getLast<> = OK.... 8-Z trow = sh.getFirstRow () + 1; brow = sh.getLastRow (); lcol = sh.getFirstCol () + 1; Modified: trunk/octave-forge/main/io/inst/object2json.m =================================================================== --- trunk/octave-forge/main/io/inst/object2json.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/object2json.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,137 +1,190 @@ -%% Copyright (C) 2010 Torre Herrera, Daniel de -%% -%% 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 Foundation; either version 2 of the License, or -%% (at your option) any later version. -%% -%% This program is distributed in the hope that it will be useful, -%% but WITHOUT ANY WARRANTY; without even the implied warranty of -%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -%% GNU General Public License for more details. -%% -%% You should have received a copy of the GNU General Public License -%% along with Octave; see the file COPYING. If not, see -%% <http://www.gnu.org/licenses/>. -%% object2json.m -%% Ultima modificacion: 2010-12-06 - -function json=object2json(object) - % function json=object2json(object) - % This function returns a valid json string that will describe object - % The string will be in a compact form (i.e. no spaces or line breaks) - % - % It will map simple octave values this way: - % function handles: string with the name of the function - % double (numbers): depends: - % If it's real it will map to a string representing that number - % If it's complex it will map to an object with the next properties: - % real: real part of the number - % imag: imaginary part of the number - % char: A string enclosed by double quotes representing that character - % And will map more complex octave values this other way: - % struct: an object with properties equal to the struct's field names - % and value equal to the json counterpart of that field - % cell: it will be mapped depending on the value of the cell (for - % example {i} will be mapped to an object with real=0 and imag=1) - % vectors or cell arrays: it will map them to a corresponding js - % array (same size) with the values transformed to their json - % counterpart (Note: that in javascript all arrays are like octave's - % cells ,i.e. they can store different type and size variables) - % strings or char vectors: they will be mapped to the same string - % enclosed by double quotes - % Other octave values will be mapped to a string enclosed by double - % quuotes with the value that the class() function returns - - s=size(object); - if(all(s==1)) - % It's not a vector so we must check how to map it - % Depending on the class of the object we must do one or another thing - switch(class(object)) - case 'function_handle' - % For a function handle we will only print the name - fun=functions(object); - json=['"',fun.function,'"']; - case 'struct' - fields=fieldnames(object); - -results=cellfun(@object2json,struct2cell(object),"UniformOutput",false); - json='{'; - if(numel(fields)>1) - sep=','; - else - sep=''; - endif - for(tmp=1:numel(fields)) - json=[json,'"',fields{tmp},'":',results{tmp},sep]; - if(tmp>=numel(fields)-1) - sep=''; - endif - endfor - json(end+1)='}'; - case 'cell' - % We dereference the cell and use it as a new value - json=object2json(object{1}); - case 'double' - if(isreal(object)) - json=num2str(object); - else - if(iscomplex(object)) - -json=['{"real":',num2str(real(object)),',"imag":',num2str(imag(object)),'}']; - endif - endif - case 'char' - % Here we handle a single char - json=['"',object,'"']; - otherwise - % We don't know what is it so we'll put the class name - json=['"',class(object),'"']; - endswitch - else - % It's a vector so it maps to an array - sep=''; - if(numel(s)>2) - json='['; - for(tmp=1:s(1)) - json=[json,sep,object2json(reshape(object(tmp,:),s(2:end)))]; - sep=','; - endfor - json(end+1)=']'; - else - % We can have three cases here: - % Object is a row -> array with all the elements - % Object is a column -> each element is an array in it's own - % Object is a 2D matrix -> separate each row - if(s(1)==1) - % Object is a row - if(ischar(object)) - % If it's a row of chars we will take it as a string - json=['"',object,'"']; - else - json='['; - for(tmp=1:s(2)) - json=[json,sep,object2json(object(1,tmp))]; - sep=','; - endfor - json(end+1)=']'; - endif - elseif(s(2)==1) - % Object is a column - json='['; - for(tmp=1:s(1)) - json=[json,'[',object2json(object(tmp,1)),']']; - endfor - json(end+1)=']'; - else - % Object is a 2D matrix - json='['; - for(tmp=1:s(1)) - json=[json,sep,object2json(object(tmp,:))]; - sep=','; - endfor - json(end+1)=']'; - endif - endif - endif -endfunction +%% Copyright (C) 2010 Torre Herrera, Daniel de +%% +%% 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 Foundation; either version 2 of the License, or +%% (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with Octave; see the file COPYING. If not, see +%% <http://www.gnu.org/licenses/>. +%% object2json.m +%% Created: 2010-12-06 +%% Updates: +%% 2011-01-23 Added support for especial chars and escaped sequences +%% 2011-04-01 Fixed error: Column vectors not working correctly +%% 2011-09-08 (Philip Nienhuis) layout & style changes cf. Octave coding style + +function json = object2json (object) + + % function json = object2json (object) + % This function returns a valid json string that will describe object + % The string will be in a compact form (i.e. no spaces or line breaks) + % + % It will map simple octave values this way: + % function handles: string with the name of the function + % double (numbers): depends: + % If it's real it will map to a string representing that number + % If it's complex it will map to an object with the next properties: + % real: real part of the number + % imag: imaginary part of the number + % char: A string enclosed by double quotes representing that character + % And will map more complex octave values this other way: + % struct: an object with properties equal to the struct's field names + % and value equal to the json counterpart of that field + % cell: it will be mapped depending on the value of the cell (for + % example {i} will be mapped to an object with real=0 and imag=1) + % vectors or cell arrays: it will map them to a corresponding js + % array (same size) with the values transformed to their json + % counterpart (Note: that in javascript all arrays are like octave's + % cells ,i.e. they can store different type and size variables) + % strings or char vectors: they will be mapped to the same string + % enclosed by double quotes + % Other octave values will be mapped to a string enclosed by double + % quotes with the value that the class() function returns + % It can handle escape sequences and special chars automatically. + % If they're valid in JSON it will keep them if not they'll be + % escaped so they can become valid + + s = size (object); + if (all (s==1)) + % It's not a vector so we must check how to map it + % Depending on the class of the object we must do one or another thing + switch (class (object)) + case 'function_handle' + % For a function handle we will only print the name + fun = functions (object); + json = [ '"', fun.function, '"' ]; + + case 'struct' + fields = fieldnames (object); + results = cellfun (@object2json, struct2cell (object), "UniformOutput", false); + json = '{'; + if (numel (fields) > 1) + sep = ','; + else + sep = ''; + endif + for (tmp = 1:numel (fields)) + json = [ json, '"', fields{tmp}, '":', results{tmp}, sep ]; + if(tmp >= numel (fields)-1) + sep = ''; + endif + endfor + json(end+1) = '}'; + + case 'cell' + % We dereference the cell and use it as a new value + json = object2json (object{1}); + + case 'double' + if (isreal (object)) + json = num2str (object); + else + if (iscomplex (object)) + json = [ '{"real":', num2str(real(object)), ',"imag":' , num2str(imag(object)), '}' ]; + endif + endif + + case 'char' + % Here we handle a single char + % JSON only admits the next escape sequences: + % \", \\, \/, \b, \f, \n, \r, \t and \u four-hex-digits + % so we must be sure that every other sequence gets replaced + object = replace_non_JSON_escapes (object); + json = [ '"', object, '"' ]; + + otherwise + % We don't know what is it so we'll put the class name + json = [ '"', class(object), '"' ]; + endswitch + + else + % It's a vector so it maps to an array + sep = ''; + if (numel (s) > 2) + json = '['; + for (tmp=1:s(1)) + json = [ json, sep, object2json(reshape(object(tmp, :), s(2:end))) ]; + sep = ','; + endfor + json(end+1) = ']'; + + else + % We can have three cases here: + % Object is a row -> array with all the elements + % Object is a column -> each element is an array in it's own + % Object is a 2D matrix -> separate each row + if (s(1) == 1) + % Object is a row + if (ischar (object)) + % If it's a row of chars we will take it as a string + % JSON only admits the next escape sequences: + % \", \\, \/, \b, \f, \n, \r, \t and \u four-hex-digits + % so we must be sure that every other sequence gets replaced + object = replace_non_JSON_escapes (object); + json = [ '"', object, '"']; + + else + json = '['; + for (tmp=1:s(2)) + json = [ json, sep, object2json(object(1, tmp)) ]; + sep = ','; + endfor + json(end+1) = ']'; + endif + + elseif (s(2) == 1) + % Object is a column + json = '['; + for (tmp=1:s(1)) + json = [ json, sep, '[', object2json(object(tmp, 1)), ']' ]; + sep = ','; + endfor + json(end+1) = ']'; + + else + % Object is a 2D matrix + json = '['; + for (tmp=1:s(1)) + json = [ json, sep, object2json(object(tmp, :)) ]; + sep = ','; + endfor + json(end+1) = ']'; + + endif + endif + endif + +endfunction + + +% JSON only admits the next escape sequences: +% \", \\, \/, \b, \f, \n, \r, \t and \u four-hex-digits +% This function replace every escaped sequence that isn't on that list +% with a compatible version +% Note that this function uses typeinfo so it may need to be updated +% with each octave release + +function object = replace_non_JSON_escapes (object) + + if (strcmp (typeinfo (object), 'string')) + % It's a double quoted string so newlines and other chars need + % to be converted back into escape sequences before anything + object = undo_string_escapes (object); + endif + % This first regex handles double quotes and slashes that are not + % after a backslash and thus aren't escaped + object = regexprep (object, '(?<!\\)(["/])', "\\$1"); + % This regex handle double quotes and slashes that are after an even + % number of backslashes and thus aren't escaped + object = regexprep (object, '(?<!\\)(\\\\)*(["/])', "$1\\$2"); + % This last one regexp handle any other valid JSON escape sequence + object = regexprep (object, '(?<!\\)\\(?=(\\\\)*(?!([\"\\\/bfnrt]|([u][0-9A-Fa-f]{4}))+?))', "\\\\"); + +endfunction Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -111,7 +111,7 @@ ## 2011-03-23 First try of odfdom 0.8.7 ## 2011-05-15 Experimental UNO support added ## -## Last update of subfunctions below: 2012-12-08 +## Last update of subfunctions below: 2011-09-08 function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange=[], spsh_opts=[]) @@ -188,7 +188,7 @@ #============================================================================= -## Copyright (C) 2010 Philip Nienhuis <prn...@us...> +## Copyright (C) 2010,2011 Philip Nienhuis <prn...@us...> ## ## 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 @@ -630,7 +630,7 @@ #============================================================================= -## Copyright (C) 2009 Philip Nienhuis <prnienhuis _at- users.sf.net> +## Copyright (C) 2010,2011 Philip Nienhuis <prnienhuis _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 @@ -828,7 +828,7 @@ #============================================================================= -## Copyright (C) 2009-2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 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 @@ -1007,6 +1007,9 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-05-15 +## Updates: +## 2011-summer <many many improvements> +## 2011-09-08 Stylistic changes function [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts) @@ -1018,7 +1021,7 @@ sheets = ods.workbook.getSheets (); sh_names = sheets.getElementNames (); # Check sheet pointer - # FIXME sheet capacity check needed + # FIXME sheet capacity check needed. How many can fit in an OOo sprsh.file? if (isnumeric (wsh)) if (wsh < 1) error ("Illegal sheet index: %d", wsh); @@ -1105,11 +1108,11 @@ otherwise # Empty cell endswitch - changed = 1; + changed = 1; catch printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); keyboard - end_try_catch + end_try_catch endfor endfor Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -105,6 +105,7 @@ ## 2011-03-29 OpenXLS support added. Works but saving to file (xlsclose) doesn't work yet ## " Bug fixes (stray variable c_arr, and wrong test for valid xls struct) ## 2011-05-18 Experimental UNO support +## 2011-09-08 Bug fix in range arg check; code cleanup ## Last script file update (incl. subfunctions): 2011-05-18 (oct2uno2xls) @@ -138,7 +139,7 @@ # Check worksheet ptr if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif # Check range - if (~(isempty (crange) || ischar (crange))), error ("Character string (range) expected for arg # 4"); endif + if (isempty (crange) || ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif # Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; @@ -164,7 +165,7 @@ [xls, rstatus] = oct2jxla2xls (obj, xls, wsh, crange, spsh_opts); elseif (strcmp (xls.xtype, 'OXS')) # # Invoke Java and OpenXLS ##### Not complete, saving file doesn't work yet! - printf ('Sorry, writing with OpenXLS not supported yet\n'); + printf ('Sorry, writing with OpenXLS not reliable => not supported yet\n'); # [xls, rstatus] = oct2oxs2xls (obj, xls, wsh, crange, spsh_opts); elseif (strcmp (xls.xtype, 'UNO')) # Invoke Java and UNO bridge (OpenOffice.org) @@ -243,7 +244,7 @@ function [ xls, status ] = oct2com2xls (obj, xls, wsh, crange, spsh_opts) # Preliminary sanity checks - if (~strmatch (tolower (xls.filename(end-4:end)), '.xls')) + if (~strmatch (lower (xls.filename(end-4:end)), '.xls')) error ("oct2com2xls can only write to Excel .xls or .xlsx files") endif if (isnumeric (wsh)) @@ -718,7 +719,7 @@ # First make sure formula functions are all uppercase obj{ii, jj} = toupper (obj{ii, jj}); # There's no guarantee for formula correctness, so.... - try # Actually JExcelAPI flags formula errors as warnings :-( + try # Actually JExcelAPI flags formula errors as mere warnings :-( tmp = java_new ('jxl.write.Formula', kk, ll, obj{ii, jj}); # ... while errors are actually detected in addCell(), so # that should be within the try-catch @@ -980,7 +981,7 @@ switch typearr(ii, jj) case 1 # Float XCell.setValue (c_arr{ii, jj}); - case 2 # Logical. Convert to float + case 2 # Logical. Convert to float as OOo has no Boolean type XCell.setValue (double (c_arr{ii, jj})); case 3 # String unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -194,7 +194,7 @@ #===================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis _at- users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis _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 @@ -410,7 +410,7 @@ #=========================================================================== -## Copyright (C) 2010 Philip Nienhuis <prn...@us...> +## Copyright (C) 2010,2011 Philip Nienhuis <prn...@us...> ## ## 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 @@ -544,7 +544,7 @@ rawarr(ii-trow+1, jj-lcol+1) = ocell.getBooleanValue (); case 'string' rawarr(ii-trow+1, jj-lcol+1) = ocell.getStringValue (); -# # Code left in for in case odfdom 0.8.6 has similar bug +# # Code left in for in case odfdom 0.8.6+ has similar bug # # as 0.7.5 # cvalue = tcell.getOfficeStringValueAttribute (); # if (isempty (cvalue)) # Happens with e.g., hyperlinks @@ -577,7 +577,7 @@ #=========================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 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 Modified: trunk/octave-forge/main/io/inst/odsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/odsclose.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odsclose.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -63,6 +63,7 @@ ## 2011-05-06 Experimental UNO support ## 2011-05-07 In case of UNO, soffice now properly closed using xDesk ## 2011-05-18 Saving newly created files using UNO supported now +## 2011-09-08 FIXME - closing OOo kills all other OOo invocations (known Java-UNO issue) function [ ods ] = odsclose (ods, varargs) Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -242,7 +242,7 @@ catch # 1.2b2 has not ods.odfvsn = 2; - printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2b3+\n"); + printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2\n"); end_try_catch odssupport += 2; catch Modified: trunk/octave-forge/main/io/inst/odsread.m =================================================================== --- trunk/octave-forge/main/io/inst/odsread.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odsread.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis 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 @@ -113,6 +113,7 @@ ## 2010-05-31 Updated help text (delays i.c.o. empty range due to getusedrange call) ## 2010-11-10 Updated help text (filename extension req'd) ## 2010-11-13 Added some input validity checks +## 2011-09-08 Catch empty ods structs after failed odsopen attempts function [ numarr, txtarr, rawarr, lim ] = odsread (filename, wsh=1, datrange=[], reqintf=[]) @@ -124,15 +125,19 @@ endif ods = odsopen (filename, 0, reqintf); + + if (~isempty (ods)) - [rawarr, ods, rstatus] = ods2oct (ods, wsh, datrange); + [rawarr, ods, rstatus] = ods2oct (ods, wsh, datrange); - if (rstatus) - [numarr, txtarr, lim] = parsecell (rawarr, ods.limits); - else - warning (sprintf ("No data read from %s.", filename)); - endif + if (rstatus) + [numarr, txtarr, lim] = parsecell (rawarr, ods.limits); + else + warning (sprintf ("No data read from %s.", filename)); + endif - ods = odsclose (ods); + ods = odsclose (ods); + endif + endfunction Modified: trunk/octave-forge/main/io/inst/odswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/odswrite.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odswrite.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 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 @@ -88,6 +88,7 @@ ## 2010-08-25 Removed text about 31 char limit for sheet names (invalid) ## 2010-11-13 Added note about required file extension in help text ## 2010-11-13 Added some input arg checks +## 2011-09-08 Minor filename error text adaptation function [ rstatus ] = odswrite (filename, data, wsh=1, range=[], reqintf=[]) @@ -95,7 +96,7 @@ if (nargin < 2) usage ("Insufficient arguments - see 'help odswrite'"); elseif (~ischar (filename) || isempty (findstr ('.ods', tolower (filename)))) - error ("First argument must be a filename (incl. .ods suffix)"); + error ("First argument must be a filename (incl. .ods suffix for OTK & JOD)"); endif ods = odsopen (filename, 1, reqintf); Modified: trunk/octave-forge/main/io/inst/parsecell.m =================================================================== --- trunk/octave-forge/main/io/inst/parsecell.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/parsecell.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis 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 @@ -61,6 +61,7 @@ ## 2010-10-15 Simplified code for numerical array ## 2011-05-17 Fixed subscript indexing bug in cropping section when rawarr is ## " numeric scalar +## 2011-09-08 Copyright string updated function [ numarr, txtarr, lim ] = parsecell (rawarr, arg2=[]) Modified: trunk/octave-forge/main/io/inst/spsh_chkrange.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_chkrange.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/spsh_chkrange.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -70,6 +70,7 @@ case { 'UNO' } # ODS; LibreOffice has a higher row capacity # FIXME - use UNO calls to check physical row capacity + # FIXME - LibreOffice has higher row capacity but it's Java classes haven't been updated ROW_CAP = 65536; COL_CAP = 1024; otherwise error (sprintf ("Unknown interface type - %s\n", xtype)); Modified: trunk/octave-forge/main/io/inst/spsh_prstype.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_prstype.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/spsh_prstype.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -42,30 +42,30 @@ # 1 = numeric # 2 = boolean # 3 = text - # 4 = formula + # 4 = formula # 5 = error / NaN / empty typearr = ctype(5) * ones (nrows, ncols); # type "EMPTY", provisionally obj2 = cell (size (obj)); # Temporary storage for strings - txtptr = cellfun ('isclass', obj, 'char'); # type "STRING" replaced by "NUMERIC" + txtptr = cellfun ('isclass', obj, 'char'); # type "STRING" replaced by "NUMERIC" obj2(txtptr) = obj(txtptr); obj(txtptr) = ctype(3); # Save strings in a safe place emptr = cellfun ("isempty", obj); obj(emptr) = ctype(5); # Set empty cells to NUMERIC - lptr = cellfun ("islogical" , obj); # Find logicals... + lptr = cellfun ("islogical" , obj); # Find logicals... obj2(lptr) = obj(lptr); # .. and set them to BOOLEAN - ptr = cellfun ("isnan", obj); # Find NaNs & set to BLANK + ptr = cellfun ("isnan", obj); # Find NaNs & set to BLANK typearr(ptr) = ctype(5); typearr(~ptr) = ctype(1); # All other cells are now numeric - obj(txtptr) = obj2(txtptr); # Copy strings back into place + obj(txtptr) = obj2(txtptr); # Copy strings back into place obj(lptr) = obj2(lptr); # Same for logicals - obj(emptr) = -1; # Add in a filler value for empty cells + obj(emptr) = -1; # Add in a filler value for empty cells - typearr(txtptr) = ctype(3); # ...and clean up - typearr(emptr) = ctype(5); # EMPTY + typearr(txtptr) = ctype(3); # ...and clean up + typearr(emptr) = ctype(5); # EMPTY typearr(lptr) = ctype(2); # BOOLEAN if ~(spsh_opts.formulas_as_text) Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -117,6 +117,7 @@ ## 2011-03-26 OpenXLS support added ## 2011-03-29 Test for proper input xls struct extended ## 2011-05-18 Experimental UNO support added +## 2011-09-08 Minor code layout ## ## Latest subfunc update: 2011-05-18 (UNO) @@ -132,6 +133,7 @@ if test1 error ("Invalid xls file pointer struct"); endif + # Check worksheet ptr if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 2"); endif # Check range @@ -467,7 +469,7 @@ type_of_cell = scell.getCellType (); if (type_of_cell == ctype(3)) # Formula if ~(spsh_opts.formulas_as_text) - try # Because not al Excel formulas have been implemented + try # Because not al Excel formulas have been implemented in POI cvalue = frm_eval.evaluate (scell); type_of_cell = cvalue.getCellType(); # Separate switch because form.eval. yields different type @@ -601,7 +603,7 @@ shnames = char (wb.getSheetNames ()); if (isnumeric (wsh)) if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif - sh = wb.getSheet (wsh - 1); # POI sheet count 0-based + sh = wb.getSheet (wsh - 1); # JXL sheet count 0-based printf ("(Reading from worksheet %s)\n", shnames {wsh}); else sh = wb.getSheet (wsh); Modified: trunk/octave-forge/main/io/inst/xlsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsclose.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsclose.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -24,7 +24,7 @@ ## ## If no errors occured during writing, the xls file pointer struct will be ## reset and -if COM interface was used- ActiveX/Excel will be closed. -## However if errors occurred, the file pinter will be ontouched so you can +## However if errors occurred, the file pinter will be untouched so you can ## clean up before a next try with xlsclose(). ## Be warned that until xlsopen is called again with the same @var{xls} pointer ## struct, hidden Excel or Java applications with associated (possibly large) @@ -70,6 +70,7 @@ ## always keep file pointer in case of write errors ## 2011-03-26 Added OpenXLS support ## 2011-05-18 Added experimental UNO support, incl. saving newly created files +## 2011-09-08 Bug fix in check for filename input arg function [ xls ] = xlsclose (xls, varargs) @@ -86,16 +87,16 @@ printf ("File %s wasn't changed, new filename ignored.", xls.filename); elseif (strcmp (xls.xtype, 'JXL')) error ("JXL doesn't support changing filename, new filename ignored."); - elseif ~((strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'UNO')) && isempty (strfind ('filename', '.xls'))) + elseif ~((strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'UNO')) && isempty (strfind ( lower (filename), '.xls'))) # Excel/ActiveX && OOo (UNO bridge) will write any valid filetype; POI/JXL/OXS need .xls[x] error ('.xls or .xlsx extension lacking in filename %s', filename); else ### For multi-user environments, uncomment below AND relevant stanza in xlsopen # In case of COM, be sure to first close the open workbook #if (strcmp (xls.xtype, 'COM')) - # xls.app.Application.DisplayAlerts = 0; - # xls.workbook.close(); - # xls.app.Application.DisplayAlerts = 0; + # xls.app.Application.DisplayAlerts = 0; + # xls.workbook.close(); + # xls.app.Application.DisplayAlerts = 0; #endif if (strcmp (xls.xtype, 'UNO')) # If needed, turn filename into URL @@ -115,6 +116,7 @@ endif endif endif + # Preprocessing / -checking ready. Assign filename arg to file ptr struct xls.filename = filename; endif endif Modified: trunk/octave-forge/main/io/inst/xlsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -82,6 +82,7 @@ ## 2010-11-01 Added other file type strings for return arg #3 (fformat) ## 2011-03-26 Added OpenXLS support ## 2011-05-18 Experimental UNO support +## 2011-09-08 Some code simplifications function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[]) @@ -118,13 +119,13 @@ endif endfor if (ws_cnt > 0 || ch_cnt > 0) - if (strcmp (tolower (xls.filename(end-2:end)), 'xls')) + if (strcmpi (xls.filename(end-2:end), 'xls')) fformat = "xlWorkbookNormal"; - elseif (strcmp (tolower (xls.filename(end-2:end)), 'csv')) + elseif (strcmpi (xls.filename(end-2:end), 'csv')) fformat = "xlCSV"; # Works only with COM - elseif (strcmp (tolower (xls.filename(end-3:end-1)), 'xls')) + elseif (strcmpi (xls.filename(end-3:end-1), 'xls')) fformat = "xlOpenXMLWorkbook"; - elseif (strmatch ('htm', tolower (xls.filename(end-3:end)))) + elseif (strmatch ('htm', lower (xls.filename(end-3:end)))) fformat = "xlHtml"; # Works only with COM else fformat = ''; @@ -147,9 +148,9 @@ endif endfor if (sh_cnt > 0) - if (strcmp (tolower (xls.filename(end-2:end)), 'xls')) + if (strcmpi (xls.filename(end-2:end), 'xls')) fformat = "xlWorkbookNormal"; - elseif (strcmp (tolower (xls.filename(end-3:end-1)), 'xls')) + elseif (strcmpi (xls.filename(end-3:end-1), 'xls')) fformat = "xlOpenXMLWorkbook"; else fformat = ''; Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -102,6 +102,7 @@ ## 2011-05-29 Cleanup of comments & messages ## 2011-09-03 Reset chkintf to [] if no xls support was discovered (to allow ## rediscovery of interfaces between xlsopen calls, e.g. javaclasspath changes) +## 2011-09-08 Minor code cleanup ## ## 2011-09-03 Latest subfunction update @@ -119,9 +120,11 @@ if (nargout < 1) usage ("XLS = xlsopen (Xlfile [, Rw] [, reqintf]). But no return argument specified!"); endif + if (~(islogical (xwrite) || isnumeric (xwrite))) usage ("Numerical or logical value expected for arg # 2") endif + if (~isempty (reqinterface)) if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif # Turn arg3 into cell array if needed @@ -154,7 +157,7 @@ for ii=1:numel (reqinterface) if (~xlsinterfaces.(toupper (reqinterface{ii}))) # No it aint - printf ("%s is not supported.\n", toupper (reqinterface{ii})); + printf ("%s is not supported.\n", upper (reqinterface{ii})); else ++xlsintf_cnt; endif @@ -196,8 +199,8 @@ xlsinterfaces = getxlsinterfaces (xlsinterfaces); # Supported interfaces determined; Excel file type check moved to seperate interfaces. - chk1 = strcmpi (filename(end-3:end), '.xls'); - chk2 = strcmpi (filename(end-4:end-1), '.xls'); + chk1 = strcmpi (filename(end-3:end), '.xls'); # Regular (binary) BIFF + chk2 = strcmpi (filename(end-4:end-1), '.xls'); # Zipped XML / OOXML # Initialize file ptr struct xls = struct ("xtype", 'NONE', "app", [], "filename", [], "workbook", [], "changed", 0, "limits", []); @@ -245,8 +248,6 @@ wb = java_new ('org.apache.poi.hssf.usermodel.HSSFWorkbook'); elseif (chk2) wb = java_new ('org.apache.poi.xssf.usermodel.XSSFWorkbook'); - else - # Nothing; we let the user encounter the full java error text endif xls.app = 'new_POI'; else @@ -287,7 +288,7 @@ catch clear xlsin; if (xlsinterfaces.POI) - printf ('... No luck with JXL, unsupported file format.\n', filename); + printf ('... No luck with JXL either, unsupported file format.\n', filename); endif end_try_catch endif @@ -378,7 +379,7 @@ # Until something was written to existing files we keep status "unchanged". # xls.changed = 0 (existing/only read from), 1 (existing/data added), 2 (new, # data added) or 3 (pristine, no data added). - if (xls.changed == 1) xls.changed = 0; endif + if (xls.changed == 1), xls.changed = 0; endif endif # Rounding up. If none of the xlsinterfaces is supported we're out of luck. @@ -445,10 +446,11 @@ ## 2011-06-13 Fixed potentially faulty tests for java classlib presence ## 2011-09-03 Fixed order of xlsinterfaces.<member> statements in Java detection try-catch ## '' Reset tmp1 (always allow interface rediscovery) for empty xlsinterfaces arg +## 2011-09-08 Minor code cleanup function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) - # tmp1 = [] (not initialized), 0 (No java detected), or 1 (Working Java found) + # tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) persistent tmp1 = []; persistent jcp; # Java class path if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS)) @@ -488,7 +490,7 @@ jver = char (java_invoke ('java.lang.System', 'getProperty', 'java.version')); cjver = strsplit (jver, '.'); if (sscanf (cjver{2}, '%d') < 6) - warning ("\nJava version too old - you need at least Java 6 (v. 1.6.x.x)\n"); + warning ("\nJava version might be too old - you need at least Java 6 (v. 1.6.x.x)\n"); return endif # Now check for proper entries in class path. Under *nix the classpath @@ -502,7 +504,7 @@ # Some Java-based interface requested but Java support is absent error (' No Java support found.'); else - # No specific Java-based interface requested. Just return + # No specific Java-based interface requested xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; xlsinterfaces.OXS = 0; @@ -536,7 +538,7 @@ jpchk2 = 0; entries2 = {"xbean", "poi-ooxml-schemas", "dom4j"}; for ii=1:length (jcp) for jj=1:length (entries2) - if (isempty (strfind (tolower (jcp{ii}), entries2{jj}))), ++jpchk2; endif + if (isempty (strfind (lower (jcp{ii}), entries2{jj}))), ++jpchk2; endif endfor endfor if (jpchk2 > 2), printf (" (& OOXML)"); endif @@ -551,7 +553,7 @@ jpchk = 0; entries = {"jxl"}; for ii=1:length (jcp) for jj=1:length (entries) - if (isempty (strfind (tolower (jcp{ii}), entries{jj}))), ++jpchk; endif + if (isempty (strfind (lower (jcp{ii}), entries{jj}))), ++jpchk; endif endfor endfor if (jpchk > 0) @@ -567,7 +569,7 @@ jpchk = 0; entries = {"openxls"}; for ii=1:length (jcp) for jj=1:length (entries) - if (isempty (strfind (tolower (jcp{ii}), entries{jj}))), ++jpchk; endif + if (isempty (strfind (lower (jcp{ii}), entries{jj}))), ++jpchk; endif endfor endfor if (jpchk > 0) Modified: trunk/octave-forge/main/io/inst/xlsread.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsread.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsread.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 by Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 by Philip Nienhuis <prnienhuis 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 @@ -146,16 +146,17 @@ ## 2010-11-13 Added some input checks ## 2011-04-11 Return upon empty xls struct from xlsopen() ## 2011-04-17 Suppress xlsopen messages (";" was missing) +## 2011-09-08 Minor code cleanup; included UNO & OXS support in test function [ numarr, txtarr, rawarr, lims ] = xlsread (fn, wsh, datrange, reqintf=[]) rstatus = 0; if (nargout < 1) - usage ("xlsread: no output argument(s) specified"); + usage ("xlsread: no output argument(s) specified that should receive data"); endif if (nargin < 1) - error ("xlsread: no arguments specified") + error ("xlsread: no input arguments specified") numarr = []; txtarr={}; rawarr = {}; return elseif (nargin == 1) @@ -163,7 +164,7 @@ datrange = ''; elseif (nargin == 2) # Find out whether 2nd argument = worksheet or range - if (isnumeric (wsh) || (isempty (findstr(wsh,':')) && ~isempty (wsh))) + if (isnumeric (wsh) || (isempty (findstr (wsh,':')) && ~isempty (wsh))) # Apparently a worksheet specified datrange = ''; else @@ -174,15 +175,13 @@ endif # A small gesture for Matlab compatibility. JExcelAPI supports BIFF5. - if (~isempty (reqintf) && ischar (reqintf) && strcmp (toupper(reqintf), 'BASIC')) + if (~isempty (reqintf) && ischar (reqintf) && strcmpi (reqintf, 'BASIC')) reqintf= {"JXL"} ; - printf ("BASIC (BIFF5) support request translated to JXL. \n"); + printf ("(BASIC (BIFF5) support request translated to JXL.) \n"); endif - - if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified as argument.\n"); endif # Checks done. Get raw data into cell array "rawarr". xlsopen finds out - # what interface to use. If none found, suggest csv + # what interface to use. If none found, just return as xlsopen will complain enough unwind_protect # Needed to catch COM errors & able to close stray Excel invocations # Get pointer array to Excel file @@ -194,7 +193,8 @@ return endif - if (strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'POI') || strcmp (xls.xtype, 'JXL')) +# if (strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'POI') || strcmp (xls.xtype, 'JXL')... +# || strcmp (xls.xtype, 'OXS') || strcmp (xls.xtype, 'UNO')) # Get data from Excel file & return handle [rawarr, xls, rstatus] = xls2oct (xls, wsh, datrange); @@ -209,13 +209,13 @@ rawarr = {}; numarr = []; txtarr = {}; endif - else - printf ("Error XLSREAD: reading EXCEL file (BIFF- or OOXML Format) isn\'t supported on this system.\n"); - printf ("You need to convert the file into a tab- or comma delimited text file or .csv file\n"); - printf ("and then invoke csvread(), dlmread() or textread()\n\n"); +# else +# printf ("Error XLSREAD: reading EXCEL file (BIFF- or OOXML Format) isn\'t supported on this system.\n"); +# printf ("You need to convert the file into a tab- or comma delimited text file or .csv file\n"); +# printf ("and then invoke csvread(), dlmread() or textread()\n\n"); +# +# endif - endif - unwind_protect_cleanup # Close Excel file if (xls_ok) xls = xlsclose (xls); endif Modified: trunk/octave-forge/main/io/inst/xlswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/xlswrite.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlswrite.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis 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 @@ -95,7 +95,8 @@ ## 2010-01-15 Fixed typos in texinfo ## 2010-08-18 Added check for existence of xls after call to xlsopen to ## avoid unneeded error message clutter -## 2010-10-27 Chnged range -> crange to unhide other range functions +## 2010-10-27 Changed range -> crange to unhide other range functions +## 2011-09-08 Minor code syntax updates function [ rstatus ] = xlswrite (filename, arr, arg3, arg4, arg5) @@ -160,7 +161,7 @@ [xls, rstatus] = oct2xls (arr(1:nr, 1:nc), xls, wsh, topleft); unwind_protect_cleanup - if (xls_ok) xls = xlsclose (xls); endif + if (xls_ok), xls = xlsclose (xls); endif end_unwind_protect This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |