Mercurial > forge
changeset 11164:9401a757a3d6 octave-forge
Style fixes
line wrap: on
line diff
--- a/main/io/inst/calccelladdress.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/calccelladdress.m Wed Oct 24 21:43:38 2012 +0000 @@ -30,18 +30,23 @@ ## 2011-04-30 Simplified column name computation ## 2011-12-17 Bugfix for wrong column address if column equals multiple of 26 ## 2011-12-18 Added tests for multiple-of-26 cases +## 2012-10-24 Style fixes function [ celladdress ] = calccelladdress (row, column) if (nargin < 2) error ("calccelladdress: Two arguments needed") endif - if (column > 18278 || column < 1) error ("Specified column out of range (1..18278)"); endif - if (row > 1048576 || row < 1), error ('Specified row out of range (1..1048576)'); endif + if (column > 18278 || column < 1) + error ("Specified column out of range (1..18278)"); + endif + if (row > 1048576 || row < 1) + error ('Specified row out of range (1..1048576)'); + endif str = ''; while (column > 0.01) rmd = floor ((column - 1) / 26); - str = [char(column - rmd * 26 + 'A' - 1) str]; + str = [ char(column - rmd * 26 + 'A' - 1) str ]; column = rmd; endwhile
--- a/main/io/inst/oct2ods.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/oct2ods.m Wed Oct 24 21:43:38 2012 +0000 @@ -118,14 +118,15 @@ ## 2012-06-08 Support for odfdom-incubator-0.8.8 ## '' Tabs replaced by double space ## 2012-10-12 Moved all interface-specific subfubcs into ./private +## 2012-10-24 Style fixes ## ## Latest subfunc update: 2012-10-12 -function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange='', spsh_opts=[]) +function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange="", spsh_opts=[]) if (nargin < 2) error ("oct2xls needs a minimum of 2 arguments."); endif - # Check if input array is cell + ## Check if input array is cell if (isempty (c_arr)) warning ("Request to write empty matrix - ignored."); rstatus = 1; @@ -138,9 +139,11 @@ elseif (~iscell (c_arr)) error ("oct2ods: input array neither cell nor numeric array"); endif - if (ndims (c_arr) > 2), error ("Only 2-dimensional arrays can be written to spreadsheet"); endif + if (ndims (c_arr) > 2) + error ("Only 2-dimensional arrays can be written to spreadsheet"); + endif - # Check ods file pointer struct + ## Check ods file pointer struct test1 = ~isfield (ods, "xtype"); test1 = test1 || ~isfield (ods, "workbook"); test1 = test1 || isempty (ods.workbook); @@ -149,31 +152,38 @@ error ("Arg #2: Invalid ods file pointer struct"); endif - # Check worksheet ptr - if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif + ## Check worksheet ptr + if (~(ischar (wsh) || isnumeric (wsh))) + error ("Integer (index) or text (wsh name) expected for arg # 3"); + endif - # Check range + ## Check range if (~isempty (crange) && ~ischar (crange)) error ("Character string (range) expected for arg # 4"); elseif (isempty (crange)) - crange = ''; + crange = ""; endif - # Various options + ## Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; - # other options to be implemented here + ## other options to be implemented here elseif (isstruct (spsh_opts)) - if (~isfield (spsh_opts, 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif - # other options to be implemented here + if (~isfield (spsh_opts, "formulas_as_text")) + spsh_opts.formulas_as_text = 0; + endif + ## other options to be implemented here: + else - error ("Structure expected for arg # 5"); + error ("Structure expected for arg # 5" (options)); endif - if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified.\n"); endif + if (nargout < 1) + printf ("Warning: no output spreadsheet file pointer specified.\n"); + endif - if (strcmp (ods.xtype, 'OTK')) - # Write ods file tru Java & ODF toolkit. + if (strcmp (ods.xtype, "OTK")) + ## Write ods file tru Java & ODF toolkit. switch ods.odfvsn case "0.7.5" [ ods, rstatus ] = __OTK_oct2ods__ (c_arr, ods, wsh, crange, spsh_opts); @@ -183,19 +193,20 @@ error ("Unsupported odfdom version"); endswitch - elseif (strcmp (ods.xtype, 'JOD')) - # Write ods file tru Java & jOpenDocument. API still leaves lots to be wished... + elseif (strcmp (ods.xtype, "JOD")) + ## Write ods file tru Java & jOpenDocument. API still leaves lots to be wished... [ ods, rstatus ] = __JOD_oct2spsh__ (c_arr, ods, wsh, crange); - elseif (strcmp (ods.xtype, 'UNO')) - # Write ods file tru Java & UNO bridge (OpenOffice.org & clones) + elseif (strcmp (ods.xtype, "UNO")) + ## Write ods file tru Java & UNO bridge (OpenOffice.org & clones) [ ods, rstatus ] = __UNO_oct2spsh__ (c_arr, ods, wsh, crange, spsh_opts); -# elseif - # ---- < Other interfaces here > + ##elseif + ##---- < Other interfaces here > else - error (sprintf ("ods2oct: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); + error (sprintf ("ods2oct: unknown OpenOffice.org .ods interface - %s.",... + ods.xtype)); endif if (rstatus), ods.limits = []; endif
--- a/main/io/inst/oct2xls.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/oct2xls.m Wed Oct 24 21:43:38 2012 +0000 @@ -113,85 +113,95 @@ ## 2012-03-07 Updated texinfo help text ## 2012-05-22 Cast all numeric data in input array to double ## 2012-10-12 Moved all interface-specific subfubcs into ./private +## 2012-10-24 Style fixes ## ## Latest subfunc update: 2012-10-12 -function [ xls, rstatus ] = oct2xls (obj, xls, wsh=1, crange='', spsh_opts=[]) +function [ xls, rstatus ] = oct2xls (obj, xls, wsh=1, crange="", spsh_opts=[]) - if (nargin < 2) error ("oct2xls needs a minimum of 2 arguments."); endif + if (nargin < 2) error ("oct2xls needs a minimum of 2 arguments."); endif - # Validate input array, make sure it is a cell array - if (isempty (obj)) - warning ("Request to write empty matrix - ignored."); - rstatus = 1; - return; - elseif (isnumeric (obj)) - obj = num2cell (obj); - elseif (ischar (obj)) - obj = {obj}; - printf ("(oct2xls: input character array converted to 1x1 cell)\n"); - elseif (~iscell (obj)) - error ("oct2xls: input array neither cell nor numeric array"); - endif - if (ndims (obj) > 2), error ("Only 2-dimensional arrays can be written to spreadsheet"); endif - # Cast all numerical values to double as spreadsheets only have double/boolean/text type + ## Validate input array, make sure it is a cell array + if (isempty (obj)) + warning ("Request to write empty matrix - ignored."); + rstatus = 1; + return; + elseif (isnumeric (obj)) + obj = num2cell (obj); + elseif (ischar (obj)) + obj = {obj}; + printf ("(oct2xls: input character array converted to 1x1 cell)\n"); + elseif (~iscell (obj)) + error ("oct2xls: input array neither cell nor numeric array"); + endif + if (ndims (obj) > 2) + error ("Only 2-dimensional arrays can be written to spreadsheet"); + endif + ## Cast all numerical values to double as spreadsheets only have double/boolean/text type idx = cellfun (@isnumeric, obj, "UniformOutput", true); obj(idx) = cellfun (@double, obj(idx), "UniformOutput", false); - # Check xls file pointer struct - test1 = ~isfield (xls, "xtype"); - test1 = test1 || ~isfield (xls, "workbook"); - test1 = test1 || isempty (xls.workbook); - test1 = test1 || isempty (xls.app); - test1 = test1 || ~ischar (xls.xtype); - if (test1) - error ("Invalid xls file pointer struct"); - endif + ## Check xls file pointer struct + test1 = ~isfield (xls, "xtype"); + test1 = test1 || ~isfield (xls, "workbook"); + test1 = test1 || isempty (xls.workbook); + test1 = test1 || isempty (xls.app); + test1 = test1 || ~ischar (xls.xtype); + 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 # 3"); endif + ## 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"); + ## Check range + if (~isempty (crange) && ~ischar (crange)) + error ("Character string expected for arg # 4 (range)"); elseif (isempty (crange)) - crange = ''; + crange = ""; endif - # Various options - if (isempty (spsh_opts)) - spsh_opts.formulas_as_text = 0; - # other options to be implemented here - elseif (isstruct (spsh_opts)) - if (~isfield (spsh_opts, 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif - # other options to be implemented here - else - error ("Structure expected for arg # 5"); - endif - - if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified.\n"); endif - - # Select interface to be used - if (strcmpi (xls.xtype, 'COM')) - # ActiveX / COM - [xls, rstatus] = __COM_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); - elseif (strcmpi (xls.xtype, 'POI')) - # Invoke Java and Apache POI - [xls, rstatus] = __POI_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); - elseif (strcmpi (xls.xtype, 'JXL')) - # Invoke Java and JExcelAPI - [xls, rstatus] = __JXL_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); - elseif (strcmpi (xls.xtype, 'OXS')) - # Invoke Java and OpenXLS ##### Not complete, saving file doesn't work yet! - printf ('Sorry, writing with OpenXLS not reliable => not supported yet\n'); -# [xls, rstatus] = __OXS_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); - elseif (strcmpi (xls.xtype, 'UNO')) - # Invoke Java and UNO bridge (OpenOffice.org) - [xls, rstatus] = __UNO_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); -# elseif (strcmpi (xls.xtype, '<whatever>')) -# <Other Excel interfaces> - else - error (sprintf ("oct2xls: unknown Excel .xls interface - %s.", xls.xtype)); - endif + ## Various options + if (isempty (spsh_opts)) + spsh_opts.formulas_as_text = 0; + ## other options to be implemented here + elseif (isstruct (spsh_opts)) + if (~isfield (spsh_opts, "formulas_as_text")) + spsh_opts.formulas_as_text = 0; + endif + ## other options to be implemented here + + else + error ("Structure expected for arg # 5"); + endif + + if (nargout < 1) + printf ("Warning: no output spreadsheet file pointer specified.\n"); + endif + + ## Select interface to be used + if (strcmpi (xls.xtype, "COM")) + ## ActiveX / COM + [xls, rstatus] = __COM_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); + elseif (strcmpi (xls.xtype, "POI")) + ## Invoke Java and Apache POI + [xls, rstatus] = __POI_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); + elseif (strcmpi (xls.xtype, "JXL")) + ## Invoke Java and JExcelAPI + [xls, rstatus] = __JXL_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); + elseif (strcmpi (xls.xtype, "OXS")) + ## Invoke Java and OpenXLS ##### Not complete, saving file doesn't work yet! + printf ("Sorry, writing with OpenXLS not reliable => not supported yet\n"); + ## [xls, rstatus] = __OXS_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); + elseif (strcmpi (xls.xtype, "UNO")) + ## Invoke Java and UNO bridge (OpenOffice.org) + [xls, rstatus] = __UNO_oct2spsh__ (obj, xls, wsh, crange, spsh_opts); +##elseif (strcmpi (xls.xtype, "<whatever>")) + ##<Other Excel interfaces> + else + error (sprintf ("oct2xls: unknown Excel .xls interface - %s.", xls.xtype)); + endif endfunction
--- a/main/io/inst/ods2oct.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/ods2oct.m Wed Oct 24 21:43:38 2012 +0000 @@ -124,13 +124,14 @@ ## 2012-06-08 Support for odfdom-incubator 0.8.8 ## '' Replaced tabs by double space ## 2012-10-12 Moved all interface-specific subfubcs into ./private +## 2012-10-24 Style fixes ## ## Latest subfunc update: 2012-10-12 function [ rawarr, ods, rstatus ] = ods2oct (ods, wsh=1, datrange=[], spsh_opts=[]) - # Check if ods struct pointer seems valid - if (~isstruct (ods)), error ("File ptr struct expected for arg @ 1"); endif + ## Check if ods struct pointer seems valid + if (~isstruct (ods)); error ("File ptr struct expected for arg @ 1"); endif test1 = ~isfield (ods, "xtype"); test1 = test1 || ~isfield (ods, "workbook"); test1 = test1 || isempty (ods.workbook); @@ -138,64 +139,74 @@ if (test1) error ("Arg #1 is an invalid ods file struct"); endif - # Check worksheet ptr - if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 2"); endif - # Check range - if (~(isempty (datrange) || ischar (datrange))), error ("Character string (range) expected for arg # 3"); endif - # Check & setup options struct + ## Check worksheet ptr + if (~(ischar (wsh) || isnumeric (wsh))) + error ("Integer (index) or text (wsh name) expected for arg # 2"); + endif + ## Check range + if (~(isempty (datrange) || ischar (datrange))) + error ("Character string (range) expected for arg # 3"); + endif + ## Check & setup options struct if (nargin < 4 || isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; spsh_opts.strip_array = 1; - # Other options here + ## Other options here: + elseif (~isstruct (spsh_opts)) error ("struct expected for OPTIONS argument (# 4)"); else - if (~isfield (spsh_opts, 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif - if (~isfield (spsh_opts, 'strip_array')), spsh_opts.strip_array = 1; endif - % Future options: + if (~isfield (spsh_opts, "formulas_as_text")) + spsh_opts.formulas_as_text = 0; + endif + if (~isfield (spsh_opts, "strip_array")) + spsh_opts.strip_array = 1; + endif + ## Future options: + endif - # Select the proper interfaces - if (strcmp (ods.xtype, 'OTK')) - # Read ods file tru Java & ODF toolkit + ## Select the proper interfaces + if (strcmp (ods.xtype, "OTK")) + ## Read ods file tru Java & ODF toolkit switch ods.odfvsn - case '0.7.5' + case "0.7.5" [rawarr, ods] = __OTK_ods2oct__ (ods, wsh, datrange, spsh_opts); - case {'0.8.6', '0.8.7', '0.8.8'} + case {"0.8.6", "0.8.7", "0.8.8"} [rawarr, ods] = __OTK_spsh2oct__ (ods, wsh, datrange, spsh_opts); otherwise error ("Unsupported odfdom version or invalid ods file pointer."); endswitch - elseif (strcmp (ods.xtype, 'JOD')) - # Read ods file tru Java & jOpenDocument. JOD doesn't know about formulas :-( + elseif (strcmp (ods.xtype, "JOD")) + ## Read ods file tru Java & jOpenDocument. JOD doesn't know about formulas :-( [rawarr, ods] = __JOD_spsh2oct__ (ods, wsh, datrange); - elseif (strcmp (ods.xtype, 'UNO')) - # Read ods file tru Java & UNO + elseif (strcmp (ods.xtype, "UNO")) + ## Read ods file tru Java & UNO [rawarr, ods] = __UNO_spsh2oct__ (ods, wsh, datrange, spsh_opts); -# elseif - # ---- < Other interfaces here > + ##elseif + ## ---- < Other interfaces here > else error (sprintf ("ods2oct: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); endif rstatus = ~isempty (rawarr); - # Optionally strip empty outer rows and columns & keep track of original data location + ## Optionally strip empty outer rows and columns & keep track of original data location if (spsh_opts.strip_array && rstatus) - emptr = cellfun ('isempty', rawarr); + emptr = cellfun ("isempty", rawarr); if (all (all (emptr))) rawarr = {}; ods.limits= []; else nrows = size (rawarr, 1); ncols = size (rawarr, 2); irowt = 1; - while (all (emptr(irowt, :))), irowt++; endwhile + while (all (emptr(irowt, :))); irowt++; endwhile irowb = nrows; - while (all (emptr(irowb, :))), irowb--; endwhile + while (all (emptr(irowb, :))); irowb--; endwhile icoll = 1; - while (all (emptr(:, icoll))), icoll++; endwhile + while (all (emptr(:, icoll))); icoll++; endwhile icolr = ncols; - while (all (emptr(:, icolr))), icolr--; endwhile + while (all (emptr(:, icolr))); icolr--; endwhile # Crop outer rows and columns and update limits rawarr = rawarr(irowt:irowb, icoll:icolr);
--- a/main/io/inst/odsclose.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/odsclose.m Wed Oct 24 21:43:38 2012 +0000 @@ -68,63 +68,70 @@ ## 2012-09-03 Extended file renaming section to xlsclose equivalent ## 2012-10-12 Move most interface-specific code to ./private subfuncs ## '' Move "file ptr preserved" message to proper else clause +## 2012-10-23 Style fixes function [ ods ] = odsclose (ods, varargs) - # If needed warn that dangling spreadsheet pointers may be left - if (nargout < 1) warning ("return argument missing - ods invocation not reset."); endif + ## If needed warn that dangling spreadsheet pointers may be left + if (nargout < 1) + warning ("return argument missing - ods invocation not reset."); + endif force = 0; if (nargin > 1) for ii=2:nargin - if (strcmp (lower (varargin{ii}), "force")) - # Close .ods anyway even if write errors occur + if (strcmpi(varargin{ii}, "force")) + ## Close .ods anyway even if write errors occur force = 1; - elseif (~isempty (strfind (tolower (varargin{ii}), '.'))) - # Apparently a file name. First some checks.... + elseif (~isempty (strfind (tolower (varargin{ii}), "."))) + ## Apparently a file name. First some checks.... if (ods.changed == 0 || ods.changed > 2) warning ("File %s wasn't changed, new filename ignored.", ods.filename); - elseif (~strcmp (xls.xtype, 'UNO') && isempty (strfind ( lower (filename), '.ods'))) - # UNO will write any file type, all other interfaces only .ods - error ('.ods suffix lacking in filename %s', filename); + elseif (~strcmp (xls.xtype, "UNO") && ... + isempty (strfind ( lower (filename), ".ods"))) + ## UNO will write any file type, all other interfaces only .ods + error (".ods suffix lacking in filename %s", filename); else - # Preprocessing / -checking ready. Assign filename arg to file ptr struct + ## Preprocessing / -checking ready. + ## Assign filename arg to file ptr struct ods.nfilename = filename; endif endif endfor endif - if (strcmp (ods.xtype, 'OTK')) - # Java & ODF toolkit + if (strcmp (ods.xtype, "OTK")) + ## Java & ODF toolkit ods = __OTK_spsh_close__ (ods, force); - elseif (strcmp (ods.xtype, 'JOD')) - # Java & jOpenDocument + elseif (strcmp (ods.xtype, "JOD")) + ## Java & jOpenDocument ods = __JOD_spsh_close__ (ods); - elseif (strcmp (ods.xtype, 'UNO')) - # Java & UNO bridge + elseif (strcmp (ods.xtype, "UNO")) + ## Java & UNO bridge ods = __UNO_spsh_close__ (ods, force); -# elseif ---- < Other interfaces here > + ##elseif ---- < Other interfaces here > else - error (sprintf ("ods2close: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); + error (sprintf ("ods2close: unknown OpenOffice.org .ods interface - %s.",... + ods.xtype)); endif if (ods.changed && ods.changed < 3) - error ( sprintf ("Could not save file %s - read-only or in use elsewhere?", ods.filename)); + error (sprintf ("Could not save file %s - read-only or in use elsewhere?",... + ods.filename)); if (force) ods = []; else printf ("(File pointer preserved)\n"); endif else - # Reset file pointer + ## Reset file pointer ods = []; endif
--- a/main/io/inst/odsfinfo.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/odsfinfo.m Wed Oct 24 21:43:38 2012 +0000 @@ -78,37 +78,37 @@ ## 2012-03-01 Fix wrong cell refs in UNO section ("(..)" rather than "{..}" ## 2012-06-08 Support for odfdom-0.8.8-incubator ## 2012-10-12 Moved all interface-specific code into ./private subfuncs +## 2012-10-24 Style fixes function [ filetype, sh_names ] = odsfinfo (filename, reqintf=[]) - persistent str2; str2 = ' '; # 33 spaces + persistent str2; str2 = " "; # 33 spaces persistent lstr2; lstr2 = length (str2); toscreen = nargout < 1; ods = odsopen (filename, 0, reqintf); - # If no ods support was found, odsopen will have complained. Just return here + ## If no ods support was found, odsopen will have complained. Just return here if (isempty (ods)), return; endif - filetype = 'OpenOffice.org Calc Document'; - - persistent adj_str; adj_str = ' '; # 30 char filler string + filetype = "OpenOffice.org Calc Document"; - # To save execution time, only proceed if sheet names are wanted + ## To save execution time, only proceed if sheet names are wanted if ~(nargout == 1) - if (strcmp (ods.xtype, 'OTK')) + if (strcmp (ods.xtype, "OTK")) [sh_names] = __OTK_spsh_info__ (ods); - elseif (strcmp (ods.xtype, 'JOD')) + elseif (strcmp (ods.xtype, "JOD")) [sh_names] = __JOD_spsh_info__ (ods); - elseif (strcmp (ods.xtype, 'UNO')) + elseif (strcmp (ods.xtype, "UNO")) [sh_names] = __UNO_spsh_info__ (ods); else ## Below error will have been catched in odsopen() above -# error (sprintf ("odsfinfo: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); + ##error (sprintf ("odsfinfo: unknown OpenOffice.org .ods interface - %s.",... + ## ods.xtype)); endif endif @@ -119,7 +119,7 @@ for ii=1:sh_cnt str1 = sprintf ("%3d: %s", ii, sh_names{ii, 1}); if (index (sh_names{ii, 2}, ":")) - str3 = ['(Used range ~ ' sh_names{ii, 2} ')']; + str3 = ["(Used range ~ " sh_names{ii, 2} ")"]; else str3 = sh_names{ii, 2}; endif
--- a/main/io/inst/odsopen.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/odsopen.m Wed Oct 24 21:43:38 2012 +0000 @@ -68,36 +68,46 @@ ## Updates: ## 2009-12-30 ....<forgot what is was > ## 2010-01-17 Make sure proper dimensions are checked in parsed javaclasspath -## 2010-01-24 Added warning when trying to create a new spreadsheet using jOpenDocument +## 2010-01-24 Added warning when trying to create a new spreadsheet using +## jOpenDocument ## 2010-03-01 Removed check for rt.jar in javaclasspath ## 2010-03-04 Slight texinfo adaptation (reqd. odfdom version = 0.7.5) ## 2010-03-14 Updated help text (section on readwrite) ## 2010-06-01 Added check for jOpenDocument version + suitable warning ## 2010-06-02 Added ";" to supress debug stuff around lines 115 -## '' Moved JOD version check to subfunc getodsinterfaces -## '' Fiddled ods.changed flag when creating a spreadsheet to avoid unnamed 1st sheets -## 2010-08-23 Added version field "odfvsn" to ods file ptr, set in getodsinterfaces() (odfdom) -## '' Moved JOD version check to this func from subfunc getodsinterfaces() +## '' Moved JOD version check to subfunc getodsinterfaces +## '' Fiddled ods.changed flag when creating a spreadsheet to avoid +## unnamed 1st sheets +## 2010-08-23 Added version field "odfvsn" to ods file ptr, set in +## getodsinterfaces() (odfdom) +## '' Moved JOD version check to this func from subfunc +## getodsinterfaces() ## '' Full support for odfdom 0.8.6 (in subfunc) ## 2010-08-27 Improved help text ## 2010-10-27 Improved tracking of file changes tru ods.changed ## 2010-11-12 Small changes to help text -## '' Added try-catch to file open sections to create fallback to other intf +## '' Added try-catch to file open sections to create fallback to other +## interface ## 2011-05-06 Experimental UNO support ## 2011-05-18 Creating new spreadsheet docs in UNO now works ## 2011-06-06 Tamed down interface verbosity on first startup ## '' Multiple requested interfaces now possible -## 2011-09-03 Reset chkintf if no ods support was found to allow full interface rediscovery -## (otherwise javaclasspath additions will never be picked up) +## 2011-09-03 Reset chkintf if no ods support found to allow full interface +## rediscovery (otherwise javaclasspath additions will never be +## picked up) ## 2012-01-26 Fixed "seealso" help string ## 2012-02-26 Added ";" to suppress echo of filename f UNO -## 2012-06-06 Made interface checking routine less verbose when same requested interface -## was used consecutively +## 2012-06-06 Made interface checking routine less verbose when same requested +## interface was used consecutively ## 2012-09-03 (in UNO section) replace canonicalize_file_name on non-Windows to ## make_absolute_filename (see bug #36677) ## '' (in UNO section) web adresses need only two consecutive slashes ## 2012-10-07 Moved subfunc getodsinterfaces to ./private -## 2012-10-12 Moved all interface-specific file open stanzas to separate ./private funcs +## 2012-10-12 Moved all interface-specific file open stanzas to separate +## ./private funcs +## 2012-10-24 Style fixes +## '' Removed fall-back options for .sxc. Other than .xls this can be +## inferred from file suffix function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) @@ -106,46 +116,51 @@ odsinterfaces = struct ( "OTK", [], "JOD", [], "UNO", [] ); chkintf = 1; endif - if (isempty (lastintf)); lastintf = '---'; endif + if (isempty (lastintf)); lastintf = "---"; endif - if (nargout < 1) usage ("ODS = odsopen (ODSfile, [Rw]). But no return argument specified!"); endif + if (nargout < 1) + usage ("ODS = odsopen (ODSfile, [Rw]). But no return argument specified!"); + endif if (~isempty (reqinterface)) - if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif - # Turn arg3 into cell array if needed + if ~(ischar (reqinterface) || iscell (reqinterface)) + usage ("Arg # 3 (interface) not recognized"); + endif + ## Turn arg3 into cell array if needed if (~iscell (reqinterface)), reqinterface = {reqinterface}; endif ## Check if previously used interface matches a requested interface - if (isempty (regexpi (reqinterface, lastintf, 'once'){1})) + if (isempty (regexpi (reqinterface, lastintf, "once"){1})) ## New interface requested odsinterfaces.OTK = 0; odsinterfaces.JOD = 0; odsinterfaces.UNO = 0; for ii=1:numel (reqinterface) reqintf = toupper (reqinterface {ii}); - # Try to invoke requested interface(s) for this call. Check if it - # is supported anyway by emptying the corresponding var. - if (strcmp (reqintf, 'OTK')) + ## Try to invoke requested interface(s) for this call. Check if it + ## is supported anyway by emptying the corresponding var. + if (strcmp (reqintf, "OTK")) odsinterfaces.OTK = []; - elseif (strcmp (reqintf, 'JOD')) + elseif (strcmp (reqintf, "JOD")) odsinterfaces.JOD = []; - elseif (strcmp (reqintf, 'UNO')) + elseif (strcmp (reqintf, "UNO")) odsinterfaces.UNO = []; else - usage (sprintf ("Unknown .ods interface \"%s\" requested. Only OTK, JOD or UNO supported\n", reqinterface{})); + usage (sprintf (["Unknown .ods interface \"%s\" requested.\n" ... + "Only OTK, JOD or UNO supported\n"], reqinterface{})); endif endfor + printf ("Checking requested interface(s):\n"); odsinterfaces = getodsinterfaces (odsinterfaces); - # Well, is/are the requested interface(s) supported on the system? - # FIXME check for multiple interfaces + ## Well, is/are the requested interface(s) supported on the system? odsintf_cnt = 0; for ii=1:numel (reqinterface) if (~odsinterfaces.(toupper (reqinterface{ii}))) - # No it aint + ## No it aint printf ("%s is not supported.\n", toupper (reqinterface{ii})); else ++odsintf_cnt; endif endfor - # Reset interface check indicator if no requested support found + ## Reset interface check indicator if no requested support found if (~odsintf_cnt) chkintf = []; ods = []; @@ -154,69 +169,79 @@ endif endif - # Var rw is really used to avoid creating files when wanting to read, or - # not finding not-yet-existing files when wanting to write. + ## Var rw is really used to avoid creating files when wanting to read, or + ## not finding not-yet-existing files when wanting to write a new one. + ## Be sure it's either 0 or 1 initially + if (rw), rw = 1; endif - if (rw), rw = 1; endif # Be sure it's either 0 or 1 initially - - # Check if ODS file exists. Set open mode based on rw argument - if (rw), fmode = 'r+b'; else fmode = 'rb'; endif + ## Check if ODS file exists. Set open mode based on rw argument + if (rw), fmode = "r+b"; else fmode = "rb"; endif fid = fopen (filename, fmode); if (fid < 0) - if (~rw) # Read mode requested but file doesn't exist + if (~rw) ## Read mode requested but file doesn't exist err_str = sprintf ("File %s not found\n", filename); error (err_str) - else # For writing we need more info: - fid = fopen (filename, 'rb'); # Check if it can be opened for reading - if (fid < 0) # Not found => create it + else + ## For writing we need more info: + fid = fopen (filename, "rb"); + ## Check if it can be opened for reading + if (fid < 0) ## Not found => create it printf ("Creating file %s\n", filename); rw = 3; - else # Found but not writable = error - fclose (fid); # Do not forget to close the handle neatly - error (sprintf ("Write mode requested but file %s is not writable\n", filename)) + else ## Found but not writable = error + fclose (fid); ## Do not forget to close the handle neatly + error (sprintf ("Write mode requested but file %s is not writable\n",... + filename)) endif endif else - # close file anyway to avoid Java errors + ## Close file anyway to avoid Java errors fclose (fid); endif -# Check for the various ODS interfaces. No problem if they've already -# been checked, getodsinterfaces (far below) just returns immediately then. + ## Check for the various ODS interfaces. No problem if they've already + ## been checked, getodsinterfaces (far below) just returns immediately then. [odsinterfaces] = getodsinterfaces (odsinterfaces); -# Supported interfaces determined; now check ODS file type. + ## Supported interfaces determined; now check ODS file type. + + chk3 = strcmpi (filename(end-3:end), '.ods'); + ## Only jOpenDocument (JOD) can read from .sxc files, but only if odfvsn = 2 + chk4 = strcmpi (filename(end-3:end), '.sxc'); -# chk1 = strcmp (tolower (filename(end-3:end)), '.ods'); - # Only jOpenDocument (JOD) can read from .sxc files, but only if odfvsn = 2 - chk2 = strcmp (tolower (filename(end-3:end)), '.sxc'); -# if (~chk1) -# error ("Currently ods2oct can only read reliably from .ods files") -# endif + ods = struct ("xtype", [], + "app", [], + "filename", [], + "workbook", [], + "changed", 0, + "limits", [], + "odfvsn", []); - ods = struct ("xtype", [], "app", [], "filename", [], "workbook", [], "changed", 0, "limits", [], "odfvsn", []); - - # Preferred interface = OTK (ODS toolkit & xerces), so it comes first. - # Keep track of which interface is selected. Can be used for fallback to other intf + ## Preferred interface = OTK (ODS toolkit & xerces), so it comes first. + ## Keep track of which interface is selected. Can be used for fallback to other intf odssupport = 0; - if (odsinterfaces.OTK && ~odssupport) - [ ods, odssupport, lastintf ] = __OTK_spsh_open__ (ods, rw, filename, odssupport, chk2, odsinterfaces); + if (odsinterfaces.OTK && ~odssupport && chk3) + [ ods, odssupport, lastintf ] = ... + __OTK_spsh_open__ (ods, rw, filename, odssupport); endif - if (odsinterfaces.JOD && ~odssupport) - [ ods, odssupport, lastintf ] = __JOD_spsh_open__ (ods, rw, filename, odssupport); + if (odsinterfaces.JOD && ~odssupport && (chk3 || chk4)) + [ ods, odssupport, lastintf ] = ... + __JOD_spsh_open__ (ods, rw, filename, odssupport); endif if (odsinterfaces.UNO && ~odssupport) - [ ods, odssupport, lastintf ] = __UNO_spsh_open__ (ods, rw, filename, odssupport); + [ ods, odssupport, lastintf ] = ... + __UNO_spsh_open__ (ods, rw, filename, odssupport); endif -# if -# <other interfaces here> + ## if + ## <other interfaces here> if (~odssupport) + ## Below message follows after getodsinterfaces printf ("None.\n"); warning ("No support for OpenOffice.org .ods I/O"); ods = []; @@ -227,10 +252,10 @@ # message is to be given when saving a newly created ods file. ods.changed = rw; - # Until something was written to existing files we keep status "unchanged". # ods.changed = 0 (existing/only read from), 1 (existing/data added), 2 (new, # data added) or 3 (pristine, no data added). - if (ods.changed == 1) ods.changed = 0; endif + # Until something was written to existing files we keep status "unchanged". + if (ods.changed == 1); ods.changed = 0; endif endif endfunction
--- a/main/io/inst/odsread.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/odsread.m Wed Oct 24 21:43:38 2012 +0000 @@ -119,10 +119,11 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-03-07 Updated texinfo help text ## 2012-06-08 Tabs replaced by double space +## 2012-10-24 Style fixes function [ numarr, txtarr, rawarr, lim ] = odsread (filename, wsh=1, datrange=[], reqintf=[]) - if (nargin < 1 || isempty (findstr ('.ods', tolower (filename)))) + if (nargin < 1 || isempty (findstr (".ods", tolower (filename)))) usage ("odsread: at least a filename incl. suffix is needed"); endif if (nargout < 1)
--- a/main/io/inst/odswrite.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/odswrite.m Wed Oct 24 21:43:38 2012 +0000 @@ -95,13 +95,14 @@ ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral ## 2010-03-07 Updated texinfo help text ## 2012-06-08 Tabs replaced by double space +## 2012-10-24 Style fixes -function [ rstatus ] = odswrite (filename, data, wsh=1, crange='', reqintf=[]) +function [ rstatus ] = odswrite (filename, data, wsh=1, crange="", reqintf=[]) - # Input validity checks + ## Input validity checks if (nargin < 2) usage ("Insufficient arguments - see 'help odswrite'"); - elseif (~ischar (filename) || isempty (findstr ('.ods', tolower (filename)))) + elseif (~ischar (filename) || isempty (findstr (".ods", tolower (filename)))) error ("First argument must be a filename (incl. .ods suffix for OTK & JOD)"); endif @@ -110,7 +111,7 @@ if (~isempty (ods)) [ods, rstatus] = oct2ods (data, ods, wsh, crange); - # If rstatus was not OK, reset change indicator in ods pointer + ## If rstatus was not OK, reset change indicator in ods pointer if (~rstatus) ods.changed = rstatus; warning ("odswrite: data transfer errors, file not rewritten");
--- a/main/io/inst/parsecell.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/parsecell.m Wed Oct 24 21:43:38 2012 +0000 @@ -59,15 +59,16 @@ ## 2010-08-25 Added option for second argument to be a file ptr ## 2010-10-15 Simplified code for numerical array ## 2011-05-17 Fixed subscript indexing bug in cropping section when rawarr is -## " numeric scalar +## '' numeric scalar ## 2011-09-08 Copyright string updated ## 2012-01-26 Fixed "seealso" help string +## 2012-10-24 Style fixes function [ numarr, txtarr, lim ] = parsecell (rawarr, arg2=[]) if (isstruct (arg2)) - # Assume a file ptr has been supplied - if (isfield (arg2, 'limits')) + ## Assume a file ptr has been supplied + if (isfield (arg2, "limits")) rawlimits = arg2.limits; else warning ("Invalid file ptr supplied to parsecell() - limits ignored."); @@ -82,7 +83,7 @@ txtarr = {}; if (~isempty (rawarr)) - # Valid data returned. Divide into numeric & text arrays + ## Valid data returned. Divide into numeric & text arrays no_txt = 0; no_num = 0; if (isnumeric ([rawarr{:}])) numarr = num2cell (rawarr); @@ -91,70 +92,71 @@ txtarr = cellstr (rawarr); no_num = 1; endif - # Prepare parsing + ## Prepare parsing [nrows, ncols] = size (rawarr); - # Find text entries in raw data cell array - txtptr = cellfun ('isclass', rawarr, 'char'); + ## Find text entries in raw data cell array + txtptr = cellfun ("isclass", rawarr, "char"); if (~no_txt) - # Prepare text array. Create placeholder for text cells + ## Prepare text array. Create placeholder for text cells txtarr = cell (size (rawarr)); - txtarr(:) = {''}; + txtarr(:) = {""}; if (any (any (txtptr))) - # Copy any text cells found into place holder + ## Copy any text cells found into place holder txtarr(txtptr) = rawarr(txtptr); - # Clean up text array (find leading / trailing empty - # rows & columns) + ## Clean up text array (find leading / trailing empty + ## rows & columns) irowt = 1; - while (~any (txtptr(irowt, :))) irowt++; endwhile + while (~any (txtptr(irowt, :))); irowt++; endwhile irowb = nrows; - while (~any (txtptr(irowb, :))) irowb--; endwhile + while (~any (txtptr(irowb, :))); irowb--; endwhile icoll = 1; - while (~any (txtptr(:, icoll))) icoll++; endwhile + while (~any (txtptr(:, icoll))); icoll++; endwhile icolr = ncols; - while (~any (txtptr(:, icolr))) icolr--; endwhile - # Crop textarray + while (~any (txtptr(:, icolr))); icolr--; endwhile + ## Crop textarray txtarr = txtarr(irowt:irowb, icoll:icolr); lim.txtlimits = [icoll, icolr; irowt, irowb]; if (~isempty (rawlimits)) correction = [1; 1]; - lim.txtlimits (:,1) = lim.txtlimits(:,1) + rawlimits(:,1) - correction; - lim.txtlimits (:,2) = lim.txtlimits(:,2) + rawlimits(:,1) - correction; + lim.txtlimits(:,1) = lim.txtlimits(:,1) + rawlimits(:,1) - correction; + lim.txtlimits(:,2) = lim.txtlimits(:,2) + rawlimits(:,1) - correction; endif else - # If no text cells found return empty text array + ## If no text cells found return empty text array txtarr = {}; endif endif if (~no_num) - # Prepare numeric array. Set all text & empty cells to - # NaN. First get their locations - emptr = cellfun ('isempty', rawarr); + ## Prepare numeric array. Set all text & empty cells to NaN. + ## First get their locations + emptr = cellfun ("isempty", rawarr); emptr(find (txtptr)) = 1; if (all (all (emptr))) numarr= []; else - # Find leading & trailing empty rows + ## Find leading & trailing empty rows irowt = 1; - while (all(emptr(irowt, :))) irowt++; endwhile + while (all(emptr(irowt, :))); irowt++; endwhile irowb = nrows; - while (all(emptr(irowb, :))) irowb--; endwhile + while (all(emptr(irowb, :))); irowb--; endwhile icoll = 1; - while (all(emptr(:, icoll))) icoll++; endwhile + while (all(emptr(:, icoll))); icoll++; endwhile icolr = ncols; - while (all(emptr(:, icolr))) icolr--; endwhile + while (all(emptr(:, icolr))); icolr--; endwhile - # Pre-crop rawarr + ## Pre-crop rawarr rawarr = rawarr (irowt:irowb, icoll:icolr); - # Build numerical array + ## Build numerical array numarr = zeros (irowb-irowt+1, icolr-icoll+1); - # Watch out for scalar (non-empty) numarr where emptr = 0 + ## Watch out for scalar (non-empty) numarr where emptr = 0 if (sum (emptr(:)) > 0) - numarr (emptr(irowt:irowb, icoll:icolr)) = NaN; + numarr(emptr(irowt:irowb, icoll:icolr)) = NaN; endif - numarr(~emptr(irowt:irowb, icoll:icolr)) = cell2mat (rawarr(~emptr(irowt:irowb, icoll:icolr))); - # Save limits + numarr(~emptr(irowt:irowb, icoll:icolr)) = ... + cell2mat (rawarr(~emptr(irowt:irowb, icoll:icolr))); + ## Save limits lim.numlimits = [icoll, icolr; irowt, irowb]; if (~isempty (rawlimits)) correction = [1; 1];
--- a/main/io/inst/private/__COM_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__COM_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -17,29 +17,31 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2010-10-07 +## Updates: ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ trow, brow, lcol, rcol ] = __COM_getusedrange__ (xls, ii) sh = xls.workbook.Worksheets (ii); - # Decipher used range. Beware, UsedRange() returns *cached* rectangle of - # all spreadsheet cells containing *anything*, including just formatting - # (i.e., empty cells are included too). ==> This is an approximation only + ## Decipher used range. Beware, UsedRange() returns *cached* rectangle of + ## all spreadsheet cells containing *anything*, including just formatting + ## (i.e., empty cells are included too). ==> This is an approximation only allcells = sh.UsedRange; - # Get top left cell as a Range object + ## Get top left cell as a Range object toplftcl = allcells.Columns(1).Rows(1); - # Count number of rows & cols in virtual range from A1 to top left cell + ## Count number of rows & cols in virtual range from A1 to top left cell lcol = sh.Range ("A1", toplftcl).columns.Count; trow = sh.Range ("A1", toplftcl).rows.Count; - # Add real occupied rows & cols to obtain end row & col + ## Add real occupied rows & cols to obtain end row & col brow = trow + allcells.rows.Count() - 1; rcol = lcol + allcells.columns.Count() - 1; - # Check if there are real data + ## Check if there are real data if ((lcol == rcol) && (trow = brow)) if (isempty (toplftcl.Value)) trow = brow = lcol = rcol = 0;
--- a/main/io/inst/private/__COM_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__COM_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -61,10 +61,14 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-02-27 Copyright strings updated ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ xls, status ] = __COM_oct2spsh__ (obj, xls, wsh, crange, spsh_opts) - # Preliminary sanity checks + ## Preliminary sanity checks + ## FIXME - Excel can write to much more than .xls/.xlsx (but not to all + ## formats with multiple sheets): + ## .wk1 .wk3 .wk4 .csv .pxl .html .dbf .txt .prn .wks .wq1 .dif if (~strmatch (lower (xls.filename(end-4:end)), '.xls')) error ("COM interface can only write to Excel .xls or .xlsx files") endif @@ -73,79 +77,82 @@ elseif (size (wsh, 2) > 31) error ("Illegal worksheet name - too long") endif - # Check to see if ActiveX is still alive + ## Check to see if ActiveX is still alive try wb_cnt = xls.workbook.Worksheets.count; catch error ("ActiveX invocation in file ptr struct seems non-functional"); end_try_catch - # define some constants not yet in __COM__.cc - xlWorksheet = -4167; # xlChart= 4; - # scratch vars + ## define some constants not yet in __COM__.cc + xlWorksheet = -4167; ## xlChart= 4; + ## scratch vars status = 0; - # Parse date ranges + ## Parse date ranges [nr, nc] = size (obj); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); lowerright = calccelladdress (trow + nrows - 1, lcol + ncols - 1); - crange = [topleft ':' lowerright]; + crange = [topleft ":" lowerright]; if (nrows < nr || ncols < nc) warning ("Array truncated to fit in range"); obj = obj(1:nrows, 1:ncols); endif - # Cleanup NaNs. Find where they are and mark as empty - ctype = [0 1 2 3 4]; # Numeric Boolean Text Formula Empty + ## Cleanup NaNs. Find where they are and mark as empty + ctype = [0 1 2 3 4]; ## Numeric Boolean Text Formula Empty typearr = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts); - # Make cells now indicated to be empty, empty + ## Make cells now indicated to be empty, empty fptr = ~(4 * (ones (size (typearr))) .- typearr); obj(fptr) = cellfun (@(x) [], obj(fptr), "Uniformoutput", false); if (spsh_opts.formulas_as_text) - # find formulas (designated by a string starting with "=" and ending in ")") - fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) && strncmp (x(end:end), ")", 1), obj); - # ... and add leading "'" character + ## find formulas (designated by a string starting with "=" and ending in ")") + fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) ... + && strncmp (x(end:end), ")", 1), obj); + ## ... and add leading "'" character obj(fptr) = cellfun (@(x) ["'" x], obj(fptr), "Uniformoutput", false); endif clear fptr; if (xls.changed < 3) - # Existing file OR a new file with data added in a previous oct2xls call. - # Some involved investigation is needed to preserve - # existing data that shouldn't be touched. - # - # See if desired *sheet* name exists. + ## Existing file OR a new file with data added in a previous oct2xls call. + ## Some involved investigation is needed to preserve + ## existing data that shouldn't be touched. + ## + ## See if desired *sheet* name exists. old_sh = 0; ws_cnt = xls.workbook.Sheets.count; if (isnumeric (wsh)) if (wsh <= ws_cnt) - # Here we check for sheet *position* in the sheet stack - # rather than a name like "Sheet<Number>" + ## Here we check for sheet *position* in the sheet stack + ## rather than a name like "Sheet<Number>" old_sh = wsh; else - # wsh > nr of sheets; proposed new sheet name. - # This sheet name can already exist to the left in the sheet stack! + ## wsh > nr of sheets; proposed new sheet name. + ## This sheet name can already exist to the left in the sheet stack! shnm = sprintf ("Sheet%d", wsh); shnm1 = shnm; endif endif if (~old_sh) - # Check if the requested (or proposed) sheet already exists - # COM objects are not OO (yet?), so we need a WHILE loop + ## Check if the requested (or proposed) sheet already exists + ## COM objects are not OO (yet?), so we need a WHILE loop ii = 1; jj = 1; while ((ii <= ws_cnt) && ~old_sh) - # Get existing sheet names one by one + ## Get existing sheet names one by one sh_name = xls.workbook.Sheets(ii).name; if (~isnumeric (wsh) && strcmp (sh_name, wsh)) - # ...and check with requested sheet *name*... + ## ...and check with requested sheet *name*... old_sh = ii; elseif (isnumeric (wsh) && strcmp (sh_name, shnm)) - # ... or proposed new sheet name (corresp. to requested sheet *number*) + ## ... or proposed new sheet name (corresp. to requested sheet *number*) shnm = [shnm "_"]; - ii = 0; # Also check if this new augmented sheet name exists... + ii = 0; ## Also check if this new augmented sheet name exists... if (strmatch (shnm1, sh_name)), jj++; endif - if (jj > 5) # ... but not unlimited times... - error (sprintf (" > 5 sheets named [_]Sheet%d already present!", wsh)); + if (jj > 5) ## ... but not unlimited times... + error (sprintf ... + (" > 5 sheets named [_]Sheet%d already present!", wsh)); endif endif ++ii; @@ -153,16 +160,16 @@ endif if (old_sh) - # Requested sheet exists. Check if it is a *work*sheet + ## Requested sheet exists. Check if it is a *work*sheet if ~(xls.workbook.Sheets(old_sh).Type == xlWorksheet) - # Error as you can't write data to Chart sheet + ## Error as you can't write data to Chart sheet error (sprintf ("Existing sheet '%s' is not type worksheet.", wsh)); else - # Simply point to the relevant sheet + ## Simply point to the relevant sheet sh = xls.workbook.Worksheets (old_sh); endif else - # Add a new worksheet. Earlier it was checked whether this is safe + ## Add a new worksheet. Earlier it was checked whether this is safe try sh = xls.workbook.Worksheets.Add (); catch @@ -174,25 +181,25 @@ sh.Name = shnm; printf ("Writing to worksheet %s\n", shnm); endif - # Prepare to move new sheet to right of the worksheet stack anyway - ws_cnt = xls.workbook.Worksheets.count; # New count needed - # Find where Excel has left it. We have to, depends on Excel version :-( + ## Prepare to move new sheet to right of the worksheet stack anyway + ws_cnt = xls.workbook.Worksheets.count; ## New count needed + ## Find where Excel has left it. We have to, depends on Excel version :-( ii = 1; while ((ii < ws_cnt+1) && ~strcmp (sh.Name, xls.workbook.Worksheets(ii).Name) == 1) ++ii; endwhile - # Excel can't move it beyond the current last one, so we need a trick. - # First move it to just before the last one.... + ## Excel can't move it beyond the current last one, so we need a trick. + ## First move it to just before the last one.... xls.workbook.Worksheets(ii).Move (before = xls.workbook.Worksheets(ws_cnt)); - # ....then move the last one before the new sheet. + ## ....then move the last one before the new sheet. xls.workbook.Worksheets (ws_cnt).Move (before = xls.workbook.Worksheets(ws_cnt - 1)); endif else - # The easy case: a new Excel file. Workbook was created in xlsopen. + ## The easy case: a new Excel file. Workbook was created in xlsopen. - # Delete empty non-used sheets, last one first + ## Delete empty non-used sheets, last one first xls.app.Application.DisplayAlerts = 0; ii = xls.workbook.Sheets.count; while (ii > 1) @@ -201,31 +208,32 @@ endwhile xls.app.Application.DisplayAlerts = 1; - # Write to first worksheet: + ## Write to first worksheet: sh = xls.workbook.Worksheets (1); - # Rename the sheet + ## Rename the sheet if (isnumeric (wsh)) sh.Name = sprintf ("Sheet%i", wsh); else sh.Name = wsh; endif - xls.changed = 2; # 3 => 2 + xls.changed = 2; ## 3 => 2 endif - # MG's original part. - # Save object in Excel sheet, starting at cell top_left_cell + ## MG's original part. + ## Save object in Excel sheet, starting at cell top_left_cell if (~isempty(obj)) r = sh.Range (crange); try r.Value = obj; catch - error (sprintf ("Cannot add data to worksheet %s in file %s\n", sh.Name, xls.filename)); + error (sprintf ("Cannot add data to worksheet %s in file %s\n",... + sh.Name, xls.filename)); end_try_catch delete (r); endif - # If we get here, all went OK + ## If we get here, all went OK status = 1; - xls.changed = max (xls.changed, 1); # If it was 2, preserve it. + xls.changed = max (xls.changed, 1); ## If it was 2, preserve it. endfunction
--- a/main/io/inst/private/__COM_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__COM_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -51,27 +51,30 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-06-06 Implemented "formulas_as_text option" ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [rawarr, xls, rstatus ] = __COM_spsh2oct__ (xls, wsh, crange, spsh_opts) rstatus = 0; rawarr = {}; - # Basic checks - if (nargin < 2) error ("__COM_spsh2oct__ needs a minimum of 2 arguments."); endif + ## Basic checks + if (nargin < 2) + error ("__COM_spsh2oct__ needs a minimum of 2 arguments."); + endif if (size (wsh, 2) > 31) warning ("Worksheet name too long - truncated") wsh = wsh(1:31); endif app = xls.app; wb = xls.workbook; - # Check to see if ActiveX is still alive + ## Check to see if ActiveX is still alive try wb_cnt = wb.Worksheets.count; catch error ("ActiveX invocation in file ptr struct seems non-functional"); end_try_catch - # Check & get handle to requested worksheet + ## Check & get handle to requested worksheet wb_cnt = wb.Worksheets.count; old_sh = 0; if (isnumeric (wsh)) @@ -84,7 +87,7 @@ old_sh = wsh; endif else - # Find worksheet number corresponding to name in wsh + ## Find worksheet number corresponding to name in wsh wb_cnt = wb.Worksheets.count; for ii =1:wb_cnt sh_name = wb.Worksheets(ii).name; @@ -102,10 +105,10 @@ nrows = 0; if ((nargin == 2) || (isempty (crange))) allcells = sh.UsedRange; - # Get actually used range indices + ## Get actually used range indices [trow, brow, lcol, rcol] = getusedrange (xls, old_sh); if (trow == 0 && brow == 0) - # Empty sheet + ## Empty sheet rawarr = {}; printf ("Worksheet '%s' contains no data\n", sh.Name); return; @@ -113,17 +116,17 @@ nrows = brow - trow + 1; ncols = rcol - lcol + 1; topleft = calccelladdress (trow, lcol); lowerright = calccelladdress (brow, rcol); - crange = [topleft ':' lowerright]; + crange = [topleft ":" lowerright]; endif else - # Extract top_left_cell from range + ## Extract top_left_cell from range [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); brow = trow + nrows - 1; rcol = lcol + ncols - 1; endif; if (nrows >= 1) - # Get object from Excel sheet, starting at cell top_left_cell + ## Get object from Excel sheet, starting at cell top_left_cell rr = sh.Range (crange); if (spsh_opts.formulas_as_text) rawarr = rr.Formula; @@ -132,14 +135,14 @@ endif delete (rr); - # Take care of actual singe cell range + ## Take care of actual singe cell range if (isnumeric (rawarr) || ischar (rawarr)) rawarr = {rawarr}; endif - # If we get here, all seems to have gone OK + ## If we get here, all seems to have gone OK rstatus = 1; - # Keep track of data rectangle limits + ## Keep track of data rectangle limits xls.limits = [lcol, rcol; trow, brow]; else error ("No data read from Excel file");
--- a/main/io/inst/private/__COM_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__COM_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -21,23 +21,23 @@ function [ xls ] = __COM_spsh_close__ (xls) - # If file has been changed, write it out to disk. - # - # Note: COM / VB supports other Excel file formats as FileFormatNum: - # 4 = .wks - Lotus 1-2-3 / Microsoft Works - # 6 = .csv - # -4158 = .txt - # 36 = .prn - # 50 = .xlsb - xlExcel12 (Excel Binary Workbook in 2007 with or without macro's) - # 51 = .xlsx - xlOpenXMLWorkbook (without macro's in 2007) - # 52 = .xlsm - xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007) - # 56 = .xls - xlExcel8 (97-2003 format in Excel 2007) - # (see Excel Help, VB reference, Enumerations, xlFileType) + ## If file has been changed, write it out to disk. + ## + ## Note: COM / VB supports other Excel file formats as FileFormatNum: + ## 4 = .wks - Lotus 1-2-3 / Microsoft Works + ## 6 = .csv + ## -4158 = .txt + ## 36 = .prn + ## 50 = .xlsb - xlExcel12 (Excel Binary Workbook in 2007 with or without macro's) + ## 51 = .xlsx - xlOpenXMLWorkbook (without macro's in 2007) + ## 52 = .xlsm - xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007) + ## 56 = .xls - xlExcel8 (97-2003 format in Excel 2007) + ## (see Excel Help, VB reference, Enumerations, xlFileType) - # xls.changed = 0: no changes: just close; - # 1: existing file with changes: save, close. - # 2: new file with data added: save, close - # 3: new file, no added added (empty): close & delete on disk + ## xls.changed = 0: no changes: just close; + ## 1: existing file with changes: save, close. + ## 2: new file with data added: save, close + ## 3: new file, no added added (empty): close & delete on disk xls.app.Application.DisplayAlerts = 0; try @@ -48,19 +48,19 @@ fname = xls.filename; endif if (xls.changed == 2) - # Probably a newly created, or renamed, Excel file -# printf ("Saving file %s ...\n", fname); + ## Probably a newly created, or renamed, Excel file +## printf ("Saving file %s ...\n", fname); xls.workbook.SaveAs (canonicalize_file_name (fname)); elseif (xls.changed == 1) - # Just updated existing Excel file + ## Just updated existing Excel file xls.workbook.Save (); endif xls.changed = 0; xls.workbook.Close (canonicalize_file_name (fname)); endif xls.app.Quit (); - delete (xls.workbook); # This statement actually closes the workbook - delete (xls.app); # This statement actually closes down Excel + delete (xls.workbook); ## This statement actually closes the workbook + delete (xls.app); ## This statement actually closes down Excel catch xls.app.Application.DisplayAlerts = 1; end_try_catch
--- a/main/io/inst/private/__COM_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__COM_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,12 +20,13 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## 2012-10-24 Style fixes function [sh_names] = __COM_spsh_info__ (xls) xlWorksheet = -4167; xlChart = 4; - # See if desired worksheet number or name exists + ## See if desired worksheet number or name exists sh_cnt = xls.workbook.Sheets.count; sh_names = cell (sh_cnt, 2); ws_cnt = 0; ch_cnt = 0; o_cnt = 0; @@ -34,14 +35,15 @@ if (xls.workbook.Sheets(ii).Type == xlWorksheet) [tr, lr, lc, rc] = getusedrange (xls, ++ws_cnt); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = sprintf ... + ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); else sh_names(ii, 2) = "Empty"; endif elseif (xls.workbook.Sheets(ii).Type == xlChart) sh_names(ii, 2) = sprintf ("Chart"); ++ch_cnt; else - sh_names(ii, 2) = 'Other_type'; ++o_cnt; + sh_names(ii, 2) = "Other_type"; ++o_cnt; endif endfor
--- a/main/io/inst/private/__COM_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__COM_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,30 +20,32 @@ ## Created: 2012-10-07 ## Updates (possibly from xlsopen): ## 2010-11-01 Added <COM>.Application.DisplayAlerts=0 in COM section to avoid Excel pop-ups +## 2012-10-24 Style fixes function [ xls, xlssupport, lastintf ] = __COM_spsh_open__ (xls, xwrite, filename, xlssupport) app = actxserver ("Excel.Application"); - try # Because Excel itself can still crash on file formats etc. + try ## Because Excel itself can still crash on file formats etc. app.Application.DisplayAlerts = 0; if (xwrite < 2) - # Open workbook + ## Open workbook wb = app.Workbooks.Open (canonicalize_file_name (filename)); elseif (xwrite > 2) - # Create a new workbook + ## Create a new workbook wb = app.Workbooks.Add (); - ### Uncommenting the below statement can be useful in multi-user environments. - ### Be sure to uncomment correspondig stanza in xlsclose to avoid zombie Excels - # wb.SaveAs (canonicalize_file_name (filename)) + ## Uncommenting the below statement can be useful in multi-user environments. + ## Be sure to uncomment correspondig stanza in xlsclose to avoid zombie Excels + ## wb.SaveAs (canonicalize_file_name (filename)) endif xls.app = app; - xls.xtype = 'COM'; + xls.xtype = "COM"; xls.workbook = wb; xls.filename = filename; xlssupport += 1; - lastintf = 'COM'; + lastintf = "COM"; catch - warning ( sprintf ("ActiveX error trying to open or create file %s\n", filename)); + warning ( sprintf ("ActiveX error trying to open or create file %s\n",... + filename)); app.Application.DisplayAlerts = 1; app.Quit (); delete (app);
--- a/main/io/inst/private/__JOD_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JOD_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -26,12 +26,13 @@ ## 2012-04-09 Fixed rowrepcnt (str2num not applied to tablerow) ## 2012-04-18 Added getUsedRange() method for JOD 1.3x and above ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ trow, brow, lcol, rcol ] = __JOD_getusedrange__ (ods, wsh) - # This function works by virtue of sheets in JOD actually being a Java string. - # It works outside of the Java memory/heap space which is an added benefit... - # (Read: this is one big dirty hack...... prone to crash Java on BIG spreadsheets) + ## This function works by virtue of sheets in JOD actually being a Java string. + ## It works outside of the Java memory/heap space which is an added benefit... + ## (Read: this is one big dirty hack...... prone to crash Java on BIG spreadsheets) if (isnumeric (wsh)) sh = char (ods.workbook.getSheet (wsh - 1)); @@ -40,40 +41,40 @@ endif try - # Let's see if we have JOD v. 1.3x. If not, next call fails & we'll fall back to the old hack + ## Let's see if we have JOD v. 1.3x. If not, next call fails & we'll fall back to the old hack sh_rng = char (sh.getUsedRange ()); if (isempty (sh_rng)) - # Empty sheet + ## Empty sheet trow = brow = lcol = rcol = 0; else - # Strip sheet name + ## Strip sheet name sh_rng = sh_rng(length (sh.getName) + 2 : end); - # Get rid of period - sh_rng = strrep (sh_rng, '.', ''); + ## Get rid of period + sh_rng = strrep (sh_rng, ".", ""); [~, nr, nc, trow, lcol] = parse_sp_range (sh_rng); brow = trow + nr - 1; rcol = lcol + nc - 1; endif catch - # Fall back to the old hack :-( + ## Fall back to the old hack :-( sh = char (sh); - # 1. Get table-row pointers - id_trow = strfind (sh, '<table:table-row'); - id = strfind (sh, '</table:table>') - 1; + ## 1. Get table-row pointers + id_trow = strfind (sh, "<table:table-row"); + id = strfind (sh, "</table:table>") - 1; id_trow = [id_trow id]; trow = rcol = 0; lcol = 1024; brow = 0; if (~isempty (id)) - # 2. Loop over all table-rows + ## 2. Loop over all table-rows rowrepcnt = 0; for irow = 1:length (id_trow)-1 - # Isolate single table-row + ## Isolate single table-row tablerow = sh(id_trow(irow):id_trow(irow+1)-1); - # Search table-cells. table-c covers both table-cell & table-covered-cell - id_tcell = strfind (tablerow, '<table:table-c'); + ## Search table-cells. table-c covers both table-cell & table-covered-cell + id_tcell = strfind (tablerow, "<table:table-c"); id_tcell = [id_tcell id]; rowl = length (tablerow); if (isempty (id_tcell(1:end-1))) @@ -81,72 +82,77 @@ else rowend = id_tcell(1); endif - # Add in table-number-rows-repeated attribute values - rowrept = strfind (tablerow(1:rowend), 'number-rows-repeated'); + ## Add in table-number-rows-repeated attribute values + rowrept = strfind (tablerow(1:rowend), "number-rows-repeated"); if (~isempty (rowrept)) [st, en] = regexp (tablerow(rowrept:min (rowend, rowrept+30)), '\d+'); rowrepcnt += str2num (tablerow(rowrept+st-1:min (rowend, rowrept+en-1))) - 1; endif - # 3. Search table-cells. table-c is a table-covered-cell that is considered empty - id_tcell = strfind (tablerow, '<table:table-c'); + ## 3. Search table-cells. table-c is a table-covered-cell that is considered empty + id_tcell = strfind (tablerow, "<table:table-c"); if (~isempty (id_tcell)) - # OK, this row has a value cell. Now table-covered-cells must be included. - id_tcell2 = strfind (tablerow, '<table:covered-t'); + ## OK, this row has a value cell. Now table-covered-cells must be included. + id_tcell2 = strfind (tablerow, "<table:covered-t"); if (~isempty (id_tcell2)) id_tcell = sort ([id_tcell id_tcell2]); endif id_tcell = [id_tcell rowl]; - # Search for non-empty cells (i.e., with an office:value-type attribute). But: - # jOpenDocument 1.2b3 has a bug: it often doesn't set this attr for string cells - id_valtcell = strfind (tablerow, 'office:value-type='); - id_textonlycell = strfind (tablerow, '<text:'); + ## Search for non-empty cells (i.e., with an office:value-type attribute). But: + ## jOpenDocument 1.2b3 has a bug: it often doesn't set this attr for string cells + id_valtcell = strfind (tablerow, "office:value-type="); + id_textonlycell = strfind (tablerow, "<text:"); id_valtcell = sort ([id_valtcell id_textonlycell]); id_valtcell = [id_valtcell rowl]; if (~isempty (id_valtcell(1:end-1))) brow = irow + rowrepcnt; - # First set trow if it hadn't already been found + ## First set trow if it hadn't already been found if (~trow) trow = irow; endif - # Search for repeated table-cells - id_reptcell = strfind (tablerow, 'number-columns-repeated'); + ## Search for repeated table-cells + id_reptcell = strfind (tablerow, "number-columns-repeated"); id_reptcell = [id_reptcell rowl]; - # Search for leftmost non-empty table-cell. llcol = counter for this table-row + ## Search for leftmost non-empty table-cell. llcol = counter for this table-row llcol = 1; while (id_tcell (llcol) < id_valtcell(1) && llcol <= length (id_tcell) - 1) ++llcol; endwhile --llcol; - # Compensate for repeated cells. First count all repeats left of llcol + ## Compensate for repeated cells. First count all repeats left of llcol ii = 1; repcnt = 0; if (~isempty (id_reptcell(1:end-1))) - # First try lcol + ## First try lcol while (ii <= length (id_reptcell) - 1 && id_reptcell(ii) < id_valtcell(1)) - # Add all repeat counts left of leftmost data tcell minus 1 for each - [st, en] = regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); - repcnt += str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; + ## Add all repeat counts left of leftmost data tcell minus 1 for each + [st, en] = ... + regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); + repcnt += ... + str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; ++ii; endwhile - # Next, add current repcnt value to llcol and update lcol + ## Next, add current repcnt value to llcol and update lcol lcol = min (lcol, llcol + repcnt); - # Get last value table-cell in table-cell idx + ## Get last value table-cell in table-cell idx jj = 1; while (id_tcell (jj) < id_valtcell(length (id_valtcell)-1)) ++jj; endwhile - # Get rest of column repeat counts in value table-cell range + ## Get rest of column repeat counts in value table-cell range while (ii < length (id_reptcell) && id_reptcell(ii) < id_tcell(jj)) - # Add all repeat counts minus 1 for each tcell in value tcell range - [st, en] = regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); - repcnt += str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; + ## Add all repeat counts minus 1 for each tcell in value tcell range + [st, en] = ... + regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); + repcnt += ... + str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; ++ii; endwhile else - # In case left column = A + ## In case left column = A lcol = min (lcol, llcol); endif - # Count all table-cells in value table-cell-range - ii = 1; # Indexes cannot be negative - while (ii < length (id_tcell) && id_tcell(ii) < id_valtcell(length (id_valtcell) - 1)) + ## Count all table-cells in value table-cell-range + ii = 1; ## Indexes cannot be negative + while (ii < length (id_tcell) ... + && id_tcell(ii) < id_valtcell(length (id_valtcell) - 1)) ++ii; endwhile --ii; @@ -155,7 +161,7 @@ endif endfor else - # No data found, empty sheet + ## No data found, empty sheet lcol = rcol = brow = trow = 0; endif
--- a/main/io/inst/private/__JOD_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JOD_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -39,50 +39,53 @@ ## 2010-11-12 Improved file change tracking tru ods.changed ## 2012-02-26 Write logicals as doubles (bug in jOpenDocument, would write as text) ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ ods, rstatus ] = __JOD_oct2spsh__ (c_arr, ods, wsh, crange) rstatus = 0; sh = []; changed = 0; - # Get worksheet. Use first one if none given + ## Get worksheet. Use first one if none given if (isempty (wsh)) wsh = 1; endif sh_cnt = ods.workbook.getSheetCount (); if (isnumeric (wsh)) if (wsh > 1024) error ("Sheet number out of range of ODS specification (>1024)"); elseif (wsh > sh_cnt) - error ("Sheet number (%d) larger than number of sheets in file (%d)\n", wsh, sh_cnt); + error ("Sheet number (%d) larger than number of sheets in file (%d)\n",... + wsh, sh_cnt); else wsh = wsh - 1; sh = ods.workbook.getSheet (wsh); if (isempty (sh)) - # Sheet number wsh didn't exist yet + ## Sheet number wsh didn't exist yet wsh = sprintf ("Sheet%d", wsh+1); elseif (ods.changed > 2) - sh.setName ('Sheet1'); + sh.setName ("Sheet1"); changed = 1; endif endif endif - # wsh is now either a 0-based sheet no. or a string. In latter case: + ## wsh is now either a 0-based sheet no. or a string. In latter case: if (isempty (sh) && ischar (wsh)) sh = ods.workbook.getSheet (wsh); if (isempty (sh)) - # Still doesn't exist. Create sheet + ## Still doesn't exist. Create sheet if (ods.odfvsn == 3) if (ods.changed > 2) - # 1st "new" -unnamed- sheet has already been made when creating the spreadsheet + ## 1st "new" -unnamed- sheet has already been made when creating the spreadsheet sh = ods.workbook.getSheet (0); sh.setName (wsh); changed = 1; else - # For existing spreadsheets - # printf ("Adding sheet '%s'\n", wsh); + ## For existing spreadsheets + ## printf ("Adding sheet '%s'\n", wsh); sh = ods.workbook.addSheet (sh_cnt, wsh); changed = 1; endif else - error ("jOpenDocument v. 1.2b2 does not support adding sheets - upgrade to v. 1.2b3\n"); + error (["jOpenDocument v. 1.2b2 does not support adding sheets" ... + " - upgrade to v. 1.2b3\n"]); endif endif endif @@ -93,59 +96,59 @@ lcol = 0; nrows = nr; ncols = nc; - elseif (isempty (strfind (deblank (crange), ':'))) + elseif (isempty (strfind (deblank (crange), ":"))) [dummy1, dummy2, dummy3, trow, lcol] = parse_sp_range (crange); nrows = nr; ncols = nc; - # Row/col = 0 based in jOpenDocument + ## Row/col = 0 based in jOpenDocument trow = trow - 1; lcol = lcol - 1; else [dummy, nrows, ncols, trow, lcol] = parse_sp_range (crange); - # Row/col = 0 based in jOpenDocument + ## Row/col = 0 based in jOpenDocument trow = trow - 1; lcol = lcol - 1; endif if (trow > 65535 || lcol > 1023) error ("Topleft cell beyond spreadsheet limits (AMJ65536)."); endif - # Check spreadsheet capacity beyond requested topleft cell - nrows = min (nrows, 65536 - trow); # Remember, lcol & trow are zero-based + ## Check spreadsheet capacity beyond requested topleft cell + nrows = min (nrows, 65536 - trow); ## Remember, lcol & trow are zero-based ncols = min (ncols, 1024 - lcol); - # Check array size and requested range + ## Check array size and requested range nrows = min (nrows, nr); ncols = min (ncols, nc); if (nrows < nr || ncols < nc) warning ("Array truncated to fit in range"); endif if (isnumeric (c_arr)) c_arr = num2cell (c_arr); endif - # Ensure sheet capacity is large enough to contain new data - try # try-catch needed to work around bug in jOpenDocument v 1.2b3 and earlier + ## Ensure sheet capacity is large enough to contain new data + try ## try-catch needed to work around bug in jOpenDocument v 1.2b3 and earlier sh.ensureColumnCount (lcol + ncols); # Remember, lcol & trow are zero-based - catch # catch is needed for new empty sheets (first ensureColCnt() hits null ptr) + catch ## catch is needed for new empty sheets (first ensureColCnt() hits null ptr) sh.ensureColumnCount (lcol + ncols); - # Kludge needed because upper row is defective (NPE jOpenDocument bug). ?Fixed in 1.2b4? + ## Kludge needed because upper row is defective (NPE jOpenDocument bug). ?Fixed in 1.2b4? if (trow == 0) - # Shift rows one down to avoid defective upper row + ## Shift rows one down to avoid defective upper row ++trow; printf ("Info: empy upper row above data added to avoid JOD bug.\n"); endif end_try_catch sh.ensureRowCount (trow + nrows); - # Write data to worksheet + ## Write data to worksheet for ii = 1 : nrows for jj = 1 : ncols val = c_arr {ii, jj}; if ((isnumeric (val) && ~isnan (val)) || ischar (val) || islogical (val)) - # FIXME: jOpenDocument doesn't really support writing booleans (doesn't set OffValAttr) + ## FIXME: jOpenDocument doesn't really support writing booleans (doesn't set OffValAttr) if (islogical (val)); val = double (val); endif try sh.getCellAt (jj + lcol - 1, ii + trow - 1).clearValue(); jcell = sh.getCellAt (jj + lcol - 1, ii + trow - 1).setValue (val); changed = 1; catch - # No panic, probably a merged cell - # printf (sprintf ("Cell skipped at (%d, %d)\n", ii+lcol-1, jj+trow-1)); + ## No panic, probably a merged cell + ## printf (sprintf ("Cell skipped at (%d, %d)\n", ii+lcol-1, jj+trow-1)); end_try_catch endif endfor
--- a/main/io/inst/private/__JOD_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JOD_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -32,71 +32,72 @@ ## the cntents could be BOOLEAN as well (JOD doesn't write OffVal attr either) ## 2012-02-26 Further workaround for reading strings (actually: cells w/o OfficeValueAttr) ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ rawarr, ods] = __JOD_spsh2oct__ (ods, wsh, crange) persistent months; months = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; - # Check jOpenDocument version + ## Check jOpenDocument version sh = ods.workbook.getSheet (0); cl = sh.getCellAt (0, 0); if (ods.odfvsn == 3) - # 1.2b3+ has public getValueType () + ## 1.2b3+ has public getValueType () persistent ctype; if (isempty (ctype)) - BOOLEAN = char (java_get ('org.jopendocument.dom.ODValueType', 'BOOLEAN')); - CURRENCY = char (java_get ('org.jopendocument.dom.ODValueType', 'CURRENCY')); - DATE = char (java_get ('org.jopendocument.dom.ODValueType', 'DATE')); - FLOAT = char (java_get ('org.jopendocument.dom.ODValueType', 'FLOAT')); - PERCENTAGE = char (java_get ('org.jopendocument.dom.ODValueType', 'PERCENTAGE')); - STRING = char (java_get ('org.jopendocument.dom.ODValueType', 'STRING')); - TIME = char (java_get ('org.jopendocument.dom.ODValueType', 'TIME')); + BOOLEAN = char (java_get ("org.jopendocument.dom.ODValueType", "BOOLEAN")); + CURRENCY = char (java_get ("org.jopendocument.dom.ODValueType", "CURRENCY")); + DATE = char (java_get ("org.jopendocument.dom.ODValueType", "DATE")); + FLOAT = char (java_get ("org.jopendocument.dom.ODValueType", "FLOAT")); + PERCENTAGE = char (java_get ("org.jopendocument.dom.ODValueType", "PERCENTAGE")); + STRING = char (java_get ("org.jopendocument.dom.ODValueType", "STRING")); + TIME = char (java_get ("org.jopendocument.dom.ODValueType", "TIME")); endif -# else -# # 1.2b2 has not -# ver = 2; +## else +## ## 1.2b2 has not +## ver = 2; endif - if (isnumeric (wsh)) wsh = wsh - 1; endif # Sheet INDEX starts at 0 - # Check if sheet exists. If wsh = numeric, nonexistent sheets throw errors. + if (isnumeric (wsh)); wsh = wsh - 1; endif ## Sheet INDEX starts at 0 + ## Check if sheet exists. If wsh = numeric, nonexistent sheets throw errors. try - sh = ods.workbook.getSheet (wsh); + sh = ods.workbook.getSheet (wsh); catch error ("Illegal sheet number (%d) requested for file %s\n", wsh+1, ods.filename); end_try_catch - # If wsh = string, nonexistent sheets yield empty results + ## If wsh = string, nonexistent sheets yield empty results if (isempty (sh)) error ("No sheet called '%s' present in file %s\n", wsh, ods.filename); endif - # Either parse (given cell range) or prepare (unknown range) help variables + ## Either parse (given cell range) or prepare (unknown range) help variables if (isempty (crange)) if (ods.odfvsn < 3) error ("No empty read range allowed in jOpenDocument version 1.2b2") else - if (isnumeric (wsh)) wsh = wsh + 1; endif + if (isnumeric (wsh)); wsh = wsh + 1; endif [ trow, brow, lcol, rcol ] = getusedrange (ods, wsh); - nrows = brow - trow + 1; # Number of rows to be read - ncols = rcol - lcol + 1; # Number of columns to be read + nrows = brow - trow + 1; ## Number of rows to be read + ncols = rcol - lcol + 1; ## Number of columns to be read endif else [dummy, nrows, ncols, trow, lcol] = parse_sp_range (crange); - # Check ODS column limits + ## Check ODS column limits if (lcol > 1024 || trow > 65536) error ("ods2oct: invalid range; max 1024 columns & 65536 rows."); endif - # Truncate range silently if needed + ## Truncate range silently if needed rcol = min (lcol + ncols - 1, 1024); ncols = min (ncols, 1024 - lcol + 1); nrows = min (nrows, 65536 - trow + 1); brow= trow + nrows - 1; endif - # Create storage for data content + ## Create storage for data content rawarr = cell (nrows, ncols); if (ods.odfvsn >= 3) - # Version 1.2b3+ + ## Version 1.2b3+ for ii=1:nrows for jj = 1:ncols try @@ -110,7 +111,7 @@ case STRING rawarr{ii, jj} = scell.getValue(); case DATE - tmp = strsplit (char (scell.getValue ()), ' '); + tmp = strsplit (char (scell.getValue ()), " "); yy = str2num (tmp{6}); mo = find (ismember (months, toupper (tmp{2})) == 1); dd = str2num (tmp{3}); @@ -119,44 +120,46 @@ ss = str2num (tmp{4}(7:8)); rawarr{ii, jj} = datenum (yy, mo, dd, hh, mi, ss); case TIME - tmp = strsplit (char (scell.getValue ().getTime ()), ' '); + tmp = strsplit (char (scell.getValue ().getTime ()), " "); hh = str2num (tmp{4}(1:2)) / 24.0; mi = str2num (tmp{4}(4:5)) / 1440.0; ss = str2num (tmp{4}(7:8)) / 86600.0; rawarr {ii, jj} = hh + mi + ss; otherwise - # Workaround for sheets written by jOpenDocument (no value-type attrb): + ## Workaround for sheets written by jOpenDocument (no value-type attrb): if (~isempty (scell.getValue) ) - # FIXME Assume cell contains string if there's a text attr. But it could be BOOLEAN too... - if (findstr ('<text:', char (scell))), sctype = STRING; endif + ## FIXME Assume cell contains string if there's a text attr. + ## But it could be BOOLEAN too... + if (findstr ("<text:", char (scell))), sctype = STRING; endif rawarr{ii, jj} = scell.getValue(); endif - # Nothing + ## Nothing endswitch catch - # Probably a merged cell, just skip - # printf ("Error in row %d, col %d (addr. %s)\n", ii, jj, calccelladdress (lcol+jj-2, trow+ii-2)); + ## Probably a merged cell, just skip + ## printf ("Error in row %d, col %d (addr. %s)\n", + ## ii, jj, calccelladdress (lcol+jj-2, trow+ii-2)); end_try_catch endfor endfor - else # ods.odfvsn == 3 - # 1.2b2 + else ## ods.odfvsn == 3 + ## 1.2b2 for ii=1:nrows for jj = 1:ncols celladdress = calccelladdress (trow+ii-1, lcol+jj-1); try val = sh.getCellAt (celladdress).getValue (); catch - # No panic, probably a merged cell + ## No panic, probably a merged cell val = {}; end_try_catch if (~isempty (val)) if (ischar (val)) - # Text string + ## Text string rawarr(ii, jj) = val; elseif (isnumeric (val)) - # Boolean - if (val) rawarr(ii, jj) = true; else; rawarr(ii, jj) = false; endif + ## Boolean + if (val) rawarr(ii, jj) = true; else; rawarr(ii, jj) = false; endif else try val = sh.getCellAt (celladdress).getValue ().doubleValue (); @@ -164,9 +167,9 @@ catch val = char (val); if (isempty (val)) - # Probably empty Cell + ## Probably empty Cell else - # Maybe date / time value. Dirty hack to get values: + ## Maybe date / time value. Dirty hack to get values: mo = strmatch (toupper (val(5:7)), months); dd = str2num (val(9:10)); yy = str2num (val(25:end)); @@ -183,7 +186,7 @@ endif - # Keep track of data rectangle limits + ## Keep track of data rectangle limits ods.limits = [lcol, rcol; trow, brow]; endfunction
--- a/main/io/inst/private/__JOD_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JOD_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,15 +18,17 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-23 Style fixes function [ ods ] = __JOD_spsh_close__ (ods) try if (ods.changed && ods.changed < 3) if (isfield (ods, "nfilename")) - ofile = java_new ('java.io.File', ods.nfilename); + ofile = java_new ("java.io.File", ods.nfilename); else - ofile = java_new ('java.io.File', ods.filename); + ofile = java_new ("java.io.File", ods.filename); endif ods.workbook.saveAs (ofile); ods.changed = 0;
--- a/main/io/inst/private/__JOD_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JOD_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,6 +20,8 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## Updates: +## 2012-10-24 Style fixes function [sh_names] = __JOD_spsh_info__ (ods) @@ -29,7 +31,8 @@ sh_names(ii) = ods.workbook.getSheet (ii-1).getName (); [ tr, lr, lc, rc ] = getusedrange (ods, ii); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc),... + calccelladdress (lr, rc)); else sh_names(ii, 2) = "Empty"; endif
--- a/main/io/inst/private/__JOD_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JOD_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2012 Philip +## Copyright (C) 2012 Philip Nienhuis <prnienhuis@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 @@ -16,27 +16,29 @@ ## __JOD_spsh_open -## Author: Philip <Philip@DESKPRN> +## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-24 Style fixes function [ ods, odssupport, lastintf ] = __JOD_spsh_open__ (ods, rw, filename, odssupport) - file = java_new ('java.io.File', filename); - jopendoc = 'org.jopendocument.dom.spreadsheet.SpreadSheet'; + file = java_new ("java.io.File", filename); + jopendoc = "org.jopendocument.dom.spreadsheet.SpreadSheet"; try if (rw > 2) - # Create an empty 2 x 2 default TableModel template - tmodel= java_new ('javax.swing.table.DefaultTableModel', 2, 2); - wb = java_invoke (jopendoc, 'createEmpty', tmodel); + ## Create an empty 2 x 2 default TableModel template + tmodel= java_new ("javax.swing.table.DefaultTableModel", 2, 2); + wb = java_invoke (jopendoc, "createEmpty", tmodel); else - wb = java_invoke (jopendoc, 'createFromFile', file); + wb = java_invoke (jopendoc, "createFromFile", file); endif ods.workbook = wb; ods.filename = filename; - ods.xtype = 'JOD'; - ods.app = 'file'; - # Check jOpenDocument version. This can only work here when a - # workbook has been opened + ods.xtype = "JOD"; + ods.app = "file"; + ## Check jOpenDocument version. This can only work here when a + ## workbook has been opened sh = ods.workbook.getSheet (0); cl = sh.getCellAt (0, 0); try @@ -49,9 +51,9 @@ printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2\n"); end_try_catch odssupport += 2; - lastintf = 'JOD'; + lastintf = "JOD"; catch - error ('Couldn''t open file %s using JOD', filename); + error ("Couldn't open file %s using JOD", filename); end_try_catch endfunction
--- a/main/io/inst/private/__JXL_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JXL_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,27 +18,31 @@ ## Author: Philip <Philip@DESKPRN> ## Created: 2010-03-20 +## Updates: ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ trow, brow, lcol, rcol ] = __JXL_getusedrange__ (xls, wsh) - persistent emptycell = (java_get ('jxl.CellType', 'EMPTY')).toString (); + persistent emptycell = (java_get ("jxl.CellType", "EMPTY")).toString (); - sh = xls.workbook.getSheet (wsh - 1); # JXL sheet count 0-based + sh = xls.workbook.getSheet (wsh - 1); ## JXL sheet count 0-based brow = sh.getRows (); rcol = sh.getColumns (); if (brow == 0 || rcol == 0) - # Empty sheet + ## Empty sheet trow = 0; lcol = 0; brow = 0; rcol = 0; else trow = brow + 1; lcol = rcol + 1; - for ii=0:brow-1 # For loop coz we must check ALL rows for leftmost column + ## For loop coz we must check ALL rows for leftmost column + for ii=0:brow-1 emptyrow = 1; jj = 0; - while (jj < rcol && emptyrow) # While loop => only til first non-empty cell + ## While loop => only til first non-empty cell + while (jj < rcol && emptyrow) cell = sh.getCell (jj, ii); if ~(strcmp (char (cell.getType ()), emptycell)) lcol = min (lcol, jj + 1); @@ -46,7 +50,7 @@ endif ++jj; endwhile - if ~(emptyrow) trow = min (trow, ii + 1); endif + if ~(emptyrow); trow = min (trow, ii + 1); endif endfor endif
--- a/main/io/inst/private/__JXL_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JXL_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -60,115 +60,119 @@ ## 2012-05-21 "Double" cast added when writing numeric values ## 2012-05-21 "Double" cast moved into main func oct2xls ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ xls, rstatus ] = __JXL_oct2spsh__ (obj, xls, wsh, crange, spsh_opts) - # Preliminary sanity checks - if (~strmatch (tolower (xls.filename(end-4:end-1)), '.xls')) # No OOXML in JXL + ## Preliminary sanity checks + if (~strmatch (tolower (xls.filename(end-4:end-1)), ".xls")) ## No OOXML in JXL error ("JXL interface can only write to Excel .xls files") endif persistent ctype; if (isempty (ctype)) ctype = [1, 2, 3, 4, 5]; - # Number, Boolean, String, Formula, Empty + ## Number, Boolean, String, Formula, Empty endif - # scratch vars + ## scratch vars rstatus = 0; f_errs = 0; - # Prepare workbook pointer if needed - if (xls.changed == 0) # Only for 1st call of octxls after xlsopen - # Create writable copy of workbook. If >2 a writable wb was made in xlsopen - xlsout = java_new ('java.io.File', xls.filename); - wb = java_invoke ('jxl.Workbook', 'createWorkbook', xlsout, xls.workbook); - # Catch JExcelAPI bug/"feature": when switching to write mode, the file on disk - # is affected and the memory file MUST be written to disk to save earlier data + ## Prepare workbook pointer if needed + if (xls.changed == 0) ## Only for 1st call of octxls after xlsopen + ## Create writable copy of workbook. If >2 a writable wb was made in xlsopen + xlsout = java_new ("java.io.File", xls.filename); + wb = java_invoke ("jxl.Workbook", "createWorkbook", xlsout, xls.workbook); + ## Catch JExcelAPI bug/"feature": when switching to write mode, the file on disk + ## is affected and the memory file MUST be written to disk to save earlier data xls.changed = 1; xls.workbook = wb; else wb = xls.workbook; endif - # Check if requested worksheet exists in the file & if so, get pointer - nr_of_sheets = xls.workbook.getNumberOfSheets (); # 1 based !! + ## Check if requested worksheet exists in the file & if so, get pointer + nr_of_sheets = xls.workbook.getNumberOfSheets (); ## 1 based !! if (isnumeric (wsh)) if (wsh > nr_of_sheets) - # Watch out as a sheet called Sheet%d can exist with a lower index... + ## Watch out as a sheet called Sheet%d can exist with a lower index... strng = sprintf ("Sheet%d", wsh); ii = 1; while (~isempty (wb.getSheet (strng)) && (ii < 5)) - strng = ['_' strng]; + strng = ["_" strng]; ++ii; endwhile - if (ii >= 5) error (sprintf( " > 5 sheets named [_]Sheet%d already present!", wsh)); endif + if (ii >= 5) + error (sprintf( " > 5 sheets named [_]Sheet%d already present!", wsh)); + endif sh = wb.createSheet (strng, nr_of_sheets); ++nr_of_sheets; - xls.changed = min (xls.changed, 2); # Keep a 2 in case of new file + xls.changed = min (xls.changed, 2); ## Keep a 2 in case of new file else - sh = wb.getSheet (wsh - 1); # JXL sheet count 0-based + sh = wb.getSheet (wsh - 1); ## JXL sheet count 0-based endif shnames = char (wb.getSheetNames ()); printf ("(Writing to worksheet %s)\n", shnames {nr_of_sheets, 1}); else sh = wb.getSheet (wsh); if (isempty(sh)) - # Sheet not found, just create it + ## Sheet not found, just create it sh = wb.createSheet (wsh, nr_of_sheets); ++nr_of_sheets; - xls.changed = min (xls.changed, 2); # Keep a 2 for new file + xls.changed = min (xls.changed, 2); ## Keep a 2 for new file endif endif - # Parse date ranges + ## Parse date ranges [nr, nc] = size (obj); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); if (nrows < nr || ncols < nc) warning ("Array truncated to fit in range"); obj = obj(1:nrows, 1:ncols); endif - # Prepare type array + ## Prepare type array typearr = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts); if ~(spsh_opts.formulas_as_text) - # Remove leading '=' from formula strings + ## Remove leading '=' from formula strings fptr = ~(4 * (ones (size (typearr))) .- typearr); obj(fptr) = cellfun (@(x) x(2:end), obj(fptr), "Uniformoutput", false); endif clear fptr - # Write date to worksheet + ## Write date to worksheet for ii=1:nrows - ll = ii + trow - 2; # Java JExcelAPI's row count = 0-based + ll = ii + trow - 2; ## Java JExcelAPI's row count = 0-based for jj=1:ncols - kk = jj + lcol - 2; # JExcelAPI's column count is also 0-based + kk = jj + lcol - 2; ## JExcelAPI's column count is also 0-based switch typearr(ii, jj) - case 1 # Numerical - tmp = java_new ('jxl.write.Number', kk, ll, obj{ii, jj}); + case 1 ## Numerical + tmp = java_new ("jxl.write.Number", kk, ll, obj{ii, jj}); sh.addCell (tmp); - case 2 # Boolean - tmp = java_new ('jxl.write.Boolean', kk, ll, obj{ii, jj}); + case 2 ## Boolean + tmp = java_new ("jxl.write.Boolean", kk, ll, obj{ii, jj}); sh.addCell (tmp); - case 3 # String - tmp = java_new ('jxl.write.Label', kk, ll, obj{ii, jj}); + case 3 ## String + tmp = java_new ("jxl.write.Label", kk, ll, obj{ii, jj}); sh.addCell (tmp); - case 4 # Formula - # First make sure formula functions are all uppercase + case 4 ## Formula + ## 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 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 + ## There's no guarantee for formula correctness, so.... + 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 sh.addCell (tmp); catch ++f_errs; - # Formula error. Enter formula as text string instead - tmp = java_new ('jxl.write.Label', kk, ll, obj{ii, jj}); + ## Formula error. Enter formula as text string instead + tmp = java_new ("jxl.write.Label", kk, ll, obj{ii, jj}); sh.addCell (tmp); end_try_catch - case 5 # Empty or NaN - tmp = java_new ('jxl.write.Blank', kk, ll); + case 5 ## Empty or NaN + tmp = java_new ("jxl.write.Blank", kk, ll); sh.addCell (tmp); otherwise - # Just skip + ## Just skip endswitch endfor endfor @@ -176,7 +180,7 @@ if (f_errs) printf ("%d formula errors encountered - please check input array\n", f_errs); endif - xls.changed = max (xls.changed, 1); # Preserve 2 for new files + xls.changed = max (xls.changed, 1); ## Preserve 2 for new files rstatus = 1; endfunction
--- a/main/io/inst/private/__JXL_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JXL_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -27,8 +27,8 @@ ## Examples: ## ## @example -## [Arr, status, xls] = __JXL_spsh2oct__ (xls, 'Second_sheet', 'B3:AY41'); -## B = __JXL_spsh2oct__ (xls, 'Second_sheet'); +## [Arr, status, xls] = __JXL_spsh2oct__ (xls, "Second_sheet", "B3:AY41"); +## B = __JXL_spsh2oct__ (xls, "Second_sheet"); ## @end example ## ## @seealso {xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite, oct2jxla2xls} @@ -50,44 +50,50 @@ ## '' order in strsplit, wrong isTime condition ## 2012-01-26 Fixed "seealso" help string ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ rawarr, xls, rstatus ] = __JXL_spsh2oct__ (xls, wsh, cellrange, spsh_opts) persistent ctype; persistent months; if (isempty (ctype)) ctype = cell (11, 1); - # Get enumerated cell types. Beware as they start at 0 not 1 - ctype( 1) = (java_get ('jxl.CellType', 'BOOLEAN')).toString (); - ctype( 2) = (java_get ('jxl.CellType', 'BOOLEAN_FORMULA')).toString (); - ctype( 3) = (java_get ('jxl.CellType', 'DATE')).toString (); - ctype( 4) = (java_get ('jxl.CellType', 'DATE_FORMULA')).toString (); - ctype( 5) = (java_get ('jxl.CellType', 'EMPTY')).toString (); - ctype( 6) = (java_get ('jxl.CellType', 'ERROR')).toString (); - ctype( 7) = (java_get ('jxl.CellType', 'FORMULA_ERROR')).toString (); - ctype( 8) = (java_get ('jxl.CellType', 'NUMBER')).toString (); - ctype( 9) = (java_get ('jxl.CellType', 'LABEL')).toString (); - ctype(10) = (java_get ('jxl.CellType', 'NUMBER_FORMULA')).toString (); - ctype(11) = (java_get ('jxl.CellType', 'STRING_FORMULA')).toString (); - months = {'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'}; + ## Get enumerated cell types. Beware as they start at 0 not 1 + ctype( 1) = (java_get ("jxl.CellType", "BOOLEAN")).toString (); + ctype( 2) = (java_get ("jxl.CellType", "BOOLEAN_FORMULA")).toString (); + ctype( 3) = (java_get ("jxl.CellType", "DATE")).toString (); + ctype( 4) = (java_get ("jxl.CellType", "DATE_FORMULA")).toString (); + ctype( 5) = (java_get ("jxl.CellType", "EMPTY")).toString (); + ctype( 6) = (java_get ("jxl.CellType", "ERROR")).toString (); + ctype( 7) = (java_get ("jxl.CellType", "FORMULA_ERROR")).toString (); + ctype( 8) = (java_get ("jxl.CellType", "NUMBER")).toString (); + ctype( 9) = (java_get ("jxl.CellType", "LABEL")).toString (); + ctype(10) = (java_get ("jxl.CellType", "NUMBER_FORMULA")).toString (); + ctype(11) = (java_get ("jxl.CellType", "STRING_FORMULA")).toString (); + months = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; endif rstatus = 0; wb = xls.workbook; - # Check if requested worksheet exists in the file & if so, get pointer + ## Check if requested worksheet exists in the file & if so, get pointer nr_of_sheets = wb.getNumberOfSheets (); 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); # JXL sheet count 0-based - # printf ("(Reading from worksheet %s)\n", shnames {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); ## JXL sheet count 0-based + ## printf ("(Reading from worksheet %s)\n", shnames {wsh}); else sh = wb.getSheet (wsh); - if (isempty (sh)), error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); endif + if (isempty (sh)) + error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); + endif end if (isempty (cellrange)) - # Get numeric sheet pointer (1-based) + ## Get numeric sheet pointer (1-based) ii = 1; while (ii <= nr_of_sheets) if (strcmp (wsh, shnames{ii}) == 1) @@ -97,10 +103,10 @@ ++ii; endif endwhile - # Get data rectangle row & column numbers (1-based) + ## Get data rectangle row & column numbers (1-based) [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh); if (firstrow == 0 && lastrow == 0) - # Empty sheet + ## Empty sheet rawarr = {}; printf ("Worksheet '%s' contains no data\n", shnames {wsh}); rstatus = 1; @@ -110,37 +116,37 @@ ncols = rcol - lcol + 1; endif else - # Translate range to row & column numbers (1-based) + ## Translate range to row & column numbers (1-based) [dummy, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); - # Check for too large requested range against actually present range + ## Check for too large requested range against actually present range lastrow = min (firstrow + nrows - 1, sh.getRows ()); nrows = min (nrows, sh.getRows () - firstrow + 1); ncols = min (ncols, sh.getColumns () - lcol + 1); rcol = lcol + ncols - 1; endif - # Read contents into rawarr - rawarr = cell (nrows, ncols); # create placeholder + ## Read contents into rawarr + rawarr = cell (nrows, ncols); ## create placeholder for jj = lcol : rcol for ii = firstrow:lastrow scell = sh.getCell (jj-1, ii-1); switch char (scell.getType ()) - case ctype {1} # Boolean + case ctype {1} ## Boolean rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - case ctype {2} # Boolean formula + case ctype {2} ## Boolean formula if (spsh_opts.formulas_as_text) tmp = scell.getFormula (); rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; else rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); endif - case ctype {3} # Date + case ctype {3} ## Date try % Older JXL.JAR, returns float rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); catch % Newer JXL.JAR, returns date string w. epoch = 1-1-1900 :-( - tmp = strsplit (char (scell.getDate ()), ' '); + tmp = strsplit (char (scell.getDate ()), " "); yy = str2num (tmp{6}); mo = find (ismember (months, upper (tmp{2})) == 1); dd = str2num (tmp{3}); @@ -152,7 +158,7 @@ endif rawarr {ii+1-firstrow, jj+1-lcol} = datenum (yy, mo, dd, hh, mi, ss); end_try_catch - case ctype {4} # Date formula + case ctype {4} ## Date formula if (spsh_opts.formulas_as_text) tmp = scell.getFormula (); rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; @@ -171,7 +177,7 @@ unwind_protect_cleanup if (isempty (rawarr {ii+1-firstrow, jj+1-lcol})) % Newer JXL.JAR, returns date string w. epoch = 1-1-1900 :-( - tmp = strsplit (char (scell.getDate ()), ' '); + tmp = strsplit (char (scell.getDate ()), " "); yy = str2num (tmp{6}); mo = find (ismember (months, upper (tmp{2})) == 1); dd = str2num (tmp{3}); @@ -186,19 +192,19 @@ end_unwind_protect endif case { ctype {5}, ctype {6}, ctype {7} } - # Empty, Error or Formula error. Nothing to do here - case ctype {8} # Number + ## Empty, Error or Formula error. Nothing to do here + case ctype {8} ## Number rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - case ctype {9} # String + case ctype {9} ## String rawarr {ii+1-firstrow, jj+1-lcol} = scell.getString (); - case ctype {10} # Numerical formula + case ctype {10} ## Numerical formula if (spsh_opts.formulas_as_text) tmp = scell.getFormula (); rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; else rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); endif - case ctype {11} # String formula + case ctype {11} ## String formula if (spsh_opts.formulas_as_text) tmp = scell.getFormula (); rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; @@ -206,7 +212,7 @@ rawarr {ii+1-firstrow, jj+1-lcol} = scell.getString (); endif otherwise - # Do nothing + ## Do nothing endswitch endfor endfor
--- a/main/io/inst/private/__JXL_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JXL_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,17 +18,19 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-24 Style fixes function [ xls ] = __JXL_spsh_close__ (xls) if (xls.changed > 0 && xls.changed < 3) try -# if (xls.changed == 2) printf ("Saving file %s...\n", xls.filename); endif +## if (xls.changed == 2); printf ("Saving file %s...\n", xls.filename); endif xls.workbook.write (); xls.workbook.close (); if (xls.changed == 3) - # Upon entering write mode, JExcelAPI always makes a disk file - # Incomplete new files (no data added) had better be deleted. + ## Upon entering write mode, JExcelAPI always resets disk file. + ## Incomplete new files (no data added) had better be deleted. xls.workbook.close (); delete (xls.filename); endif
--- a/main/io/inst/private/__JXL_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JXL_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,6 +20,7 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## 2012-10-24 Style fixes function [sh_names, fformat] = __JXL_spsh_info__ (xls) @@ -29,11 +30,12 @@ for ii=1:sh_cnt [tr, lr, lc, rc] = getusedrange (xls, ii); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = ... + sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); else sh_names(ii, 2) = "Empty"; endif endfor - if (sh_cnt > 0) fformat = "xlWorkbookNormal"; else, fformat = ''; endif + if (sh_cnt > 0); fformat = "xlWorkbookNormal"; else, fformat = ''; endif endfunction
--- a/main/io/inst/private/__JXL_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__JXL_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,6 +20,7 @@ ## Created: 2012-10-07 ## Updates (possibly from xlsopen): ## 2010-11-05 Bug fix: JXL fallback from POI for BIFF5 is only useful for reading +## 2012-10-24 Style fixes function [ xls, xlssupport, lastintf ] = __JXL_spsh_open__ (xls, xwrite, filename, xlssupport, chk1) @@ -27,24 +28,25 @@ error ("JXL can only read reliably from .xls files") endif try - xlsin = java_new ('java.io.File', filename); + xlsin = java_new ("java.io.File", filename); if (xwrite > 2) - # Get handle to new xls-file - wb = java_invoke ('jxl.Workbook', 'createWorkbook', xlsin); + ## Get handle to new xls-file + wb = java_invoke ("jxl.Workbook", "createWorkbook", xlsin); else - # Open existing file - wb = java_invoke ('jxl.Workbook', 'getWorkbook', xlsin); + ## Open existing file + wb = java_invoke ("jxl.Workbook", "getWorkbook", xlsin); endif - xls.xtype = 'JXL'; + xls.xtype = "JXL"; xls.app = xlsin; xls.workbook = wb; xls.filename = filename; xlssupport += 4; - lastintf = 'JXL'; + lastintf = "JXL"; catch clear xlsin; if (xlsinterfaces.POI) - printf ('... No luck with JXL either, unsupported file format.\n', filename); + ## Fall back to UNO only when that is stable (= closing soffice) + printf ("... No luck with JXL either, unsupported file format.\n", filename); endif end_try_catch
--- a/main/io/inst/private/__OTK_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -29,40 +29,42 @@ ## 2011-09-12 Support for odfdom-0.8.7 added (API change for XPATH) ## 2012-06-08 Support for odsfdom-0.8.8-incubator ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ trow, lrow, lcol, rcol ] = __OTK_getusedrange__ (ods, ii) - odfcont = ods.workbook; # Local copy just in case + odfcont = ods.workbook; ## Local copy just in case - if (isfield (ods, 'odfvsn')) - if (strcmp (ods.odfvsn, '0.8.6') || strcmp (ods.odfvsn, '0.7.5')) + if (isfield (ods, "odfvsn")) + if (strcmp (ods.odfvsn, "0.8.6") || strcmp (ods.odfvsn, "0.7.5")) xpath = ods.app.getXPath; else - # API changed in odfdom-0.8.7 + ## API changed in odfdom-0.8.7 xpath = ods.workbook.getXPath; endif else error ("ODS file ptr struct for OTK interface seems broken."); endif - # Create an instance of type NODESET for use in subsequent statement - NODESET = java_get ('javax.xml.xpath.XPathConstants', 'NODESET'); - # Get table-rows in sheet no. wsh. Sheet count = 1-based (!) + ## Create an instance of type NODESET for use in subsequent statement + NODESET = java_get ("javax.xml.xpath.XPathConstants", "NODESET"); + ## Get table-rows in sheet no. wsh. Sheet count = 1-based (!) str = sprintf ("//table:table[%d]/table:table-row", ii); sh = xpath.evaluate (str, odfcont, NODESET); nr_of_trows = sh.getLength(); - jj = 0; # Table row counter - trow = 0; drows = 0; # Top data row, actual data row range - nrows = 0; reprows = 0; # Scratch counter - rcol = 0; lcol = 1024; # Rightmost and leftmost data column + jj = 0; ## Table row counter + trow = 0; drows = 0; ## Top data row, actual data row range + nrows = 0; reprows = 0; ## Scratch counter + rcol = 0; lcol = 1024; ## Rightmost and leftmost data column + while jj < nr_of_trows row = sh.item(jj); - # Check for data rows + ## Check for data rows rw_char = char (row) (1:min(500, length (char (row)))); - if (findstr ('office:value-type', rw_char) || findstr ('<text:', rw_char)) + if (findstr ("office:value-type", rw_char) || findstr ("<text:", rw_char)) ++drows; - # Check for uppermost data row + ## Check for uppermost data row if (~trow) trow = nrows + 1; nrows = 0; @@ -71,34 +73,36 @@ reprows = 0; endif - # Get leftmost cell column number + ## Get leftmost cell column number lcell = row.getFirstChild (); cl_char = char (lcell); - # 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))) + ## 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))) lcol = min (lcol, lcell.getTableNumberColumnsRepeatedAttribute () + 1); else lcol = 1; endif - # if rcol is already 1024 no more exploring for rightmost column is needed + ## if rcol is already 1024 no more exploring for rightmost column is needed if ~(rcol == 1024) - # Get rightmost cell column number by counting.... + ## Get rightmost cell column number by counting.... rc = 0; for kk=1:row.getLength() lcell = row.item(kk - 1); rc = rc + lcell.getTableNumberColumnsRepeatedAttribute (); endfor - # Watch out for filler tablecells - if (isempty (findstr ('office:value-type', char (lcell))) || isempty (findstr ('<text:', char (lcell)))) + ## Watch out for filler tablecells + if (isempty (findstr ("office:value-type", char (lcell)))... + || isempty (findstr ("<text:", char (lcell)))) rc = rc - lcell.getTableNumberColumnsRepeatedAttribute (); endif rcol = max (rcol, rc); endif else - # Check for repeated tablerows + ## Check for repeated tablerows nrows = nrows + row.getTableNumberRowsRepeatedAttribute (); if (trow) reprows = reprows + row.getTableNumberRowsRepeatedAttribute (); @@ -110,7 +114,7 @@ if (trow) lrow = trow + drows - 1; else - # Empty sheet + ## Empty sheet lrow = 0; lcol = 0; rcol = 0; endif
--- a/main/io/inst/private/__OTK_oct2ods__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_oct2ods__.m Wed Oct 24 21:43:38 2012 +0000 @@ -15,6 +15,7 @@ ## __OTK_oct2ods__ ## write data array to an ODS spreadsheet using Java & ODFtoolkit 0.7.5 +## Note: __OTK_oct2spsh__ uses more recent odfdom that operates at higher level ## I'm truly sorry that oct2jotk2ods is so ridiculously complex, ## and therefore so slow; but there's a good reason for that: @@ -43,51 +44,52 @@ ## 2010-10-27 Improved file change tracking tru ods.changed ## 2010-11-12 Improved file change tracking tru ods.changed ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ ods, rstatus ] = __OTK_oct2ods__ (c_arr, ods, wsh, crange, spsh_opts) persistent ctype; if (isempty (ctype)) - # Number, Boolean, String, Formula, Empty, Date, Time (last 2 are ignored) + ## Number, Boolean, String, Formula, Empty, Date, Time (last 2 are ignored) ctype = [1, 2, 3, 4, 5, 6, 7]; endif rstatus = 0; f_errs = 0; - # Get some basic spreadsheet data from the pointer using ODFtoolkit + ## Get some basic spreadsheet data from the pointer using ODFtoolkit odfcont = ods.workbook; xpath = ods.app.getXPath (); offsprdsh = ods.app.getContentRoot(); autostyles = odfcont.getOrCreateAutomaticStyles(); officestyles = ods.app.getOrCreateDocumentStyles(); - # Create an instance of type NODESET for use in subsequent statements - NODESET = java_get ('javax.xml.xpath.XPathConstants', 'NODESET'); + ## Create an instance of type NODESET for use in subsequent statements + NODESET = java_get ("javax.xml.xpath.XPathConstants", "NODESET"); - # Parse sheets ("tables") from ODS file + ## Parse sheets ("tables") from ODS file sheets = xpath.evaluate ("//table:table", odfcont, NODESET); nr_of_sheets = sheets.getLength (); - newsh = 0; # Assume existing sheet + newsh = 0; ## Assume existing sheet if isempty (wsh) wsh = 1; endif - if (~isnumeric (wsh)) # Sheet name specified - # Search in sheet names, match sheet name to sheet number. - # Beware, 0-based index, 1-based count! + if (~isnumeric (wsh)) ## Sheet name specified + ## Search in sheet names, match sheet name to sheet number. + ## Beware, 0-based index, 1-based count! ii = 0; while (++ii <= nr_of_sheets && ischar (wsh)) - # Look in first part of the sheet nodeset + ## Look in first part of the sheet nodeset sh_name = sheets.item(ii-1).getTableNameAttribute (); if (strcmp (sh_name, wsh)) - # Convert local copy of wsh into a number (pointer) + ## Convert local copy of wsh into a number (pointer) wsh = ii - 1; endif endwhile if (ischar (wsh) && nr_of_sheets < 256) newsh = 1; endif - else # Sheet index specified - if ((ods.changed > 2) || (wsh > nr_of_sheets && wsh < 256)) # Max nr of sheets = 256 - # Create a new sheet + else ## Sheet index specified + if ((ods.changed > 2) || (wsh > nr_of_sheets && wsh < 256)) ## Max nr of sheets = 256 + ## Create a new sheet newsh = 1; elseif (wsh <=nr_of_sheets && wsh > 0) - # Existing sheet. Count = 1-based, index = 0-based + ## Existing sheet. Count = 1-based, index = 0-based --wsh; sh = sheets.item(wsh); printf ("Writing to sheet %s\n", sh.getTableNameAttribute()); else @@ -95,146 +97,148 @@ endif endif -# Check size of data array & range / capacity of worksheet & prepare vars +## Check size of data array & range / capacity of worksheet & prepare vars [nr, nc] = size (c_arr); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, ods.xtype, ods.filename); - --trow; --lcol; # Zero-based row # & col # + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, ods.xtype, ods.filename); + --trow; --lcol; ## Zero-based row ## & col ## if (nrows < nr || ncols < nc) warning ("Array truncated to fit in range"); c_arr = c_arr(1:nrows, 1:ncols); endif -# Parse data array, setup typarr and throw out NaNs to speed up writing; +## Parse data array, setup typarr and throw out NaNs to speed up writing; typearr = spsh_prstype (c_arr, nrows, ncols, ctype, spsh_opts, 0); if ~(spsh_opts.formulas_as_text) - # Find formulas (designated by a string starting with "=" and ending in ")") - fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) && strncmp (x(end:end), ")", 1), c_arr); - typearr(fptr) = ctype(4); # FORMULA + ## Find formulas (designated by a string starting with "=" and ending in ")") + fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) ... + && strncmp (x(end:end), ")", 1), c_arr); + typearr(fptr) = ctype(4); ## FORMULA endif -# Prepare worksheet for writing. If needed create new sheet +## Prepare worksheet for writing. If needed create new sheet if (newsh) if (ods.changed > 2) - # New spreadsheet. Prepare to use the default 1x1 first sheet. + ## New spreadsheet. Prepare to use the default 1x1 first sheet. sh = sheets.item(0); else - # Other sheets exist, create a new sheet. First the basics - sh = java_new ('org.odftoolkit.odfdom.doc.table.OdfTable', odfcont); - # Append sheet to spreadsheet ( contentRoot) + ## Other sheets exist, create a new sheet. First the basics + sh = java_new ("org.odftoolkit.odfdom.doc.table.OdfTable", odfcont); + ## Append sheet to spreadsheet ( contentRoot) offsprdsh.appendChild (sh); - # Rebuild sheets nodes + ## Rebuild sheets nodes sheets = xpath.evaluate ("//table:table", odfcont, NODESET); endif - # Sheet name + ## Sheet name if (isnumeric (wsh)) - # Give sheet a name + ## Give sheet a name str = sprintf ("Sheet%d", wsh); sh.setTableNameAttribute (str); else - # Assign name to sheet and change wsh into numeric pointer + ## Assign name to sheet and change wsh into numeric pointer sh.setTableNameAttribute (wsh); wsh = sheets.getLength () - 1; endif - # Fixup wsh pointer in case of new spreadsheet + ## Fixup wsh pointer in case of new spreadsheet if (ods.changed > 2) wsh = 0; endif - # Add table-column entry for style etc + ## Add table-column entry for style etc col = sh.addTableColumn (); col.setTableDefaultCellStyleNameAttribute ("Default"); col.setTableNumberColumnsRepeatedAttribute (lcol + ncols + 1); col.setTableStyleNameAttribute ("co1"); - # Build up the complete row & cell structure to cover the data array. - # This will speed up processing later + ## Build up the complete row & cell structure to cover the data array. + ## This will speed up processing later - # 1. Build empty table row template - row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - # Create an empty tablecell & append it to the row - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + ## 1. Build empty table row template + row = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableRow", odfcont); + ## Create an empty tablecell & append it to the row + scell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); scell = row.appendCell (scell); scell.setTableNumberColumnsRepeatedAttribute (1024); - # 2. If needed add empty filler row above the data rows & if needed add repeat count + ## 2. If needed add empty filler row above the data rows & if needed add repeat count if (trow > 0) sh.appendRow (row); if (trow > 1) row.setTableNumberRowsRepeatedAttribute (trow); endif endif - # 3. Add data rows; first one serves as a template - drow = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); + ## 3. Add data rows; first one serves as a template + drow = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableRow", odfcont); if (lcol > 0) - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + scell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); drow.appendCell (scell); if (lcol > 1) scell.setTableNumberColumnsRepeatedAttribute (lcol); endif endif - # 4. Add data cell placeholders - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + ## 4. Add data cell placeholders + scell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); drow.appendCell (scell); for jj=2:ncols - dcell = scell.cloneNode (1); # Deep copy + dcell = scell.cloneNode (1); ## Deep copy drow.appendCell (dcell); endfor - # 5. Last cell is remaining column counter + ## 5. Last cell is remaining column counter rest = max (1024 - lcol - ncols); if (rest) - dcell = scell.cloneNode (1); # Deep copy + dcell = scell.cloneNode (1); ## Deep copy drow.appendCell (dcell); if (rest > 1) dcell.setTableNumberColumnsRepeatedAttribute (rest); endif endif - # Only now add drow as otherwise for each cell an empty table-column is - # inserted above the rows (odftoolkit bug?) + ## Only now add drow as otherwise for each cell an empty table-column is + ## inserted above the rows (odftoolkit bug?) sh.appendRow (drow); if (ods.changed > 2) - # In case of a completely new spreadsheet, delete the first initial 1-cell row - # But check if it *is* a row... + ## In case of a completely new spreadsheet, delete the first initial 1-cell row + ## But check if it *is* a row... try sh.removeChild (drow.getPreviousRow ()); catch - # Nothing. Apparently there was only the just appended row. + ## Nothing. Apparently there was only the just appended row. end_try_catch endif - # 6. Row template ready. Copy row template down to cover future array + ## 6. Row template ready. Copy row template down to cover future array for ii=2:nrows - nrow = drow.cloneNode (1); # Deep copy + nrow = drow.cloneNode (1); ## Deep copy sh.appendRow (nrow); endfor - ods.changed = min (ods.changed, 2); # Keep 2 for new spshsht, 1 for existing + changed + ods.changed = min (ods.changed, 2); ## Keep 2 for new spshsht, 1 for existing + changed else - # Existing sheet. We must be prepared for all situations, incomplete rows, - # number-rows/columns-repeated, merged (spanning) cells, you name it. - # First explore row buildup of existing sheet using an XPath - sh = sheets.item(wsh); # 0 - based - str = sprintf ("//table:table[%d]/table:table-row", wsh + 1); # 1 - based + ## Existing sheet. We must be prepared for all situations, incomplete rows, + ## number-rows/columns-repeated, merged (spanning) cells, you name it. + ## First explore row buildup of existing sheet using an XPath + sh = sheets.item(wsh); ## 0 - based + str = sprintf ("//table:table[%d]/table:table-row", wsh + 1); ## 1 - based trows = xpath.evaluate (str, odfcont, NODESET); - nr_of_trows = trows.getLength(); # Nr. of existing table-rows, not data rows! + nr_of_trows = trows.getLength(); ## Nr. of existing table-rows, not data rows! - # For the first rows we do some preprocessing here. Similar stuff for cells - # i.e. table-cells (columns) is done in the loops below. - # Make sure the upper data array row doesn't end up in a nr-rows-repeated row + ## For the first rows we do some preprocessing here. Similar stuff for cells + ## i.e. table-cells (columns) is done in the loops below. + ## Make sure the upper data array row doesn't end up in a nr-rows-repeated row - # Provisionally! set start table-row in case "while" & "if" (split) are skipped + ## Provisionally! set start table-row in case "while" & "if" (split) are skipped drow = trows.item(0); - rowcnt = 0; trowcnt = 0; # Spreadsheet/ table-rows, resp; + rowcnt = 0; trowcnt = 0; ## Spreadsheet/ table-rows, resp; while (rowcnt < trow && trowcnt < nr_of_trows) - # Count rows & table-rows UNTIL we reach trow - ++trowcnt; # Nr of table-rows + ## Count rows & table-rows UNTIL we reach trow + ++trowcnt; ## Nr of table-rows row = drow; drow = row.getNextSibling (); repcnt = row.getTableNumberRowsRepeatedAttribute(); - rowcnt = rowcnt + repcnt; # Nr of spreadsheet rows + rowcnt = rowcnt + repcnt; ## Nr of spreadsheet rows endwhile rsplit = rowcnt - trow; if (rsplit > 0) - # Apparently a nr-rows-repeated top table-row must be split, as the - # first data row seems to be projected in it (1st while condition above!) - row.removeAttribute ('table:number-rows-repeated'); - row.getCellAt (0).removeAttribute ('table:number-columns-repeated'); + ## Apparently a nr-rows-repeated top table-row must be split, as the + ## first data row seems to be projected in it (1st while condition above!) + row.removeAttribute ("table:number-rows-repeated"); + row.getCellAt (0).removeAttribute ("table:number-columns-repeated"); nrow = row.cloneNode (1); - drow = nrow; # Future upper data array row + drow = nrow; ## Future upper data array row if (repcnt > 1) row.setTableNumberRowsRepeatedAttribute (repcnt - rsplit); else - row.removeAttribute ('table:number-rows-repeated'); + row.removeAttribute ("table:number-rows-repeated"); endif rrow = row.getNextSibling (); sh.insertBefore (nrow, rrow); @@ -243,14 +247,14 @@ sh.insertBefore (nrow, rrow); endfor elseif (rsplit < 0) - # New data rows to be added below existing data & table(!) rows, i.e. - # beyond lower end of the current sheet. Add filler row and 1st data row - row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - drow = row.cloneNode (1); # First data row - row.setTableNumberRowsRepeatedAttribute (-rsplit); # Filler row - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + ## New data rows to be added below existing data & table(!) rows, i.e. + ## beyond lower end of the current sheet. Add filler row and 1st data row + row = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableRow", odfcont); + drow = row.cloneNode (1); ## First data row + row.setTableNumberRowsRepeatedAttribute (-rsplit); ## Filler row + scell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); dcell = scell.cloneNode (1); - scell.setTableNumberColumnsRepeatedAttribute (COL_CAP); # Filler cell + scell.setTableNumberColumnsRepeatedAttribute (COL_CAP); ## Filler cell row.appendCell (scell); sh.appendRow (row); drow.appendCell (dcell); @@ -258,26 +262,26 @@ endif endif -# For each row, for each cell, add the data. Expand row/column-repeated nodes +## For each row, for each cell, add the data. Expand row/column-repeated nodes - row = drow; # Start row; pointer still exists from above stanzas + row = drow; ## Start row; pointer still exists from above stanzas for ii=1:nrows - if (~newsh) # Only for existing sheets the next checks should be made - # While processing next data rows, fix table-rows if needed + if (~newsh) ## Only for existing sheets the next checks should be made + ## While processing next data rows, fix table-rows if needed if (isempty (row) || (row.getLength () < 1)) - # Append an empty row with just one empty cell - row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + ## Append an empty row with just one empty cell + row = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableRow", odfcont); + scell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); scell.setTableNumberColumnsRepeatedAttribute (lcol + 1); row.appendCell (scell); sh.appendRow (row); else - # If needed expand nr-rows-repeated + ## If needed expand nr-rows-repeated repcnt = row.getTableNumberRowsRepeatedAttribute (); if (repcnt > 1) - row.removeAttribute ('table:number-rows-repeated'); - # Insert new table-rows above row until our new data space is complete. - # Keep handle of upper new table-row as that's where data are added 1st + row.removeAttribute ("table:number-rows-repeated"); + ## Insert new table-rows above row until our new data space is complete. + ## Keep handle of upper new table-row as that's where data are added 1st drow = row.cloneNode (1); sh.insertBefore (drow, row); for kk=1:min (repcnt, nrows-ii) @@ -291,26 +295,26 @@ endif endif - # Check if leftmost cell ends up in nr-cols-repeated cell + ## Check if leftmost cell ends up in nr-cols-repeated cell colcnt = 0; tcellcnt = 0; rcellcnt = row.getLength(); dcell = row.getCellAt (0); while (colcnt < lcol && tcellcnt < rcellcnt) - # Count columns UNTIL we hit lcol - ++tcellcnt; # Nr of table-cells counted + ## Count columns UNTIL we hit lcol + ++tcellcnt; ## Nr of table-cells counted scell = dcell; dcell = scell.getNextSibling (); repcnt = scell.getTableNumberColumnsRepeatedAttribute (); - colcnt = colcnt + repcnt; # Nr of spreadsheet cell counted + colcnt = colcnt + repcnt; ## Nr of spreadsheet cell counted endwhile csplit = colcnt - lcol; if (csplit > 0) - # Apparently a nr-columns-repeated cell must be split - scell.removeAttribute ('table:number-columns-repeated'); + ## Apparently a nr-columns-repeated cell must be split + scell.removeAttribute ("table:number-columns-repeated"); ncell = scell.cloneNode (1); if (repcnt > 1) scell.setTableNumberColumnsRepeatedAttribute (repcnt - csplit); else - scell.removeAttribute ('table:number-columns-repeated'); + scell.removeAttribute ("table:number-columns-repeated"); endif rcell = scell.getNextSibling (); row.insertBefore (ncell, rcell); @@ -319,8 +323,8 @@ row.insertBefore (ncell, rcell); endfor elseif (csplit < 0) - # New cells to be added beyond current last cell & table-cell in row - dcell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + ## New cells to be added beyond current last cell & table-cell in row + dcell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); scell = dcell.cloneNode (1); dcell.setTableNumberColumnsRepeatedAttribute (-csplit); row.appendCell (dcell); @@ -328,97 +332,100 @@ endif endif - # Write a row of data from data array, column by column + ## Write a row of data from data array, column by column for jj=1:ncols scell = row.getCellAt (lcol + jj - 1); if (~newsh) if (isempty (scell)) - # Apparently end of row encountered. Add cell - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + ## Apparently end of row encountered. Add cell + scell = java_new ("org.odftoolkit.odfdom.doc.table.OdfTableCell", odfcont); scell = row.appendCell (scell); else - # If needed expand nr-cols-repeated + ## If needed expand nr-cols-repeated repcnt = scell.getTableNumberColumnsRepeatedAttribute (); if (repcnt > 1) - scell.removeAttribute ('table:number-columns-repeated'); + scell.removeAttribute ("table:number-columns-repeated"); for kk=2:repcnt ncell = scell.cloneNode (1); row.insertBefore (ncell, scell.getNextSibling ()); endfor endif endif - # Clear text contents + ## Clear text contents while (scell.hasChildNodes ()) tmp = scell.getFirstChild (); scell.removeChild (tmp); endwhile - scell.removeAttribute ('table:formula'); + scell.removeAttribute ("table:formula"); endif - # Empty cell count stuff done. At last we can add the data + ## Empty cell count stuff done. At last we can add the data switch (typearr (ii, jj)) - case 1 # float - scell.setOfficeValueTypeAttribute ('float'); + case 1 ## float + scell.setOfficeValueTypeAttribute ("float"); scell.setOfficeValueAttribute (c_arr{ii, jj}); - case 2 # boolean - # Beware, for unpatched-for-booleans java-1.2.7- we must resort to floats + case 2 ## boolean + ## Beware, for unpatched-for-booleans java-1.2.7- we must resort to floats try - # First try the preferred java-boolean way - scell.setOfficeValueTypeAttribute ('boolean'); - scell.removeAttribute ('office:value'); + ## First try the preferred java-boolean way + scell.setOfficeValueTypeAttribute ("boolean"); + scell.removeAttribute ("office:value"); if (c_arr{ii, jj}) scell.setOfficeBooleanValueAttribute (1); else scell.setOfficeBooleanValueAttribute (0); endif catch - # Unpatched java package. Fall back to transferring a float - scell.setOfficeValueTypeAttribute ('float'); + ## Unpatched java package. Fall back to transferring a float + scell.setOfficeValueTypeAttribute ("float"); if (c_arr{ii, jj}) scell.setOfficeValueAttribute (1); else scell.setOfficeValueAttribute (0); endif end_try_catch - case 3 # string - scell.setOfficeValueTypeAttribute ('string'); - pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', c_arr{ii, jj}); + case 3 ## string + scell.setOfficeValueTypeAttribute ("string"); + pe = java_new ("org.odftoolkit.odfdom.doc.text.OdfTextParagraph",... + odfcont,"", c_arr{ii, jj}); scell.appendChild (pe); - case 4 # Formula. - # As we don't know the result type, simply remove previous type info. - # Once OOo Calc reads it, it'll add the missing attributes - scell.removeAttribute ('office:value'); - scell.removeAttribute ('office:value-type'); - # Try-catch not strictly needed, there's no formula validator yet + case 4 ## Formula. + ## As we don't know the result type, simply remove previous type info. + ## Once OOo Calc reads it, it'll add the missing attributes + scell.removeAttribute ("office:value"); + scell.removeAttribute ("office:value-type"); + ## Try-catch not strictly needed, there's no formula validator yet try scell.setTableFormulaAttribute (c_arr{ii, jj}); - scell.setOfficeValueTypeAttribute ('string'); - pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', '#Recalc Formula#'); + scell.setOfficeValueTypeAttribute ("string"); + pe = java_new ("org.odftoolkit.odfdom.doc.text.OdfTextParagraph",... + odfcont,"", "##Recalc Formula##"); scell.appendChild (pe); catch ++f_errs; - scell.setOfficeValueTypeAttribute ('string'); - pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', c_arr{ii, jj}); + scell.setOfficeValueTypeAttribute ("string"); + pe = java_new ("org.odftoolkit.odfdom.doc.text.OdfTextParagraph",... + odfcont,"", c_arr{ii, jj}); scell.appendChild (pe); end_try_catch - case {0 5} # Empty. Clear value attributes + case {0 5} ## Empty. Clear value attributes if (~newsh) - scell.removeAttribute ('office:value-type'); - scell.removeAttribute ('office:value'); + scell.removeAttribute ("office:value-type"); + scell.removeAttribute ("office:value"); endif - case 6 # Date (implemented but Octave has no "date" data type - yet?) - scell.setOfficeValueTypeAttribute ('date'); + case 6 ## Date (implemented but Octave has no "date" data type - yet?) + scell.setOfficeValueTypeAttribute ("date"); [hh mo dd hh mi ss] = datevec (c_arr{ii,jj}); str = sprintf ("%4d-%2d-%2dT%2d:%2d:%2d", yy, mo, dd, hh, mi, ss); scell.setOfficeDateValueAttribute (str); - case 7 # Time (implemented but Octave has no "time" data type) - scell.setOfficeValueTypeAttribute ('time'); + case 7 ## Time (implemented but Octave has no "time" data type) + scell.setOfficeValueTypeAttribute ("time"); [hh mo dd hh mi ss] = datevec (c_arr{ii,jj}); str = sprintf ("PT%2d:%2d:%2d", hh, mi, ss); scell.setOfficeTimeValuettribute (str); otherwise - # Nothing + ## Nothing endswitch scell = scell.getNextSibling (); @@ -432,7 +439,7 @@ if (f_errs) printf ("%d formula errors encountered - please check input array\n", f_errs); endif - ods.changed = max (min (ods.changed, 2), changed); # Preserve 2 (new file), 1 (existing) + ods.changed = max (min (ods.changed, 2), changed); ## Preserve 2 (new file), 1 (existing) rstatus = 1; endfunction
--- a/main/io/inst/private/__OTK_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -41,35 +41,35 @@ persistent ctype; if (isempty (ctype)) - # Number, Boolean, String, Formula, Empty; Date, Time - last two aren't used + ## Number, Boolean, String, Formula, Empty; Date, Time - last two aren't used ctype = [1, 2, 3, 4, 5, 6, 7]; endif rstatus = 0; changed = 0; newsh = 0; - # Get contents and table stuff from the workbook - odfcont = ods.workbook; # Use a local copy just to be sure. octave - # makes physical copies only when needed (?) + ## Get contents and table stuff from the workbook + odfcont = ods.workbook; ## Use a local copy just to be sure. octave + ## makes physical copies only when needed (?) odfroot = odfcont.getRootElement (); offsprdsh = ods.app.getContentRoot(); - if (strcmp (ods.odfvsn, '0.8.7') || strfind (ods.odfvsn, "0.8.8")) + if (strcmp (ods.odfvsn, "0.8.7") || strfind (ods.odfvsn, "0.8.8")) spsh = odfcont.getDocument (); else spsh = odfcont.getOdfDocument (); endif - # Get some basic spreadsheet data from the pointer using ODFtoolkit + ## Get some basic spreadsheet data from the pointer using ODFtoolkit autostyles = odfcont.getOrCreateAutomaticStyles(); officestyles = ods.app.getOrCreateDocumentStyles(); - # Parse sheets ("tables") from ODS file + ## Parse sheets ("tables") from ODS file sheets = ods.app.getTableList(); nr_of_sheets = sheets.size (); - # Check user input & find sheet pointer + ## Check user input & find sheet pointer if (~isnumeric (wsh)) try sh = ods.app.getTableByName (wsh); - # We do need a sheet index number... + ## We do need a sheet index number... ii = 0; while (ischar (wsh) && ii < nr_of_sheets) sh_nm = sh.getTableName (); @@ -80,7 +80,7 @@ end_try_catch if isempty (sh) newsh = 1; endif elseif (wsh < 1) - # Negative sheet number: + ## Negative sheet number: error (sprintf ("Illegal worksheet nr. %d\n", wsh)); elseif (wsh > nr_of_sheets) newsh = 1; @@ -88,47 +88,49 @@ sh = sheets.get (wsh - 1); endif - # Check size of data array & range / capacity of worksheet & prepare vars + ## Check size of data array & range / capacity of worksheet & prepare vars [nr, nc] = size (c_arr); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, ods.xtype, ods.filename); - --trow; --lcol; # Zero-based row # & col # + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, ods.xtype, ods.filename); + --trow; --lcol; ## Zero-based row ## & col ## if (nrows < nr || ncols < nc) warning ("Array truncated to fit in range"); c_arr = c_arr(1:nrows, 1:ncols); endif -# Parse data array, setup typarr and throw out NaNs to speed up writing; + ## Parse data array, setup typarr and throw out NaNs to speed up writing; typearr = spsh_prstype (c_arr, nrows, ncols, ctype, spsh_opts); if ~(spsh_opts.formulas_as_text) - # Find formulas (designated by a string starting with "=" and ending in ")") - fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) && strncmp (x(end:end), ")", 1), c_arr); - typearr(fptr) = ctype(4); # FORMULA + ## Find formulas (designated by a string starting with "=" and ending in ")") + fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) ... + && strncmp (x(end:end), ")", 1), c_arr); + typearr(fptr) = ctype(4); ## FORMULA endif -# Prepare spreadsheet for writing (size, etc.). If needed create new sheet + ## Prepare spreadsheet for writing (size, etc.). If needed create new sheet if (newsh) if (ods.changed > 2) - # New spreadsheet, use default first sheet + ## New spreadsheet, use default first sheet sh = sheets.get (0); else - # Create a new sheet using DOM API. This part works OK. + ## Create a new sheet using DOM API. This part works OK. sh = sheets.get (nr_of_sheets - 1).newTable (spsh, nrows, ncols); endif changed = 1; if (isnumeric (wsh)) - # Give sheet a name + ## Give sheet a name str = sprintf ("Sheet%d", wsh); sh.setTableName (str); wsh = str; else - # Assign name to sheet and change wsh into numeric pointer + ## Assign name to sheet and change wsh into numeric pointer sh.setTableName (wsh); endif - # printf ("Sheet %s added to spreadsheet.\n", wsh); + ## printf ("Sheet %s added to spreadsheet.\n", wsh); else - # Add "physical" rows & columns. Spreadsheet max. capacity checks have been done above - # Add spreadsheet data columns if needed. Compute nr of extra columns & rows. + ## Add "physical" rows & columns. Spreadsheet max. capacity checks have been done above + ## Add spreadsheet data columns if needed. Compute nr of extra columns & rows. curr_ncols = sh.getColumnCount (); ii = max (0, lcol + ncols - curr_ncols); if (ii == 1) @@ -137,7 +139,7 @@ nwcols = sh.appendColumns (ii); endif - # Add spreadsheet rows if needed + ## Add spreadsheet rows if needed curr_nrows = sh.getRowCount (); ii = max (0, trow + nrows - curr_nrows); if (ii == 1) @@ -147,36 +149,36 @@ endif endif - # Transfer array data to sheet + ## Transfer array data to sheet for ii=1:nrows for jj=1:ncols ocell = sh.getCellByPosition (jj+lcol-1, ii+trow-1); - if ~(isempty (ocell )) # Might be spanned (merged), hidden, .... - # Number, String, Boolean, Date, Time + if ~(isempty (ocell )) ## Might be spanned (merged), hidden, .... + ## Number, String, Boolean, Date, Time try switch typearr (ii, jj) - case {1, 6, 7} # Numeric, Date, Time + case {1, 6, 7} ## Numeric, Date, Time ocell.setDoubleValue (c_arr{ii, jj}); - case 2 # Logical / Boolean - # ocell.setBooleanValue (c_arr{ii, jj}); # Doesn't work, bug in odfdom 0.8.6 - # Bug workaround: 1. Remove all cell contents + case 2 ## Logical / Boolean + ## ocell.setBooleanValue (c_arr{ii, jj}); ## Doesn't work, bug in odfdom 0.8.6 + ## Bug workaround: 1. Remove all cell contents ocell.removeContent (); - # 2. Switch to TableTableElement API + ## 2. Switch to TableTableElement API tocell = ocell.getOdfElement (); - tocell.setAttributeNS ('office', 'office:value-type', 'boolean'); - # 3. Add boolean-value attribute. - # This is only accepted in TTE API with a NS tag (actual bug, IMO) + tocell.setAttributeNS ("office", "office:value-type", "boolean"); + ## 3. Add boolean-value attribute. + ## This is only accepted in TTE API with a NS tag (actual bug, IMO) if (c_arr {ii,jj}) - tocell.setAttributeNS ('office', 'office:boolean-value', 'true'); + tocell.setAttributeNS ("office", "office:boolean-value", "true"); else - tocell.setAttributeNS ('office', 'office:boolean-value', 'false'); + tocell.setAttributeNS ("office", "office:boolean-value", "false"); endif - case 3 # String + case 3 ## String ocell.setStringValue (c_arr{ii, jj}); - case 4 # Formula + case 4 ## Formula ocell.setFormula (c_arr{ii, jj}); - otherwise # 5, empty and catch-all - # The above is all octave has to offer & java can accept... + otherwise ## 5, empty and catch-all + ## The above is all octave has to offer & java can accept... endswitch changed = 1; catch @@ -187,7 +189,7 @@ endfor if (changed) - ods.changed = max (min (ods.changed, 2), changed); # Preserve 2 (new file), 1 (existing) + ods.changed = max (min (ods.changed, 2), changed); ## Preserve 2 (new file), 1 (existing) rstatus = 1; endif
--- a/main/io/inst/private/__OTK_ods2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_ods2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -30,39 +30,40 @@ ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to caller ## 2011-09-18 Remove rstatus var (now set in caller) ## 2012-10-12 Renamed & moved 2 ./private; soon te be dropped as OTK 0.7.5 is too old +## 2012-10-24 Style fixes function [ rawarr, ods ] = __OTK_ods2oct__ (ods, wsh, crange, spsh_opts) - # Parts after user gfterry in - # http://www.oooforum.org/forum/viewtopic.phtml?t=69060 + ## Parts after user gfterry in + ## http://www.oooforum.org/forum/viewtopic.phtml?t=69060 - # Get contents and table stuff from the workbook - odfcont = ods.workbook; # Use a local copy just to be sure. octave - # makes physical copies only when needed (?) + ## Get contents and table stuff from the workbook + odfcont = ods.workbook; ## Use a local copy just to be sure. octave + ## makes physical copies only when needed (?) xpath = ods.app.getXPath; - # AFAICS ODS spreadsheets have the following hierarchy (after Xpath processing): - # <table:table> - table nodes, the actual worksheets; - # <table:table-row> - row nodes, the rows in a worksheet; - # <table:table-cell> - cell nodes, the cells in a row; - # Styles (formatting) are defined in a section "settings" outside the - # contents proper but are referenced in the nodes. + ## AFAICS ODS spreadsheets have the following hierarchy (after Xpath processing): + ## <table:table> - table nodes, the actual worksheets; + ## <table:table-row> - row nodes, the rows in a worksheet; + ## <table:table-cell> - cell nodes, the cells in a row; + ## Styles (formatting) are defined in a section "settings" outside the + ## contents proper but are referenced in the nodes. - # Create an instance of type NODESET for use in subsequent statement - NODESET = java_get ('javax.xml.xpath.XPathConstants', 'NODESET'); - # Parse sheets ("tables") from ODS file + ## Create an instance of type NODESET for use in subsequent statement + NODESET = java_get ("javax.xml.xpath.XPathConstants", "NODESET"); + ## Parse sheets ("tables") from ODS file sheets = xpath.evaluate ("//table:table", odfcont, NODESET); nr_of_sheets = sheets.getLength (); - # Check user input & find sheet pointer (1-based), using ugly hacks + ## Check user input & find sheet pointer (1-based), using ugly hacks if (~isnumeric (wsh)) - # Search in sheet names, match sheet name to sheet number + ## Search in sheet names, match sheet name to sheet number ii = 0; while (++ii <= nr_of_sheets && ischar (wsh)) - # Look in first part of the sheet nodeset + ## Look in first part of the sheet nodeset sh_name = sheets.item(ii-1).getTableNameAttribute (); if (strcmp (sh_name, wsh)) - # Convert local copy of wsh into a number (pointer) + ## Convert local copy of wsh into a number (pointer) wsh = ii; endif endwhile @@ -70,40 +71,40 @@ error (sprintf ("No worksheet '%s' found in file %s", wsh, ods.filename)); endif elseif (wsh > nr_of_sheets || wsh < 1) - # We already have a numeric sheet pointer. If it's not in range: + ## We already have a numeric sheet pointer. If it's not in range: error (sprintf ("Worksheet no. %d out of range (1 - %d)", wsh, nr_of_sheets)); endif - # Get table-rows in sheet no. wsh. Sheet count = 1-based (!) + ## Get table-rows in sheet no. wsh. Sheet count = 1-based (!) str = sprintf ("//table:table[%d]/table:table-row", wsh); sh = xpath.evaluate (str, odfcont, NODESET); nr_of_rows = sh.getLength (); - # Either parse (given cell range) or prepare (unknown range) help variables + ## Either parse (given cell range) or prepare (unknown range) help variables if (isempty (crange)) [ trow, brow, lcol, rcol ] = getusedrange (ods, wsh); - nrows = brow - trow + 1; # Number of rows to be read - ncols = rcol - lcol + 1; # Number of columns to be read + nrows = brow - trow + 1; ## Number of rows to be read + ncols = rcol - lcol + 1; ## Number of columns to be read else [dummy, nrows, ncols, trow, lcol] = parse_sp_range (crange); brow = min (trow + nrows - 1, nr_of_rows); - # Check ODS column limits + ## Check ODS column limits if (lcol > 1024 || trow > 65536) error ("ods2oct: invalid range; max 1024 columns & 65536 rows."); endif - # Truncate range silently if needed + ## Truncate range silently if needed rcol = min (lcol + ncols - 1, 1024); ncols = min (ncols, 1024 - lcol + 1); nrows = min (nrows, 65536 - trow + 1); endif - # Create storage for data content + ## Create storage for data content rawarr = cell (nrows, ncols); - # Prepare reading sheet row by row - rightmcol = 0; # Used to find actual rightmost column - ii = trow - 1; # Spreadsheet row counter + ## Prepare reading sheet row by row + rightmcol = 0; ## Used to find actual rightmost column + ii = trow - 1; ## Spreadsheet row counter rowcnt = 0; - # Find uppermost requested *tablerow*. It may be influenced by nr-rows-repeated + ## Find uppermost requested *tablerow*. It may be influenced by nr-rows-repeated if (ii >= 1) tfillrows = 0; while (tfillrows < ii) @@ -112,48 +113,49 @@ tfillrows = tfillrows + extrarows; ++rowcnt; endwhile - # Desired top row may be in a nr-rows-repeated tablerow.... + ## Desired top row may be in a nr-rows-repeated tablerow.... if (tfillrows > ii); ii = tfillrows; endif endif - # Read from worksheet row by row. Row numbers are 0-based + ## Read from worksheet row by row. Row numbers are 0-based while (ii < brow) row = sh.item(rowcnt++); nr_of_cells = min (row.getLength (), rcol); - rightmcol = max (rightmcol, nr_of_cells); # Keep track of max row length - # Read column (cell, "table-cell" in ODS speak) by column + rightmcol = max (rightmcol, nr_of_cells); ## Keep track of max row length + ## Read column (cell, "table-cell" in ODS speak) by column jj = lcol; while (jj <= rcol) tcell = row.getCellAt(jj-1); form = 0; - if (~isempty (tcell)) # If empty it's possibly in columns-repeated/spanned - if (spsh_opts.formulas_as_text) # Get spreadsheet formula rather than value - # Check for formula attribute + if (~isempty (tcell)) ## If empty it's possibly in columns-repeated/spanned + if (spsh_opts.formulas_as_text) ## Get spreadsheet formula rather than value + ## Check for formula attribute tmp = tcell.getTableFormulaAttribute (); if isempty (tmp) form = 0; else - if (strcmp (tolower (tmp(1:3)), 'of:')) + if (strcmp (tolower (tmp(1:3)), "of:")) tmp (1:end-3) = tmp(4:end); endif rawarr(ii-trow+2, jj-lcol+1) = tmp; form = 1; endif endif - if ~(form || index (char(tcell), 'text:p>Err:') || index (char(tcell), 'text:p>#DIV')) - # Get data from cell + if ~(form || index (char(tcell), "text:p>Err:") ... + || index (char(tcell), "text:p>##DIV")) + ## Get data from cell ctype = tcell.getOfficeValueTypeAttribute (); cvalue = tcell.getOfficeValueAttribute (); switch deblank (ctype) - case {'float', 'currency', 'percentage'} + case {"float", "currency", "percentage"} rawarr(ii-trow+2, jj-lcol+1) = cvalue; - case 'date' + case "date" cvalue = tcell.getOfficeDateValueAttribute (); - # Dates are returned as octave datenums, i.e. 0-0-0000 based + ## Dates are returned as octave datenums, i.e. 0-0-0000 based yr = str2num (cvalue(1:4)); mo = str2num (cvalue(6:7)); dy = str2num (cvalue(9:10)); - if (index (cvalue, 'T')) + if (index (cvalue, "T")) hh = str2num (cvalue(12:13)); mm = str2num (cvalue(15:16)); ss = str2num (cvalue(18:19)); @@ -161,51 +163,51 @@ else rawarr(ii-trow+2, jj-lcol+1) = datenum (yr, mo, dy); endif - case 'time' + case "time" cvalue = tcell.getOfficeTimeValueAttribute (); - if (index (cvalue, 'PT')) + if (index (cvalue, "PT")) hh = str2num (cvalue(3:4)); mm = str2num (cvalue(6:7)); ss = str2num (cvalue(9:10)); rawarr(ii-trow+2, jj-lcol+1) = datenum (0, 0, 0, hh, mm, ss); endif - case 'boolean' + case "boolean" cvalue = tcell.getOfficeBooleanValueAttribute (); rawarr(ii-trow+2, jj-lcol+1) = cvalue; - case 'string' + case "string" cvalue = tcell.getOfficeStringValueAttribute (); - if (isempty (cvalue)) # Happens with e.g., hyperlinks + if (isempty (cvalue)) ## Happens with e.g., hyperlinks tmp = char (tcell); - # Hack string value from between <text:p|r> </text:p|r> tags - ist = findstr (tmp, '<text:'); + ## Hack string value from between <text:p|r> </text:p|r> tags + ist = findstr (tmp, "<text:"); if (ist) ist = ist (length (ist)); ist = ist + 8; - ien = index (tmp(ist:end), '</text') + ist - 2; + ien = index (tmp(ist:end), "</text") + ist - 2; tmp (ist:ien); cvalue = tmp(ist:ien); endif endif rawarr(ii-trow+2, jj-lcol+1)= cvalue; otherwise - # Nothing + ## Nothing endswitch endif endif - ++jj; # Next cell + ++jj; ## Next cell endwhile - # Check for repeated rows (i.e. condensed in one table-row) + ## Check for repeated rows (i.e. condensed in one table-row) extrarows = row.getTableNumberRowsRepeatedAttribute () - 1; if (extrarows > 0 && (ii + extrarows) < 65535) - # Expand rawarr cf. table-row + ## Expand rawarr cf. table-row nr_of_rows = nr_of_rows + extrarows; ii = ii + extrarows; endif ++ii; endwhile - # Keep track of data rectangle limits + ## Keep track of data rectangle limits ods.limits = [lcol, rcol; trow, brow]; endfunction
--- a/main/io/inst/private/__OTK_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -24,18 +24,19 @@ ## because this casts all numeric cells to string type for properly written ODS1.2 ## '' Remove rstatus var (now set in caller) ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ rawarr, ods ] = __OTK_spsh2oct__ (ods, wsh, crange, spsh_opts) - # Get contents and table stuff from the workbook - odfcont = ods.workbook; # Use a local copy just to be sure. octave - # makes physical copies only when needed (?) + ## Get contents and table stuff from the workbook + odfcont = ods.workbook; ## Use a local copy just to be sure. octave + ## makes physical copies only when needed (?) - # Parse sheets ("tables") from ODS file + ## Parse sheets ("tables") from ODS file sheets = ods.app.getTableList(); nr_of_sheets = sheets.size (); - # Check user input & find sheet pointer (1-based) + ## Check user input & find sheet pointer (1-based) if (~isnumeric (wsh)) try sh = ods.app.getTableByName (wsh); @@ -47,16 +48,16 @@ error (sprintf ("Sheet %s not found in file %s\n", wsh, ods.filename)); endif elseif (wsh > nr_of_sheets || wsh < 1) - # We already have a numeric sheet pointer. If it's not in range: + ## We already have a numeric sheet pointer. If it's not in range: error (sprintf ("Worksheet no. %d out of range (1 - %d)", wsh, nr_of_sheets)); else sh = sheets.get (wsh - 1); endif - # Either parse (given cell range) or prepare (unknown range) help variables + ## Either parse (given cell range) or prepare (unknown range) help variables if (isempty (crange)) if ~isnumeric (wsh) - # Get sheet index + ## Get sheet index jj = nr_of_sheets; while jj-- >= 0 if (strcmp (wsh, sheets.get(jj).getTableName()) == 1) @@ -66,25 +67,25 @@ endwhile endif [ trow, brow, lcol, rcol ] = getusedrange (ods, wsh); - nrows = brow - trow + 1; # Number of rows to be read - ncols = rcol - lcol + 1; # Number of columns to be read + nrows = brow - trow + 1; ## Number of rows to be read + ncols = rcol - lcol + 1; ## Number of columns to be read else [dummy, nrows, ncols, trow, lcol] = parse_sp_range (crange); - # Check ODS row/column limits + ## Check ODS row/column limits if (lcol > 1024 || trow > 65536) error ("ods2oct: invalid range; max 1024 columns & 65536 rows."); endif - # Truncate range silently if needed + ## Truncate range silently if needed rcol = min (lcol + ncols - 1, 1024); ncols = min (ncols, 1024 - lcol + 1); nrows = min (nrows, 65536 - trow + 1); brow = trow + nrows - 1; endif - # Create storage for data content + ## Create storage for data content rawarr = cell (nrows, ncols); - # Read from worksheet row by row. Row numbers are 0-based + ## Read from worksheet row by row. Row numbers are 0-based for ii=trow:nrows+trow-1 row = sh.getRowByIndex (ii-1); for jj=lcol:ncols+lcol-1; @@ -93,26 +94,28 @@ otype = deblank (tolower (ocell.getValueType ())); if (spsh_opts.formulas_as_text) if ~isempty (ocell.getFormula ()) - otype = 'formula'; + otype = "formula"; endif endif -# # Provisions for catching jOpenDocument 1.2b bug where text cells -# # haven't been assigned an <office:value-type='string'> attribute -# if (~isempty (ocell)) -# if (findstr ('<text:', char (ocell.getOdfElement ()))), otype = 'string'; endif -# endif - # At last, read the data +## ## Provisions for catching jOpenDocument 1.2b bug where text cells +## ## haven't been assigned an <office:value-type='string'> attribute +## if (~isempty (ocell)) +## if (findstr ("<text:", char (ocell.getOdfElement ()))) +## otype = "string"; +## endif +## endif + ## At last, read the data switch otype - case {'float', 'currency', 'percentage'} + case {"float", "currency", "percentage"} rawarr(ii-trow+1, jj-lcol+1) = ocell.getDoubleValue (); - case 'date' - # Dive into TableTable API + case "date" + ## Dive into TableTable API tvalue = ocell.getOdfElement ().getOfficeDateValueAttribute (); - # Dates are returned as octave datenums, i.e. 0-0-0000 based + ## Dates are returned as octave datenums, i.e. 0-0-0000 based yr = str2num (tvalue(1:4)); mo = str2num (tvalue(6:7)); dy = str2num (tvalue(9:10)); - if (index (tvalue, 'T')) + if (index (tvalue, "T")) hh = str2num (tvalue(12:13)); mm = str2num (tvalue(15:16)); ss = str2num (tvalue(18:19)); @@ -120,45 +123,45 @@ else rawarr(ii-trow+1, jj-lcol+1) = datenum (yr, mo, dy); endif - case 'time' - # Dive into TableTable API + case "time" + ## Dive into TableTable API tvalue = ocell.getOdfElement ().getOfficeTimeValueAttribute (); - if (index (tvalue, 'PT')) + if (index (tvalue, "PT")) hh = str2num (tvalue(3:4)); mm = str2num (tvalue(6:7)); ss = str2num (tvalue(9:10)); rawarr(ii-trow+1, jj-lcol+1) = datenum (0, 0, 0, hh, mm, ss); endif - case 'boolean' + case "boolean" rawarr(ii-trow+1, jj-lcol+1) = ocell.getBooleanValue (); - case 'string' + case "string" rawarr(ii-trow+1, jj-lcol+1) = ocell.getStringValue (); -# # 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 -# tmp = char (tcell); -# # Hack string value from between <text:p|r> </text:p|r> tags -# ist = findstr (tmp, '<text:'); -# if (ist) -# ist = ist (length (ist)); -# ist = ist + 8; -# ien = index (tmp(ist:end), '</text') + ist - 2; -# tmp (ist:ien); -# cvalue = tmp(ist:ien); -# endif -# endif -# rawarr(ii-trow+1, jj-lcol+1)= cvalue; - case 'formula' +## ## 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 +## tmp = char (tcell); +## ## Hack string value from between <text:p|r> </text:p|r> tags +## ist = findstr (tmp, "<text:"); +## if (ist) +## ist = ist (length (ist)); +## ist = ist + 8; +## ien = index (tmp(ist:end), "</text") + ist - 2; +## tmp (ist:ien); +## cvalue = tmp(ist:ien); +## endif +## endif +## rawarr(ii-trow+1, jj-lcol+1)= cvalue; + case "formula" rawarr(ii-trow+1, jj-lcol+1) = ocell.getFormula (); otherwise - # Nothing. + ## Nothing. endswitch endif endfor endfor - # Keep track of data rectangle limits + ## Keep track of data rectangle limits ods.limits = [lcol, rcol; trow, brow]; endfunction
--- a/main/io/inst/private/__OTK_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,6 +18,8 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-23 Style fixes (none) function [ ods ] = __OTK_spsh_close__ (ods, force)
--- a/main/io/inst/private/__OTK_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,30 +20,32 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## 2012-10-24 Style fixes function [sh_names] = __OTK_spsh_info__ (ods) - # Get contents and table (= sheet) stuff from the workbook - if (strcmp (ods.odfvsn, '0.8.7') || strfind (ods.odfvsn, "0.8.8")) + ## Get contents and table (= sheet) stuff from the workbook + if (strcmp (ods.odfvsn, "0.8.7") || strfind (ods.odfvsn, "0.8.8")) xpath = ods.workbook.getXPath; else xpath = ods.app.getXPath; endif - # Create an instance of type NODESET for use in subsequent statement - NODESET = java_get ('javax.xml.xpath.XPathConstants', 'NODESET'); - # Parse sheets ("tables") from ODS file + ## Create an instance of type NODESET for use in subsequent statement + NODESET = java_get ("javax.xml.xpath.XPathConstants", "NODESET"); + ## Parse sheets ("tables") from ODS file sheets = xpath.evaluate ("//table:table", ods.workbook, NODESET); nr_of_sheets = sheets.getLength(); sh_names = cell (nr_of_sheets, 2); - # Get sheet names (& optionally data row count estimate) + ## Get sheet names (& optionally data row count estimate) for ii=1:nr_of_sheets - # Check in first part of the sheet nodeset + ## Check in first part of the sheet nodeset sh_names (ii) = sheets.item(ii-1).getTableNameAttribute (); [ tr, lr, lc, rc ] = getusedrange (ods, ii); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc),... + calccelladdress (lr, rc)); endif endfor
--- a/main/io/inst/private/__OTK_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OTK_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2012 Philip +## Copyright (C) 2012 Philip Nienhuis <prnienhuis@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 @@ -16,35 +16,50 @@ ## __OTK_SPSH_open -## Author: Philip <Philip@DESKPRN> +## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-24 Style fixes + +function [ ods, odssupport, lastintf ] = __OTK_spsh_open__ (ods, rw, filename, odssupport) -function [ ods, odssupport, lastintf ] = __OTK_spsh_open__ (ods, rw, filename, odssupport, chk2, odsinterfaces) + ## Parts after user gfterry in + ## http://www.oooforum.org/forum/viewtopic.phtml?t=69060 + + ## Get odfdom version + persistent odfvsn; odfvsn = []; + if (isempty (odfvsn)) + try + odfvsn = " "; + ## New in 0.8.6 + odfvsn = ... + java_invoke ("org.odftoolkit.odfdom.JarManifest", "getOdfdomVersion"); + catch + odfvsn = ... + java_invoke ("org.odftoolkit.odfdom.Version", "getApplicationVersion"); + end_try_catch + ## For odfdom-incubator (= 0.8.8+), strip extra info + odfvsn = regexp (odfvsn, '\d\.\d\.\d', "match"){1}; + endif - # Parts after user gfterry in - # http://www.oooforum.org/forum/viewtopic.phtml?t=69060 - odftk = 'org.odftoolkit.odfdom.doc'; + odftk = "org.odftoolkit.odfdom.doc"; try if (rw > 2) - # New spreadsheet - wb = java_invoke ([odftk '.OdfSpreadsheetDocument'], 'newSpreadsheetDocument'); + ## New spreadsheet + wb = java_invoke ([odftk ".OdfSpreadsheetDocument"], "newSpreadsheetDocument"); else - # Existing spreadsheet - wb = java_invoke ([odftk '.OdfDocument'], 'loadDocument', filename); + ## Existing spreadsheet + wb = java_invoke ([odftk ".OdfDocument"], "loadDocument", filename); endif ods.workbook = wb.getContentDom (); # Reads the entire spreadsheet - ods.xtype = 'OTK'; + ods.xtype = "OTK"; ods.app = wb; ods.filename = filename; - ods.odfvsn = odsinterfaces.odfvsn; + ods.odfvsn = odfvsn; odssupport += 1; - lastintf = 'OTK'; + lastintf = "OTK"; catch - if (odsinterfaces.JOD && ~rw && chk2) - printf ('Couldn''t open file %s using OTK; trying .sxc format with JOD...\n', filename); - else - error ('Couldn''t open file %s using OTK', filename); - endif + error ("Couldn't open file %s using OTK", filename); end_try_catch endfunction
--- a/main/io/inst/private/__OXS_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OXS_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2010,2011,2012 Philip Nienhuis, <prnienhuis at users.sf.net> +## Copyright (C) 2010,2011,2012 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 the Free Software @@ -20,21 +20,24 @@ ## Updates: ## 2011-06-29 try-catch to be able to skip non-data (e.g., graph) sheets ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ trow, brow, lcol, rcol ] = __OXS_getusedrange__ (xls, wsh) sh = xls.workbook.getWorkSheet (wsh - 1); try - # Intriguing: sh.getFirst<> is off by one, sh.getLast<> = OK.... 8-Z + ## Intriguing: sh.getFirst<> is off by one, sh.getLast<> = OK.... 8-Z trow = sh.getFirstRow () + 1; brow = sh.getLastRow (); lcol = sh.getFirstCol () + 1; rcol = sh.getLastCol (); catch - # Might be an empty sheet + ## Might be an empty sheet trow = brow = lcol = rcol = 0; end_try_catch - # Check for empty sheet - if ((trow > brow) || (lcol > rcol)), trow = brow = lcol = rcol = 0; endif + ## Check for empty sheet + if ((trow > brow) || (lcol > rcol)) + trow = brow = lcol = rcol = 0; + endif endfunction
--- a/main/io/inst/private/__OXS_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OXS_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -33,96 +33,100 @@ ## Created: 2011-03-29 ## Updates: ## 2012-10-12 Renamed & moved into ./private - +## 2012-10-24 Style fixes function [ xls, rstatus ] = __OXS_oct2spsh__ (obj, xls, wsh, crange, spsh_opts) - # Preliminary sanity checks - if (~strmatch (tolower (xls.filename(end-4:end-1)), '.xls')) # No OOXML in OXS - error ("OXS interface can only write to Excel .xls files") - endif - - changed = 0; + ## Preliminary sanity checks + if (~strmatch (tolower (xls.filename(end-4:end-1)), ".xls")) + ## No OOXML in OXS + error ("OXS interface can only write to Excel .xls files") + endif + + changed = 0; - persistent ctype; - if (isempty (ctype)) - ctype = [1, 2, 3, 4, 5]; - # Number, Boolean, String, Formula, Empty - endif - # scratch vars - rstatus = 0; f_errs = 0; - - # Prepare workbook pointer if needed - wb = xls.workbook; + persistent ctype; + if (isempty (ctype)) + ## Number, Boolean, String, Formula, Empty + ctype = [1, 2, 3, 4, 5]; + endif + ## scratch vars + rstatus = 0; f_errs = 0; + + ## Prepare workbook pointer if needed + wb = xls.workbook; - # Check if requested worksheet exists in the file & if so, get pointer - nr_of_sheets = wb.getNumWorkSheets (); # 1 based !! - if (isnumeric (wsh)) - if (wsh > nr_of_sheets) - # Watch out as a sheet called Sheet%d can exist with a lower index... - strng = sprintf ("Sheet%d", wsh); - ii = 1; - try - # While loop should be inside try-catch - while (ii < 5) - sh = wb.getWorkSheet (strng) - strng = ['_' strng]; - ++ii; - endwhile - catch - # No worksheet named <strng> found => we can proceed - end_try_catch - if (ii >= 5) error (sprintf( " > 5 sheets named [_]Sheet%d already present!", wsh)); endif - sh = wb.createWorkSheet (strng); ++nr_of_sheets; - xls.changed = min (xls.changed, 2); # Keep a 2 in case of new file - else - sh = wb.getWorkSheet (wsh - 1); # OXS sheet count 0-based - endif - printf ("(Writing to worksheet %s)\n", sh.getSheetName ()); - else - try - sh = wb.getWorkSheet (wsh); - catch - # Sheet not found, just create it - sh = wb.createWorkSheet (wsh); ++nr_of_sheets; - xls.changed = min (xls.changed, 2); # Keep a 2 for new file - end_try_catch - endif + ## Check if requested worksheet exists in the file & if so, get pointer + nr_of_sheets = wb.getNumWorkSheets (); ## 1 based !! + if (isnumeric (wsh)) + if (wsh > nr_of_sheets) + ## Watch out as a sheet called Sheet%d can exist with a lower index... + strng = sprintf ("Sheet%d", wsh); + ii = 1; + try + ## While loop should be inside try-catch + while (ii < 5) + sh = wb.getWorkSheet (strng) + strng = ['_' strng]; + ++ii; + endwhile + catch + ## No worksheet named <strng> found => we can proceed + end_try_catch + if (ii >= 5) + error (sprintf( " > 5 sheets named [_]Sheet%d already present!", wsh)); + endif + sh = wb.createWorkSheet (strng); ++nr_of_sheets; + xls.changed = min (xls.changed, 2); ## Keep a 2 in case of new file + else + sh = wb.getWorkSheet (wsh - 1); ## OXS sheet count 0-based + endif + printf ("(Writing to worksheet %s)\n", sh.getSheetName ()); + else + try + sh = wb.getWorkSheet (wsh); + catch + ## Sheet not found, just create it + sh = wb.createWorkSheet (wsh); ++nr_of_sheets; + xls.changed = min (xls.changed, 2); ## Keep a 2 for new file + end_try_catch + endif - # Parse date ranges - [nr, nc] = size (obj); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); - if (nrows < nr || ncols < nc) - warning ("Array truncated to fit in range"); - obj = obj(1:nrows, 1:ncols); - endif + ## Parse date ranges + [nr, nc] = size (obj); + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); + if (nrows < nr || ncols < nc) + warning ("Array truncated to fit in range"); + obj = obj(1:nrows, 1:ncols); + endif - # Prepare type array - typearr = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts); - if ~(spsh_opts.formulas_as_text) - # Remove leading '=' from formula strings //FIXME needs updating - fptr = ~(4 * (ones (size (typearr))) .- typearr); - obj(fptr) = cellfun (@(x) x(2:end), obj(fptr), "Uniformoutput", false); - endif - clear fptr + ## Prepare type array + typearr = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts); + if ~(spsh_opts.formulas_as_text) + ## Remove leading '=' from formula strings //FIXME needs updating + fptr = ~(4 * (ones (size (typearr))) .- typearr); + obj(fptr) = cellfun (@(x) x(2:end), obj(fptr), "Uniformoutput", false); + endif + clear fptr - for ii=1:ncols - for jj=1:nrows - try - # Set value - sh.getCell(jj+trow-2, ii+lcol-2).setVal (obj{jj, ii}); # Addr.cnt = 0-based - changed = 1; - catch - # Cell not existent. Add cell - if ~(typearr(jj, ii) == 5) - sh.add (obj{jj, ii}, jj+trow-2, ii+lcol-2); - changed = 1; - endif - end_try_catch - endfor - endfor + for ii=1:ncols + for jj=1:nrows + try + ## Set value + sh.getCell(jj+trow-2, ii+lcol-2).setVal (obj{jj, ii}); ## Addr.cnt = 0-based + changed = 1; + catch + ## Cell not existent. Add cell + if ~(typearr(jj, ii) == 5) + sh.add (obj{jj, ii}, jj+trow-2, ii+lcol-2); + changed = 1; + endif + end_try_catch + endfor + endfor - if (changed), xls.changed = max (xls.changed, 1); endif # Preserve 2 for new files - rstatus = 1; + if (changed), xls.changed = max (xls.changed, 1); endif ## Preserve 2 for new files + rstatus = 1; endfunction
--- a/main/io/inst/private/__OXS_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OXS_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -29,29 +29,34 @@ ## Updates: ## 2012-02-25 Changed ctype into num array rather than cell array ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ rawarr, xls, rstatus ] = __OXS_spsh2oct__ (xls, wsh, cellrange, spsh_opts) persistent ctype; if (isempty (ctype)) ctype = zeros (6, 1); - # Get enumerated cell types. Beware as they start at 0 not 1 - ctype( 1) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_STRING')); # 0 - ctype( 2) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FP')); # 1 - ctype( 3) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_INT')); # 2 - ctype( 4) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FORMULA')); # 3 - ctype( 5) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_BOOLEAN')); # 4 - ctype( 6) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_DOUBLE')); # 5 + ## Get enumerated cell types. Beware as they start at 0 not 1 + ctype( 1) = (java_get ("com.extentech.ExtenXLS.CellHandle", "TYPE_STRING")); ## 0 + ctype( 2) = (java_get ("com.extentech.ExtenXLS.CellHandle", "TYPE_FP")); ## 1 + ctype( 3) = (java_get ("com.extentech.ExtenXLS.CellHandle", "TYPE_INT")); ## 2 + ctype( 4) = (java_get ("com.extentech.ExtenXLS.CellHandle", "TYPE_FORMULA")); ## 3 + ctype( 5) = (java_get ("com.extentech.ExtenXLS.CellHandle", "TYPE_BOOLEAN")); ## 4 + ctype( 6) = (java_get ("com.extentech.ExtenXLS.CellHandle", "TYPE_DOUBLE")); ## 5 endif rstatus = 0; wb = xls.workbook; - # Check if requested worksheet exists in the file & if so, get pointer + ## Check if requested worksheet exists in the file & if so, get pointer nr_of_sheets = wb.getNumWorkSheets (); 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.getWorkSheet (wsh - 1); # OXS sheet count 0-based + 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.getWorkSheet (wsh - 1); ## OXS sheet count 0-based printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); else try @@ -62,12 +67,12 @@ end if (isempty (cellrange)) - # Get numeric sheet pointer (0-based) + ## Get numeric sheet pointer (0-based) wsh = sh.getTabIndex (); - # Get data rectangle row & column numbers (1-based) + ## Get data rectangle row & column numbers (1-based) [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh+1); if (firstrow == 0 && lastrow == 0) - # Empty sheet + ## Empty sheet rawarr = {}; printf ("Worksheet '%s' contains no data\n", shnames {wsh}); rstatus = 1; @@ -77,17 +82,17 @@ ncols = rcol - lcol + 1; endif else - # Translate range to row & column numbers (1-based) + ## Translate range to row & column numbers (1-based) [dummy, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); - # Check for too large requested range against actually present range + ## Check for too large requested range against actually present range lastrow = min (firstrow + nrows - 1, sh.getLastRow + 1 ()); nrows = min (nrows, sh.getLastRow () - firstrow + 1); ncols = min (ncols, sh.getLastCol () - lcol + 1); rcol = lcol + ncols - 1; endif - # Read contents into rawarr - rawarr = cell (nrows, ncols); # create placeholder + ## Read contents into rawarr + rawarr = cell (nrows, ncols); ## create placeholder for jj = lcol:rcol for ii = firstrow:lastrow try @@ -98,7 +103,7 @@ rawarr {ii+1-firstrow, jj+1-lcol} = scell.getDoubleVal (); endif catch - # Empty or non-existing cell + ## Empty or non-existing cell end_try_catch endfor endfor
--- a/main/io/inst/private/__OXS_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OXS_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,6 +18,8 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-24 Style fixes function [ xls ] = __OXS_spsh_close__ (xls) @@ -38,7 +40,7 @@ xlsout.close (); xls.changed = 0; catch -# xlsout.close (); +## xlsout.close (); end_try_catch else xls.workbook.close ();
--- a/main/io/inst/private/__OXS_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OXS_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,18 +20,20 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## 2012-10-24 Style fixes function [sh_names] = __OXS_spsh_info__ (xls) sh_cnt = xls.workbook.getNumWorkSheets (); sh_names = cell (sh_cnt, 2); nsrows = zeros (sh_cnt, 1); for ii=1:sh_cnt - sh = xls.workbook.getWorkSheet (ii-1); # OpenXLS starts counting at 0 + sh = xls.workbook.getWorkSheet (ii-1); ## OpenXLS starts counting at 0 sh_names(ii, 1) = char (sh.getSheetName()); - # OpenXLS doesn't distinguish between worksheets and graph sheets + ## OpenXLS doesn't distinguish between worksheets and graph sheets [tr, lr, lc, rc] = getusedrange (xls, ii); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = ... + sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); else sh_names(ii, 2) = "Empty or Chart"; endif
--- a/main/io/inst/private/__OXS_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__OXS_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2012 Philip +## Copyright (C) 2012 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 @@ -16,8 +16,10 @@ ## __OXS_xlsopen__ - inernal function for opening an xls file using Java / OpenXLS -## Author: Philip <Philip@DESKPRN> +## Author: Philip Nienhuis <prnienhuis at users.sf.net> ## Created: 2012-10-07 +## Updates: +## 2012-10-24 Style fixes function [ xls, xlssupport, lastintf ] = __OXS_spsh_open__ (xls, xwrite, filename, xlssupport, chk1) @@ -25,15 +27,15 @@ error ("OXS can only read from .xls files") endif try - wb = javaObject ('com.extentech.ExtenXLS.WorkBookHandle', filename); - xls.xtype = 'OXS'; - xls.app = 'void - OpenXLS'; + wb = javaObject ("com.extentech.ExtenXLS.WorkBookHandle", filename); + xls.xtype = "OXS"; + xls.app = "void - OpenXLS"; xls.workbook = wb; xls.filename = filename; xlssupport += 8; - lastintf = 'OXS'; + lastintf = "OXS"; catch - printf ('Unsupported file format for OpenXLS - %s\n'); + printf ("Unsupported file format for OpenXLS - %s\n"); end_try_catch endfunction
--- a/main/io/inst/private/__POI_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__POI_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -17,18 +17,21 @@ ## Author: Philip <Philip@DESKPRN> ## Created: 2010-03-20 +## Updates: ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ trow, brow, lcol, rcol ] = __POI_getusedrange__ (xls, ii) - persistent cblnk; cblnk = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); + persistent cblnk; + cblnk = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_BLANK"); - sh = xls.workbook.getSheetAt (ii-1); # Java POI starts counting at 0 + sh = xls.workbook.getSheetAt (ii-1); ## Java POI starts counting at 0 - trow = sh.getFirstRowNum (); # 0-based - brow = sh.getLastRowNum (); # 0-based - # Get column range - lcol = 1048577; # OOXML (xlsx) max. + 1 + trow = sh.getFirstRowNum (); ## 0-based + brow = sh.getLastRowNum (); ## 0-based + ## Get column range + lcol = 1048577; ## OOXML (xlsx) max. + 1 rcol = 0; botrow = brow; for jj=trow:brow @@ -38,17 +41,18 @@ lcol = min (lcol, scol); ecol = (irow.getLastCellNum).intValue () - 1; rcol = max (rcol, ecol); - # Keep track of lowermost non-empty row as getLastRowNum() is unreliable - if ~(irow.getCell(scol).getCellType () == cblnk && irow.getCell(ecol).getCellType () == cblnk) + ## Keep track of lowermost non-empty row as getLastRowNum() is unreliable + if ~(irow.getCell(scol).getCellType () == cblnk ... + && irow.getCell(ecol).getCellType () == cblnk) botrow = jj; endif endif endfor if (lcol > 1048576) - # Empty sheet + ## Empty sheet trow = 0; brow = 0; lcol = 0; rcol = 0; else - brow = min (brow, botrow) + 1; ++trow; ++lcol; ++rcol; # 1-based return values + brow = min (brow, botrow) + 1; ++trow; ++lcol; ++rcol; ## 1-based retvals endif endfunction
--- a/main/io/inst/private/__POI_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__POI_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -30,7 +30,7 @@ ## Example: ## ## @example -## [xlso, status] = __POI_oct2spsh__ ('arr', xlsi, 'Third_sheet', 'AA31'); +## [xlso, status] = __POI_oct2spsh__ ("arr", xlsi, "Third_sheet", "AA31"); ## @end example ## ## @seealso {oct2xls, xls2oct, xlsopen, xlsclose, xlsread, xlswrite} @@ -50,7 +50,7 @@ ## 2010-08-01 Added range vs. array size vs. capacity checks ## 2010-08-03 Moved range checks and type array parsingto separate functions ## 2010-10-21 Improved logic for tracking file changes -## 2010-10-27 File change tracking again refined, internal var 'changed' dropped +## 2010-10-27 File change tracking again refined, internal var "changed" dropped ## 2010-11-12 Moved ptr struct check into main func ## 2011-11-19 Try-catch added to allow for changed method name for nr of worksheets ## 2012-01-26 Fixed "seealso" help string @@ -58,110 +58,112 @@ ## 2012-05-21 "Double" cast added when writing numeric values ## 2012-05-21 "Double" cast moved into main func oct2xls ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ xls, rstatus ] = __POI_oct2spsh__ (obj, xls, wsh, crange, spsh_opts) - # Preliminary sanity checks - if (~strmatch (tolower (xls.filename(end-4:end)), '.xls')) - error ("POI interface can only write to Excel .xls or .xlsx files") - endif + ## Preliminary sanity checks + if (~strmatch (tolower (xls.filename(end-4:end)), ".xls")) + error ("POI interface can only write to Excel .xls or .xlsx files") + endif - persistent ctype; - if (isempty (ctype)) - # Get cell types. Beware as they start at 0 not 1 - ctype(1) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_NUMERIC'); # 0 - ctype(2) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BOOLEAN'); # 4 - ctype(3) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_STRING'); # 1 - ctype(4) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_FORMULA'); # 2 - ctype(5) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); # 3 - endif - # scratch vars - rstatus = 0; f_errs = 0; + persistent ctype; + if (isempty (ctype)) + ## Get cell types. Beware as they start at 0 not 1 + ctype(1) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_NUMERIC"); ## 0 + ctype(2) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_BOOLEAN"); ## 4 + ctype(3) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_STRING"); ## 1 + ctype(4) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_FORMULA"); ## 2 + ctype(5) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_BLANK"); ## 3 + endif + ## scratch vars + rstatus = 0; f_errs = 0; - # Check if requested worksheet exists in the file & if so, get pointer - try + ## Check if requested worksheet exists in the file & if so, get pointer + try nr_of_sheets = xls.workbook.getNumWorkSheets (); catch nr_of_sheets = xls.workbook.getNumberOfSheets (); end_try_catch - if (isnumeric (wsh)) - if (wsh > nr_of_sheets) - # Watch out as a sheet called Sheet%d can exist with a lower index... - strng = sprintf ("Sheet%d", wsh); - ii = 1; - while (~isempty (xls.workbook.getSheet (strng)) && (ii < 5)) - strng = ['_' strng]; - ++ii; - endwhile - if (ii >= 5) error (sprintf( " > 5 sheets named [_]Sheet%d already present!", wsh)); endif - sh = xls.workbook.createSheet (strng); - xls.changed = min (xls.changed, 2); # Keep 2 for new files - else - sh = xls.workbook.getSheetAt (wsh - 1); # POI sheet count 0-based - endif - printf ("(Writing to worksheet %s)\n", sh.getSheetName ()); - else - sh = xls.workbook.getSheet (wsh); - if (isempty (sh)) - # Sheet not found, just create it - sh = xls.workbook.createSheet (wsh); - xls.changed = min (xls.changed, 2); # Keep 2 or 3 f. new files - endif - endif - - # Parse date ranges - [nr, nc] = size (obj); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); - if (nrows < nr || ncols < nc) - warning ("Array truncated to fit in range"); - obj = obj(1:nrows, 1:ncols); - endif + if (isnumeric (wsh)) + if (wsh > nr_of_sheets) + ## Watch out as a sheet called Sheet%d can exist with a lower index... + strng = sprintf ("Sheet%d", wsh); + ii = 1; + while (~isempty (xls.workbook.getSheet (strng)) && (ii < 5)) + strng = ["_" strng]; + ++ii; + endwhile + if (ii >= 5) error (sprintf( " > 5 sheets named [_]Sheet%d already present!", wsh)); endif + sh = xls.workbook.createSheet (strng); + xls.changed = min (xls.changed, 2); ## Keep 2 for new files + else + sh = xls.workbook.getSheetAt (wsh - 1); ## POI sheet count 0-based + endif + printf ("(Writing to worksheet %s)\n", sh.getSheetName ()); + else + sh = xls.workbook.getSheet (wsh); + if (isempty (sh)) + ## Sheet not found, just create it + sh = xls.workbook.createSheet (wsh); + xls.changed = min (xls.changed, 2); ## Keep 2 or 3 f. new files + endif + endif - # Prepare type array - typearr = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts); - if ~(spsh_opts.formulas_as_text) - # Remove leading '=' from formula strings - # FIXME should be easier using typearr<4> info - fptr = ~(2 * (ones (size (typearr))) .- typearr); - obj(fptr) = cellfun (@(x) x(2:end), obj(fptr), "Uniformoutput", false); - endif + ## Parse date ranges + [nr, nc] = size (obj); + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); + if (nrows < nr || ncols < nc) + warning ("Array truncated to fit in range"); + obj = obj(1:nrows, 1:ncols); + endif - # Create formula evaluator - frm_eval = xls.workbook.getCreationHelper ().createFormulaEvaluator (); + ## Prepare type array + typearr = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts); + if ~(spsh_opts.formulas_as_text) + ## Remove leading "=" from formula strings + ## FIXME should be easier using typearr<4> info + fptr = ~(2 * (ones (size (typearr))) .- typearr); + obj(fptr) = cellfun (@(x) x(2:end), obj(fptr), "Uniformoutput", false); + endif + + ## Create formula evaluator + frm_eval = xls.workbook.getCreationHelper ().createFormulaEvaluator (); - for ii=1:nrows - ll = ii + trow - 2; # Java POI's row count = 0-based - row = sh.getRow (ll); - if (isempty (row)) row = sh.createRow (ll); endif - for jj=1:ncols - kk = jj + lcol - 2; # POI's column count is also 0-based - if (typearr(ii, jj) == ctype(5)) # Empty cells - cell = row.createCell (kk, ctype(5)); - elseif (typearr(ii, jj) == ctype(4)) # Formulas - # Try-catch needed as there's no guarantee for formula correctness - try - cell = row.createCell (kk, ctype(4)); - cell.setCellFormula (obj{ii,jj}); - catch - ++f_errs; - cell.setCellType (ctype (3)); # Enter formula as text - cell.setCellValue (obj{ii, jj}); - end_try_catch - else - cell = row.createCell (kk, typearr(ii,jj)); + for ii=1:nrows + ll = ii + trow - 2; ## Java POI's row count 0-based + row = sh.getRow (ll); + if (isempty (row)) row = sh.createRow (ll); endif + for jj=1:ncols + kk = jj + lcol - 2; ## POI's column count is 0-based + if (typearr(ii, jj) == ctype(5)) ## Empty cells + cell = row.createCell (kk, ctype(5)); + elseif (typearr(ii, jj) == ctype(4)) ## Formulas + ## Try-catch needed as there's no guarantee for formula correctness + try + cell = row.createCell (kk, ctype(4)); + cell.setCellFormula (obj{ii,jj}); + catch + ++f_errs; + cell.setCellType (ctype (3)); ## Enter formula as text + cell.setCellValue (obj{ii, jj}); + end_try_catch + else + cell = row.createCell (kk, typearr(ii,jj)); if (isnumeric (obj{ii, jj})) cell.setCellValue (obj{ii, jj}); else cell.setCellValue (obj{ii, jj}); endif - endif - endfor - endfor - - if (f_errs) - printf ("%d formula errors encountered - please check input array\n", f_errs); - endif - xls.changed = max (xls.changed, 1); # Preserve a "2" - rstatus = 1; + endif + endfor + endfor + + if (f_errs) + printf ("%d formula errors encountered - please check input array\n", f_errs); + endif + xls.changed = max (xls.changed, 1); ## Preserve a "2" + rstatus = 1; endfunction
--- a/main/io/inst/private/__POI_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__POI_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -49,47 +49,53 @@ ## of text sheet name arg ## 2012-01-26 Fixed "seealso" help string ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ rawarr, xls, rstatus ] = __POI_spsh2oct__ (xls, wsh, cellrange, spsh_opts) persistent ctype; if (isempty (ctype)) - # Get enumerated cell types. Beware as they start at 0 not 1 - ctype(1) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_NUMERIC'); - ctype(2) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_STRING'); - ctype(3) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_FORMULA'); - ctype(4) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); - ctype(5) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BOOLEAN'); - ctype(6) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_ERROR'); + ## Get enumerated cell types. Beware as they start at 0 not 1 + ctype(1) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_NUMERIC"); + ctype(2) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_STRING"); + ctype(3) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_FORMULA"); + ctype(4) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_BLANK"); + ctype(5) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_BOOLEAN"); + ctype(6) = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_ERROR"); endif rstatus = 0; jerror = 0; wb = xls.workbook; - # Check if requested worksheet exists in the file & if so, get pointer + ## Check if requested worksheet exists in the file & if so, get pointer nr_of_sheets = wb.getNumberOfSheets (); 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.getSheetAt (wsh - 1); # POI sheet count 0-based - # printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); + 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.getSheetAt (wsh - 1); ## POI sheet count 0-based +## printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); else sh = wb.getSheet (wsh); - if (isempty (sh)), error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); endif + if (isempty (sh)) + error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); + endif end - # Check ranges - firstrow = sh.getFirstRowNum (); # 0-based - lastrow = sh.getLastRowNum (); # 0-based + ## Check ranges + firstrow = sh.getFirstRowNum (); ## 0-based + lastrow = sh.getLastRowNum (); ## 0-based if (isempty (cellrange)) if (ischar (wsh)) - # get numeric sheet index + ## get numeric sheet index ii = wb.getSheetIndex (sh) + 1; else ii = wsh; endif [ firstrow, lastrow, lcol, rcol ] = getusedrange (xls, ii); if (firstrow == 0 && lastrow == 0) - # Empty sheet + ## Empty sheet rawarr = {}; printf ("Worksheet '%s' contains no data\n", sh.getSheetName ()); rstatus = 1; @@ -99,17 +105,17 @@ ncols = rcol - lcol + 1; endif else - # Translate range to HSSF POI row & column numbers + ## Translate range to HSSF POI row & column numbers [topleft, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); lastrow = firstrow + nrows - 1; rcol = lcol + ncols - 1; endif - # Create formula evaluator (needed to infer proper cell type into rawarr) + ## Create formula evaluator (needed to infer proper cell type into rawarr) frm_eval = wb.getCreationHelper().createFormulaEvaluator (); - # Read contents into rawarr - rawarr = cell (nrows, ncols); # create placeholder + ## Read contents into rawarr + rawarr = cell (nrows, ncols); ## create placeholder for ii = firstrow:lastrow irow = sh.getRow (ii-1); if ~isempty (irow) @@ -118,57 +124,64 @@ for jj = lcol:rcol scell = irow.getCell (jj-1); if ~isempty (scell) - # Explore cell contents + ## Explore cell contents type_of_cell = scell.getCellType (); - if (type_of_cell == ctype(3)) # Formula + if (type_of_cell == ctype(3)) ## Formula if ~(spsh_opts.formulas_as_text) - try # Because not al Excel formulas have been implemented in POI + 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 + ## Separate switch because form.eval. yields different type switch type_of_cell - case ctype (1) # Numeric + case ctype (1) ## Numeric rawarr {ii+1-firstrow, jj+1-lcol} = cvalue.getNumberValue (); - case ctype(2) # String - rawarr {ii+1-firstrow, jj+1-lcol} = char (cvalue.getStringValue ()); - case ctype (5) # Boolean + case ctype(2) ## String + rawarr {ii+1-firstrow, jj+1-lcol} = ... + char (cvalue.getStringValue ()); + case ctype (5) ## Boolean rawarr {ii+1-firstrow, jj+1-lcol} = cvalue.BooleanValue (); otherwise - # Nothing to do here + ## Nothing to do here endswitch - # Set cell type to blank to skip switch below + ## Set cell type to blank to skip switch below type_of_cell = ctype(4); catch - # In case of formula errors we take the cached results + ## In case of formula errors we take the cached results type_of_cell = scell.getCachedFormulaResultType (); - ++jerror; # We only need one warning even for multiple errors + ## We only need one warning even for multiple errors + ++jerror; end_try_catch endif endif - # Preparations done, get data values into data array + ## Preparations done, get data values into data array switch type_of_cell - case ctype(1) # 0 Numeric + case ctype(1) ## 0 Numeric rawarr {ii+1-firstrow, jj+1-lcol} = scell.getNumericCellValue (); - case ctype(2) # 1 String - rawarr {ii+1-firstrow, jj+1-lcol} = char (scell.getRichStringCellValue ()); + case ctype(2) ## 1 String + rawarr {ii+1-firstrow, jj+1-lcol} = ... + char (scell.getRichStringCellValue ()); case ctype(3) if (spsh_opts.formulas_as_text) tmp = char (scell.getCellFormula ()); - rawarr {ii+1-firstrow, jj+1-lcol} = ['=' tmp]; + rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; endif - case ctype(4) # 3 Blank - # Blank; ignore until further notice - case ctype(5) # 4 Boolean + case ctype(4) ## 3 Blank + ## Blank; ignore until further notice + case ctype(5) ## 4 Boolean rawarr {ii+1-firstrow, jj+1-lcol} = scell.getBooleanCellValue (); - otherwise # 5 Error - # Ignore + otherwise ## 5 Error + ## Ignore endswitch endif endfor endif endfor - if (jerror > 0) warning (sprintf ("%d cached values instead of formula evaluations read.\n", jerror)); endif + if (jerror > 0) + warning (sprintf ("%d cached values instead of formula evaluations read.\n",... + jerror)); + endif rstatus = 1; xls.limits = [lcol, rcol; firstrow, lastrow];
--- a/main/io/inst/private/__POI_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__POI_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,6 +18,8 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-24 Style fixes function [ xls ] = __POI_spsh_close__ (xls) @@ -30,14 +32,14 @@ try xlsout = java_new ("java.io.FileOutputStream", fname); bufout = java_new ("java.io.BufferedOutputStream", xlsout); -# if (xls.changed == 2) printf ("Saving file %s...\n", fname); endif +## if (xls.changed == 2); printf ("Saving file %s...\n", fname); endif xls.workbook.write (bufout); bufout.flush (); bufout.close (); xlsout.close (); xls.changed = 0; catch -# xlsout.close (); +## xlsout.close (); end_try_catch endif
--- a/main/io/inst/private/__POI_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__POI_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,19 +20,21 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## 2012-10-24 Style fixes function [sh_names] = __POI_spsh_info__ (xls) - persistent cblnk; cblnk = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); + persistent cblnk; cblnk = java_get ("org.apache.poi.ss.usermodel.Cell", "CELL_TYPE_BLANK"); sh_cnt = xls.workbook.getNumberOfSheets(); sh_names = cell (sh_cnt, 2); nsrows = zeros (sh_cnt, 1); for ii=1:sh_cnt sh = xls.workbook.getSheetAt (ii-1); # Java POI starts counting at 0 sh_names(ii, 1) = char (sh.getSheetName()); - # Java POI doesn't distinguish between worksheets and graph sheets + ## Java POI doesn't distinguish between worksheets and graph sheets [tr, lr, lc, rc] = getusedrange (xls, ii); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = ... + sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); else sh_names(ii, 2) = "Empty"; endif
--- a/main/io/inst/private/__POI_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__POI_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -25,35 +25,36 @@ ## 2010-09-27 Improved POI help message for unrecognized .xls format to hint for BIFF5/JXL ## 2010-11-08 Tested with POI 3.7 (OK) ## 2012-06-07 Fixed mixed-up lastintf assignments for POI and JXL +## 2012-10-24 Style fixes; added UNO to fall-back for BIFF5 formats function [ xls, xlssupport, lastintf ] = __POI_spsh_open__ (xls, xwrite, filename, xlssupport, chk1, chk2, xlsinterfaces) - if ~(chk1 || chk2) - error ("Unsupported file format for Apache POI.") - endif - # Get handle to workbook + ## Get handle to workbook try if (xwrite > 2) if (chk1) - wb = java_new ('org.apache.poi.hssf.usermodel.HSSFWorkbook'); + wb = java_new ("org.apache.poi.hssf.usermodel.HSSFWorkbook"); elseif (chk2) - wb = java_new ('org.apache.poi.xssf.usermodel.XSSFWorkbook'); + wb = java_new ("org.apache.poi.xssf.usermodel.XSSFWorkbook"); endif - xls.app = 'new_POI'; + xls.app = "new_POI"; else - xlsin = java_new ('java.io.FileInputStream', filename); - wb = java_invoke ('org.apache.poi.ss.usermodel.WorkbookFactory', 'create', xlsin); + xlsin = java_new ("java.io.FileInputStream", filename); + wb = java_invoke ("org.apache.poi.ss.usermodel.WorkbookFactory",... + "create", xlsin); xls.app = xlsin; endif - xls.xtype = 'POI'; + xls.xtype = "POI"; xls.workbook = wb; xls.filename = filename; xlssupport += 2; - lastintf = 'POI'; + lastintf = "POI"; catch clear xlsin; - if (xlsinterfaces.JXL) - printf ('Couldn''t open file %s using POI; trying Excel''95 format with JXL...\n', filename); + if (chk1 && (xlsinterfaces.JXL || xlsinterfaces.UNO)) + printf ... + (["Couldn't open file %s using POI;\n" ... + "trying Excel'95 format with JXL or UNO...\n"], filename); endif end_try_catch
--- a/main/io/inst/private/__UNO_getusedrange__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__UNO_getusedrange__.m Wed Oct 24 21:43:38 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2011,2012 Philip Nienhuis +## Copyright (C) 2011,2012 Philip Nienhuis <prnienhuis@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 @@ -18,54 +18,56 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2011-05-06 ## Updates: -## 2011-06-29 Fixed wrong address range inference in case of sheet names containing period(s) -## 2012-03-02 Adapted code to assess nr of range blocks to ';' separator fo LO3.5+ +## 2011-06-29 Fixed wrong address range inference in case of sheet names +## containing period(s) +## 2012-03-02 Adapted code to assess nr of range blocks to ';' separator for LO3.5+ ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ srow, erow, scol, ecol ] = __UNO_getusedrange__ (ods, ii) # Get desired sheet sheets = ods.workbook.getSheets (); sh_names = sheets.getElementNames (); - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheet'); - sh = sheets.getByName(sh_names(ii)).getObject.queryInterface (unotmp); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XSpreadsheet"); + sh = sheets.getByName (sh_names(ii)).getObject.queryInterface (unotmp); - # Prepare cell range query - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XCellRangesQuery'); + ## Prepare cell range query + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XCellRangesQuery"); xRQ = sh.queryInterface (unotmp); Cellflgs = javaObject ("java.lang.Short", "23"); ccells = xRQ.queryContentCells (Cellflgs); - # Get addresses of all blocks containing data + ## Get addresses of all blocks containing data addrs = ccells.getRangeAddressesAsString (); - # Strip sheet name from addresses. Watch out, in LO3.5 they changed - # the separator from ',' to ';' (without telling me!) - # 1. Get nr of range blocks + ## Strip sheet name from addresses. Watch out, in LO3.5 they changed + ## the separator from ',' to ';' (without telling me 8-Z) + ## 1. Get nr of range blocks nblks = numel (strfind (addrs, sh_names(ii))); - # 2. First try with ',' separator... - adrblks = strsplit (addrs, ','); + ## 2. First try with "," separator... + adrblks = strsplit (addrs, ","); if (numel (adrblks) < nblks) - # Apparently we have a ';' separator, so try with semicolon - adrblks = strsplit (addrs, ';'); + ## Apparently we have a ';' separator, so try with semicolon + adrblks = strsplit (addrs, ";"); endif if (isempty (adrblks)) srow = erow = scol = ecol = 0; return endif - # Find leftmost & rightmost columns, and highest and lowest row with data + ## Find leftmost & rightmost columns, and highest and lowest row with data srow = scol = 1e10; erow = ecol = 0; for ii=1:numel (adrblks) - # Check if address contains a sheet name in quotes (happens if name contains a period) + ## Check if address contains a sheet name in quotes (happens if name contains a period) if (int8 (adrblks{ii}(1)) == 39) - # Strip sheet name part + ## Strip sheet name part idx = findstr (adrblks{ii}, "'."); range = adrblks{ii}(idx+2 : end); else - # Same, but tru strsplit() - range = strsplit (adrblks{ii}, '.'){2}; + ## Same, but tru strsplit() + range = strsplit (adrblks{ii}, "."){2}; endif [dummy, nrows, ncols, trow, lcol] = parse_sp_range (range); brow = trow + nrows - 1;
--- a/main/io/inst/private/__UNO_oct2spsh__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__UNO_oct2spsh__.m Wed Oct 24 21:43:38 2012 +0000 @@ -26,54 +26,55 @@ ## 2012-05-21 "Double" cast added when writing numeric values ## 2012-05-21 "Double" cast moved into main func oct2xls ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [ xls, rstatus ] = __UNO_oct2spsh__ (c_arr, xls, wsh, crange, spsh_opts) changed = 0; newsh = 0; - ctype = [1, 2, 3, 4, 5]; # Float, Logical, String, Formula, Empty + ctype = [1, 2, 3, 4, 5]; ## Float, Logical, String, Formula, Empty - # Get handle to sheet, create a new one if needed + ## Get handle to sheet, create a new one if needed sheets = xls.workbook.getSheets (); sh_names = sheets.getElementNames (); if (! iscell (sh_names)) - # Java array (LibreOffice 3.4.+); convert to cellstr + ## Java array (LibreOffice 3.4.+); convert to cellstr sh_names = char (sh_names); else sh_names = {sh_names}; endif - # Clear default 2 last sheets in case of a new spreadsheet file + ## Clear default 2 last sheets in case of a new spreadsheet file if (xls.changed > 2) ii = numel (sh_names); while (ii > 1) shnm = sh_names{ii}; try - # Catch harmless Java RuntimeException "out of range" in LibreOffice 3.5rc1 + ## Catch harmless Java RuntimeException "out of range" in LibreOffice 3.5rc1 sheets.removeByName (shnm); end_try_catch --ii; endwhile - # Give remaining sheet a name - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheet'); + ## Give remaining sheet a name + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XSpreadsheet"); sh = sheets.getByName (sh_names{1}).getObject.queryInterface (unotmp); if (isnumeric (wsh)); wsh = sprintf ("Sheet%d", wsh); endif - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.container.XNamed'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.container.XNamed"); sh.queryInterface (unotmp).setName (wsh); else - # Check sheet pointer - # FIXME sheet capacity check needed + ## Check sheet pointer + ## FIXME sheet capacity check needed if (isnumeric (wsh)) if (wsh < 1) error ("Illegal sheet index: %d", wsh); elseif (wsh > numel (sh_names)) - # New sheet to be added. First create sheet name but check if it already exists + ## New sheet to be added. First create sheet name but check if it already exists shname = sprintf ("Sheet%d", numel (sh_names) + 1); jj = strmatch (wsh, sh_names); if (~isempty (jj)) - # New sheet name already in file, try to create a unique & reasonable one - ii = 1; filler = ''; maxtry = 5; + ## New sheet name already in file, try to create a unique & reasonable one + ii = 1; filler = ""; maxtry = 5; while (ii <= maxtry) shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); if (isempty (strmatch (wsh, sh_names))) @@ -89,75 +90,78 @@ wsh = shname; newsh = 1; else - # turn wsh index into the associated sheet name + ## turn wsh index into the associated sheet name wsh = sh_names (wsh); endif else - # wsh is a sheet name. See if it exists already + ## wsh is a sheet name. See if it exists already if (isempty (strmatch (wsh, sh_names))) - # Not found. New sheet to be added + ## Not found. New sheet to be added newsh = 1; endif endif if (newsh) - # Add a new sheet. Sheet index MUST be a Java Short object + ## Add a new sheet. Sheet index MUST be a Java Short object shptr = java_new ("java.lang.Short", sprintf ("%d", numel (sh_names) + 1)); sh = sheets.insertNewByName (wsh, shptr); endif - # At this point we have a valid sheet name. Use it to get a sheet handle - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheet'); + ## At this point we have a valid sheet name. Use it to get a sheet handle + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XSpreadsheet"); sh = sheets.getByName (wsh).getObject.queryInterface (unotmp); endif - # Check size of data array & range / capacity of worksheet & prepare vars + ## Check size of data array & range / capacity of worksheet & prepare vars [nr, nc] = size (c_arr); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); - --trow; --lcol; # Zero-based row # & col # + [topleft, nrows, ncols, trow, lcol] = ... + spsh_chkrange (crange, nr, nc, xls.xtype, xls.filename); + --trow; --lcol; ## Zero-based row ## & col ## if (nrows < nr || ncols < nc) warning ("Array truncated to fit in range"); c_arr = c_arr(1:nrows, 1:ncols); endif - # Parse data array, setup typarr and throw out NaNs to speed up writing; + ## Parse data array, setup typarr and throw out NaNs to speed up writing; typearr = spsh_prstype (c_arr, nrows, ncols, ctype, spsh_opts, 0); if ~(spsh_opts.formulas_as_text) - # Find formulas (designated by a string starting with "=" and ending in ")") + ## Find formulas (designated by a string starting with "=" and ending in ")") fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1), c_arr); - typearr(fptr) = ctype(4); # FORMULA + typearr(fptr) = ctype(4); ## FORMULA endif - # Transfer data to sheet + ## Transfer data to sheet for ii=1:nrows for jj=1:ncols try XCell = sh.getCellByPosition (lcol+jj-1, trow+ii-1); switch typearr(ii, jj) - case 1 # Float + case 1 ## Float XCell.setValue (c_arr{ii, jj}); - case 2 # Logical. Convert to float as OOo has no Boolean type + 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'); + case 3 ## String + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.text.XText"); XCell.queryInterface (unotmp).setString (c_arr{ii, jj}); - case 4 # Formula + case 4 ## Formula if (spsh_opts.formulas_as_text) - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.text.XText"); XCell.queryInterface (unotmp).setString (c_arr{ii, jj}); else XCell.setFormula (c_arr{ii, jj}); endif otherwise - # Empty cell + ## Empty cell endswitch changed = 1; catch - printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); + printf ("Error writing cell %s (typearr() = %d)\n",... + calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); end_try_catch endfor endfor if (changed) - xls.changed = max (min (xls.changed, 2), changed); # Preserve 2 (new file), 1 (existing) + ## Preserve 2 (new file), 1 (existing) + xls.changed = max (min (xls.changed, 2), changed); rstatus = 1; endif
--- a/main/io/inst/private/__UNO_spsh2oct__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__UNO_spsh2oct__.m Wed Oct 24 21:43:38 2012 +0000 @@ -21,19 +21,20 @@ ## 2011-09-18 Adapted sh_names type to LO 3.4.1 ## 2011-09-19 Try to decipher if formulas return numeric or string values ## 2012-10-12 Renamed & moved into ./private +## 2012-10-24 Style fixes function [rawarr, xls, rstatus] = __UNO_spsh2oct__ (xls, wsh, datrange, spsh_opts) sheets = xls.workbook.getSheets (); sh_names = sheets.getElementNames (); if (! iscell (sh_names)) - # Java array (LibreOffice 3.4.+); convert to cellstr + ## Java array (LibreOffice 3.4.+), convert to cellstr sh_names = char (sh_names); else sh_names = {sh_names}; endif - # Check sheet pointer + ## Check sheet pointer if (isnumeric (wsh)) if (wsh < 1 || wsh > numel (sh_names)) error ("Sheet index %d out of range 1-%d", wsh, numel (sh_names)); @@ -43,77 +44,77 @@ if (isempty (ii)), error ("Sheet '%s' not found", wsh); endif wsh = ii; endif - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheet'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XSpreadsheet"); sh = sheets.getByName(sh_names{wsh}).getObject.queryInterface (unotmp); - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XCellRangesQuery'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XCellRangesQuery"); xRQ = sh.queryInterface (unotmp); - # Get cell ranges of all rectangles containing data. Type values: - #java_get ('com.sun.star.sheet.CellFlags', 'VALUE') ans = 1 - #java_get ('com.sun.star.sheet.CellFlags', 'DATETIME') ans = 2 - #java_get ('com.sun.star.sheet.CellFlags', 'STRING') ans = 4 - #java_get ('com.sun.star.sheet.CellFlags', 'FORMULA') ans = 16 - # Yep, boolean is lacking... + ## Get cell ranges of all rectangles containing data. Type values: + ##java_get ("com.sun.star.sheet.CellFlags", "VALUE") ans = 1 + ##java_get ("com.sun.star.sheet.CellFlags", "DATETIME") ans = 2 + ##java_get ("com.sun.star.sheet.CellFlags", "STRING") ans = 4 + ##java_get ("com.sun.star.sheet.CellFlags", "FORMULA") ans = 16 + ## Yep, boolean is lacking... Cellflgs = javaObject ("java.lang.Short", "23"); ccells = xRQ.queryContentCells (Cellflgs); addrs = ccells.getRangeAddressesAsString (); - # Strip sheet name from addresses - adrblks = strsplit (addrs, ','); + ## Strip sheet name from addresses + adrblks = strsplit (addrs, ","); if (isempty (adrblks)) - warning ('Sheet %s contains no data', sh_names{wsh}); + warning ("Sheet %s contains no data", sh_names{wsh}); return endif - # Either parse (given cell range) or prepare (unknown range) help variables. - # As OpenOffice knows the occupied range, we need the limits anyway to avoid - # out-of-range errors + ## Either parse (given cell range) or prepare (unknown range) help variables. + ## As OpenOffice knows the occupied range, we need the limits anyway to avoid + ## out-of-range errors [ trow, brow, lcol, rcol ] = getusedrange (xls, wsh); if (isempty (datrange)) - nrows = brow - trow + 1; # Number of rows to be read - ncols = rcol - lcol + 1; # Number of columns to be read + nrows = brow - trow + 1; ## Number of rows to be read + ncols = rcol - lcol + 1; ## Number of columns to be read else [dummy, nrows, ncols, srow, scol] = parse_sp_range (datrange); - # Truncate range silently if needed + ## Truncate range silently if needed brow = min (srow + nrows - 1, brow); rcol = min (scol + ncols - 1, rcol); trow = max (trow, srow); lcol = max (lcol, scol); - nrows = min (brow - trow + 1, nrows); # Number of rows to be read - ncols = min (rcol - lcol + 1, ncols); # Number of columns to be read + nrows = min (brow - trow + 1, nrows); ## Number of rows to be read + ncols = min (rcol - lcol + 1, ncols); ## Number of columns to be read endif - # Create storage for data at Octave side + ## Create storage for data at Octave side rawarr = cell (nrows, ncols); - # Get data. Apparently row & column indices are 0-based in UNO + ## Get data. Apparently row & column indices are 0-based in UNO for ii=trow-1:brow-1 for jj=lcol-1:rcol-1 XCell = sh.getCellByPosition (jj, ii); - cType = XCell.getType().getValue (); + cType = XCell.getType ().getValue (); switch cType - case 1 # Value + case 1 ## Value rawarr{ii-trow+2, jj-lcol+2} = XCell.getValue (); - case 2 # String - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); + case 2 ## String + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.text.XText"); rawarr{ii-trow+2, jj-lcol+2} = XCell.queryInterface (unotmp).getString (); - case 3 # Formula + case 3 ## Formula if (spsh_opts.formulas_as_text) rawarr{ii-trow+2, jj-lcol+2} = XCell.getFormula (); else - # Unfortunately OOo gives no clue as to the type of formula result - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); + ## Unfortunately OOo gives no clue as to the type of formula result + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.text.XText"); rawarr{ii-trow+2, jj-lcol+2} = XCell.queryInterface (unotmp).getString (); tmp = str2double (rawarr{ii-trow+2, jj-lcol+2}); - # If the string happens to contain just a number we'll assume it is numeric + ## If the string happens to contain just a number we'll assume it is numeric if (~isnan (tmp)); rawarr{ii-trow+2, jj-lcol+2} = tmp; endif endif otherwise - # Empty cell + ## Empty cell endswitch endfor endfor - # Keep track of data rectangle limits + ## Keep track of data rectangle limits xls.limits = [lcol, rcol; trow, brow]; rstatus = ~isempty (rawarr);
--- a/main/io/inst/private/__UNO_spsh_close__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__UNO_spsh_close__.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,30 +18,34 @@ ## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-12 +## Updates: +## 2012-10-23 Style fixes function [ xls ] = __UNO_spsh_close__ (xls, force) if (isfield (xls, "nfilename")) - # New filename specified + ## New filename specified if (strcmp (xls.xtype, 'UNO')) - # For UNO, turn filename into URL - if (~isempty (strmatch ("file:///", nfilename)) || ~isempty (strmatch ("http://", nfilename))... - || ~isempty (strmatch ("ftp://", nfilename)) || ~isempty (strmatch ("www://", nfilename))) - # Seems in proper shape for OOo (at first sight) + ## For UNO, turn filename into URL + if (~isempty (strmatch ("file:///", nfilename))... + || ~isempty (strmatch ("http://", nfilename))... + || ~isempty (strmatch ("ftp://", nfilename))... + || ~isempty (strmatch ("www://", nfilename))) + ## Seems in proper shape for OOo (at first sight) else - # Transform into URL form + ## Transform into URL form if (ispc) fname = canonicalize_file_name (strsplit (nfilename, filesep){end}); else fname = make_absolute_filename (strsplit (nfilename, filesep){end}); endif - # On Windows, change backslash file separator into forward slash + ## On Windows, change backslash file separator into forward slash if (strcmp (filesep, "\\")) tmp = strsplit (fname, filesep); flen = numel (tmp); tmp(2:2:2*flen) = tmp; - tmp(1:2:2*flen) = '/'; - nfilename = [ 'file://' tmp{:} ]; + tmp(1:2:2*flen) = "/"; + nfilename = [ "file://" tmp{:} ]; endif endif endif @@ -49,22 +53,24 @@ try if (xls.changed && xls.changed < 3) - # Workaround: - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XModel'); + ## Workaround: + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.frame.XModel"); xModel = xls.workbook.queryInterface (unotmp); - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.util.XModifiable'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.util.XModifiable"); xModified = xModel.queryInterface (unotmp); if (xModified.isModified ()) - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XStorable'); # isReadonly() ? + unotmp = ... + java_new ("com.sun.star.uno.Type", "com.sun.star.frame.XStorable"); # isReadonly() ? xStore = xls.app.xComp.queryInterface (unotmp); if (xls.changed == 2) - # Some trickery as Octave Java cannot create non-numeric arrays - lProps = javaArray ('com.sun.star.beans.PropertyValue', 1); - lProp = java_new ('com.sun.star.beans.PropertyValue', "Overwrite", 0, true, []); + ## Some trickery as Octave Java cannot create non-numeric arrays + lProps = javaArray ("com.sun.star.beans.PropertyValue", 1); + lProp = ... + java_new ("com.sun.star.beans.PropertyValue", "Overwrite", 0, true, []); lProps(1) = lProp; - # OK, store file + ## OK, store file if (isfield (xls, "nfilename")) - # Store in another file + ## Store in another file ## FIXME check if we need to close the old file xStore.storeAsURL (xls.nfilename, lProps); else @@ -75,21 +81,21 @@ endif endif endif - xls.changed = -1; # Needed for check on properly shutting down OOo - # Workaround: - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XModel'); + xls.changed = -1; ## Needed for check on properly shutting down OOo + ## Workaround: + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.frame.XModel"); xModel = xls.app.xComp.queryInterface (unotmp); - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.util.XCloseable'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.util.XCloseable"); xClosbl = xModel.queryInterface (unotmp); xClosbl.close (true); - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XDesktop'); + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.frame.XDesktop"); xDesk = xls.app.aLoader.queryInterface (unotmp); xDesk.terminate(); xls.changed = 0; catch if (force) - # Force closing OOo - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XDesktop'); + ## Force closing OOo + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.frame.XDesktop"); xDesk = xls.app.aLoader.queryInterface (unotmp); xDesk.terminate(); else
--- a/main/io/inst/private/__UNO_spsh_info__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__UNO_spsh_info__.m Wed Oct 24 21:43:38 2012 +0000 @@ -20,18 +20,20 @@ ## Created: 2012-10-12 ## Updates: ## 2012-10-12 Moved into ./private +## 2012-10-24 Style fixes function [sh_names] = __UNO_spsh_info__ (xls) sheets = xls.workbook.getSheets (); - sheetnames = sheets.getElementNames (); # A Java object, NOT a cell array + sheetnames = sheets.getElementNames (); ## A Java object, NOT a cell array sh_cnt = numel (sheetnames); sh_names = cell (sh_cnt, 2); for ii=1:sh_cnt sh_names(ii, 1) = sheetnames(ii); [ tr, lr, lc, rc ] = getusedrange (xls, ii); if (tr) - sh_names(ii, 2) = sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); + sh_names(ii, 2) = ... + sprintf ("%s:%s", calccelladdress (tr, lc), calccelladdress (lr, rc)); else sh_names(ii, 2) = "Empty or Chart"; endif
--- a/main/io/inst/private/__UNO_spsh_open__.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/__UNO_spsh_open__.m Wed Oct 24 21:43:38 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2012 Philip +## Copyright (C) 2012 Philip Nienhuis <prnienhuis@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 @@ -16,22 +16,23 @@ ## __UNO_xlsopen__ - Internal function for opening a spreadsheet file using Java / OOo/LO UNO -## Author: Philip <Philip@DESKPRN> +## Author: Philip Nienhuis <prnienhuis@users.sf.net> ## Created: 2012-10-07 ## Updates (possibly from xlsopen): ## 2011-05-18 Experimental UNO support added, incl. creating new spreadsheets ## 2012-09-02 (in UNO section) web adresses need only two consecutive slashes ## 2012-09-03 (in UNO section) replace canonicalize_file_name on non-Windows to ## make_absolute_filename (see bug #36677) +## 2012-10-24 Style fixes function [ xls, xlssupport, lastintf ] = __UNO_spsh_open__ (xls, xwrite, filename, xlssupport) - # First, the file name must be transformed into a URL + ## First, the file name must be transformed into a URL if (~isempty (strmatch ("file:///", filename)) || ~isempty (strmatch ("http://", filename))... - || ~isempty (strmatch ("ftp://", filename)) || ~isempty (strmatch ("www://", filename))) - # Seems in proper shape for OOo (at first sight) + || ~isempty (strmatch ("ftp://", filename)) || ~isempty (strmatch ("www://", filename))) + ## Seems in proper shape for OOo (at first sight) else - # Transform into URL form. + ## Transform into URL form. ## FIXME make_absolute_filename() doesn't work across drive(-letters) so ## until it is fixed we'll fall back on canonicalize_file_name() there if (ispc) @@ -39,7 +40,7 @@ else fname = make_absolute_filename (strsplit (filename, filesep){end}); endif - # On Windows, change backslash file separator into forward slash + ## On Windows, change backslash file separator into forward slash if (strcmp (filesep, "\\")) tmp = strsplit (fname, filesep); flen = numel (tmp); @@ -47,38 +48,38 @@ tmp(1:2:2*flen) = '/'; fname = [ tmp{:} ]; endif - filename = [ 'file://' fname ]; + filename = [ "file://" fname ]; endif try xContext = java_invoke ("com.sun.star.comp.helper.Bootstrap", "bootstrap"); xMCF = xContext.getServiceManager (); oDesktop = xMCF.createInstanceWithContext ("com.sun.star.frame.Desktop", xContext); - # Workaround for <UNOruntime>.queryInterface(): - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XComponentLoader'); + ## Workaround for <UNOruntime>.queryInterface(): + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.frame.XComponentLoader"); aLoader = oDesktop.queryInterface (unotmp); - # Some trickery as Octave Java cannot create initialized arrays - lProps = javaArray ('com.sun.star.beans.PropertyValue', 1); - lProp = java_new ('com.sun.star.beans.PropertyValue', "Hidden", 0, true, []); + ## Some trickery as Octave Java cannot create initialized arrays + lProps = javaArray ("com.sun.star.beans.PropertyValue", 1); + lProp = java_new ("com.sun.star.beans.PropertyValue", "Hidden", 0, true, []); lProps(1) = lProp; if (xwrite > 2) xComp = aLoader.loadComponentFromURL ("private:factory/scalc", "_blank", 0, lProps); else xComp = aLoader.loadComponentFromURL (filename, "_blank", 0, lProps); endif - # Workaround for <UNOruntime>.queryInterface(): - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheetDocument'); + ## Workaround for <UNOruntime>.queryInterface(): + unotmp = java_new ("com.sun.star.uno.Type", "com.sun.star.sheet.XSpreadsheetDocument"); xSpdoc = xComp.queryInterface (unotmp); - # save in ods struct: - xls.xtype = 'UNO'; - xls.workbook = xSpdoc; # Needed to be able to close soffice in odsclose() + ## save in ods struct: + xls.xtype = "UNO"; + xls.workbook = xSpdoc; ## Needed to be able to close soffice in odsclose() xls.filename = filename; - xls.app.xComp = xComp; # Needed to be able to close soffice in odsclose() - xls.app.aLoader = aLoader; # Needed to be able to close soffice in odsclose() - xls.odfvsn = 'UNO'; + xls.app.xComp = xComp; ## Needed to be able to close soffice in odsclose() + xls.app.aLoader = aLoader;## Needed to be able to close soffice in odsclose() + xls.odfvsn = "UNO"; xlssupport += 16; - lastintf = 'UNO'; + lastintf = "UNO"; catch - error ('Couldn''t open file %s using UNO', filename); + error ("Couldn't open file %s using UNO", filename); end_try_catch endfunction
--- a/main/io/inst/private/chk_jar_entries.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/chk_jar_entries.m Wed Oct 24 21:43:38 2012 +0000 @@ -18,6 +18,8 @@ ## Author: Philip <Philip@DESKPRN> ## Created: 2012-10-07 +## Updates: +## 2012-10-23 Style fixes function [ retval, missing ] = chk_jar_entries (jcp, entries, dbug=0) @@ -32,13 +34,13 @@ ++retval; found = 1; if (dbug > 2) - fprintf (' - %s OK\n', jentry); + fprintf (" - %s OK\n", jentry); endif endif endfor if (~found) if (dbug > 2) - printf (' %s....jar missing\n', entries{jj}); + printf (" %s....jar missing\n", entries{jj}); endif missing(jj) = 1; endif
--- a/main/io/inst/private/getodsinterfaces.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/getodsinterfaces.m Wed Oct 24 21:43:38 2012 +0000 @@ -65,19 +65,22 @@ ## 2012-06-08 Support for odfdom-0.8.8 (-incubator) ## 2012-10-07 Moved common classpath entry code to ./private function ## 2012-10-07 Moved into ./private +## 2012-10-24 Style fixes function [odsinterfaces] = getodsinterfaces (odsinterfaces) - # 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 persistent uno_1st_time = 0; - if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) - # Assume no interface detection has happened yet + if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) ... + && isempty (odsinterfaces.UNO)) + ## Assume no interface detection has happened yet printf ("Detected ODS interfaces: "); tmp1 = []; - elseif (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) || isempty (odsinterfaces.UNO)) - # Can't be first call. Here one of the Java interfaces is requested + elseif (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) ... + || isempty (odsinterfaces.UNO)) + ## Can't be first call. Here one of the Java interfaces is requested if (~tmp1) # Check Java support again tmp1 = []; @@ -86,29 +89,35 @@ deflt = 0; if (isempty (tmp1)) - # Check Java support + ## Check Java support try jcp = javaclasspath ("-all"); # For java pkg >= 1.2.8 if (isempty (jcp)), jcp = javaclasspath; endif # For java pkg < 1.2.8 - # If we get here, at least Java works. Now check for proper version (>= 1.6) - 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"); + ## If we get here, at least Java works. Now check for proper version (>= 1.6) + 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"); return endif - # Now check for proper entries in class path. Under *nix the classpath - # must first be split up. In java 1.2.8+ javaclasspath is already a cell array - if (isunix && ~iscell (jcp)), jcp = strsplit (char (jcp), pathsep ()); endif + ## Now check for proper entries in class path. Under *nix the classpath + ## must first be split up. In java 1.2.8+ javaclasspath is already a cell array + if (isunix && ~iscell (jcp)); + jcp = strsplit (char (jcp), pathsep ()); + endif tmp1 = 1; catch - # No Java support + ## No Java support tmp1 = 0; - if (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) || isempty (odsinterfaces.UNO)) - # Some or all Java-based interface explicitly requested; but no Java support - warning (' No Java support found (no Java JRE? no Java pkg installed AND loaded?'); + if (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) ... + || isempty (odsinterfaces.UNO)) + ## Some or all Java-based interface explicitly requested; but no Java support + warning ... + (" No Java support found (no Java JRE? no Java pkg installed AND loaded?"); endif - # No specific Java-based interface requested. Just return + ## No specific Java-based interface requested. Just return odsinterfaces.OTK = 0; odsinterfaces.JOD = 0; odsinterfaces.UNO = 0; @@ -117,31 +126,34 @@ end_try_catch endif - # Try Java & ODF toolkit + ## Try Java & ODF toolkit if (isempty (odsinterfaces.OTK)) odsinterfaces.OTK = 0; entries = {"odfdom", "xercesImpl"}; - # Only under *nix we might use brute force: e.g., strfind(classpath, classname); - # under Windows we need the following more subtle, platform-independent approach: + ## Only under *nix we might use brute force: e.g., strfind(classpath, classname); + ## under Windows we need the following more subtle, platform-independent approach: if (chk_jar_entries (jcp, entries) >= numel (entries)) - # Apparently all requested classes present. - # Only now we can check for proper odfdom version (only 0.7.5 & 0.8.6 work OK). - # The odfdom team deemed it necessary to change the version call so we need this: - odfvsn = ' '; + ## Apparently all requested classes present. + ## Only now we can check for proper odfdom version (only 0.7.5 & 0.8.6+ work OK). + ## The odfdom team deemed it necessary to change the version call so we need this: + odfvsn = " "; try - # New in 0.8.6 - odfvsn = java_invoke ('org.odftoolkit.odfdom.JarManifest', 'getOdfdomVersion'); + ## New in 0.8.6 + odfvsn = ... + java_invoke ("org.odftoolkit.odfdom.JarManifest", "getOdfdomVersion"); catch - odfvsn = java_invoke ('org.odftoolkit.odfdom.Version', 'getApplicationVersion'); + odfvsn = ... + java_invoke ("org.odftoolkit.odfdom.Version", "getApplicationVersion"); end_try_catch - # For odfdom-incubator, strip extra info + ## For odfdom-incubator (= 0.8.8+), strip extra info odfvsn = regexp (odfvsn, '\d\.\d\.\d', "match"){1}; - if ~(strcmp (odfvsn, "0.7.5") || strcmp (odfvsn, "0.8.6") || strcmp (odfvsn, "0.8.7") - || strfind (odfvsn, "0.8.8")) + if ~(strcmp (odfvsn, "0.7.5") || strcmp (odfvsn, "0.8.6") ... + || strcmp (odfvsn, "0.8.7") || strfind (odfvsn, "0.8.8")) warning ("\nodfdom version %s is not supported - use v. 0.8.6 or later\n", odfvsn); else - if (strcmp (odfvsn, '0.7.5')) - warning ("odfdom v. 0.7.5 support won't be maintained - please upgrade to 0.8.6 or higher."); + if (strcmp (odfvsn, "0.7.5")) + warning (["odfdom v. 0.7.5 support won't be maintained " ... + "- please upgrade to 0.8.6 or higher."]); endif odsinterfaces.OTK = 1; printf ("OTK"); @@ -153,7 +165,7 @@ endif endif - # Try Java & jOpenDocument + ## Try Java & jOpenDocument if (isempty (odsinterfaces.JOD)) odsinterfaces.JOD = 0; entries = {"jOpenDocument"}; @@ -166,26 +178,32 @@ endif endif - # Try Java & UNO + ## Try Java & UNO if (isempty (odsinterfaces.UNO)) odsinterfaces.UNO = 0; - # entries(1) = not a jar but a directory (<000_install_dir/program/>) - entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + ## entries(1) = not a jar but a directory (<000_install_dir/program/>) + entries = {"program", "unoil", "jurt", "juh", "unoloader", "ridl"}; if (chk_jar_entries (jcp, entries) >= numel (entries)) odsinterfaces.UNO = 1; printf ("UNO"); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; uno_1st_time = min (++uno_1st_time, 2); endif + if (deflt) + printf ("; "); + else + printf ("*; "); + deflt = 1; + uno_1st_time = min (++uno_1st_time, 2); + endif else warning ("\nOne or more UNO classes (.jar) missing in javaclasspath"); endif endif - # ---- Other interfaces here, similar to the ones above + ## ---- Other interfaces here, similar to the ones above if (deflt), printf ("(* = active interface)\n"); endif ## FIXME the below stanza should be dropped once UNO is stable. - # Echo a suitable warning about experimental status: + ## Echo a suitable warning about experimental status: if (uno_1st_time == 1) ++uno_1st_time; printf ("\nPLEASE NOTE: UNO (=OpenOffice.org-behind-the-scenes) is EXPERIMENTAL\n");
--- a/main/io/inst/private/getusedrange.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/getusedrange.m Wed Oct 24 21:43:38 2012 +0000 @@ -69,30 +69,31 @@ ## 2012-06-08 Replaced tabs by double space ## '' Added COM and OXS to message about supported interfaces ## 2012-10-12 Moved all interface-specific subfuncs to . /private -## -## Last subfunc update: 2012-10-12 +## 2012-10-23 Added UNO to error message +## '' Style fixes function [ trow, lrow, lcol, rcol ] = getusedrange (spptr, ii) - # Some checks + ## Some checks if ~isstruct (spptr), error ("Illegal spreadsheet pointer argument"); endif if (strcmp (spptr.xtype, 'OTK')) [ trow, lrow, lcol, rcol ] = __OTK_getusedrange__ (spptr, ii); - elseif (strcmp (spptr.xtype, 'JOD')) + elseif (strcmp (spptr.xtype, "JOD")) [ trow, lrow, lcol, rcol ] = __JOD_getusedrange__ (spptr, ii); - elseif (strcmp (spptr.xtype, 'UNO')) + elseif (strcmp (spptr.xtype, "UNO")) [ trow, lrow, lcol, rcol ] = __UNO_getusedrange__ (spptr, ii); - elseif (strcmp (spptr.xtype, 'COM')) + elseif (strcmp (spptr.xtype, "COM")) [ trow, lrow, lcol, rcol ] = __COM_getusedrange__ (spptr, ii); - elseif (strcmp (spptr.xtype, 'POI')) + elseif (strcmp (spptr.xtype, "POI")) [ trow, lrow, lcol, rcol ] = __POI_getusedrange__ (spptr, ii); - elseif (strcmp (spptr.xtype, 'JXL')) + elseif (strcmp (spptr.xtype, "JXL")) [ trow, lrow, lcol, rcol ] = __JXL_getusedrange__ (spptr, ii); - elseif (strcmp (spptr.xtype, 'OXS')) + elseif (strcmp (spptr.xtype, "OXS")) [ trow, lrow, lcol, rcol ] = __OXS_getusedrange__ (spptr, ii); else - error ("Only OTK, JOD, COM, POI, JXL and OXS interface implemented"); + error ... + ("Unknown interface - only OTK, JOD, COM, POI, JXL, UNO and OXS implemented"); endif endfunction
--- a/main/io/inst/private/getxlsinterfaces.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/getxlsinterfaces.m Wed Oct 24 21:43:38 2012 +0000 @@ -62,45 +62,48 @@ ## 2012-06-06 Improved & simplified Java check code ## 2012-09-03 Check for matching .jar names & javaclasspath was reversed (oops) ## 2012-10-07 Moved common classpath entry code to private function +## 2012-10-24 Style fixes function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) - # tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) - persistent tmp1 = []; persistent tmp2 = []; persistent jcp; # Java class path + ## tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) + persistent tmp1 = []; persistent tmp2 = []; persistent jcp; ## Java class path persistent uno_1st_time = 0; - if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) - && isempty (xlsinterfaces.OXS) && isempty (xlsinterfaces.UNO)) - # Looks like first call to xlsopen. Check Java support + if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) ... + && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS) ... + && isempty (xlsinterfaces.UNO)) + ## Looks like first call to xlsopen. Check Java support printf ("Detected XLS interfaces: "); tmp1 = []; - elseif (isempty (xlsinterfaces.POI) || isempty (xlsinterfaces.JXL) - || isempty (xlsinterfaces.OXS) || isempty (xlsinterfaces.UNO)) - # Can't be first call. Here one of the Java interfaces is requested + elseif (isempty (xlsinterfaces.COM) || isempty (xlsinterfaces.POI) ... + || isempty (xlsinterfaces.JXL) || isempty (xlsinterfaces.OXS) ... + || isempty (xlsinterfaces.UNO)) + ## Can't be first call. Here one of the Java interfaces is requested if (~tmp1) - # Check Java support again + ## Check Java support again tmp1 = []; endif endif deflt = 0; - # Check if MS-Excel COM ActiveX server runs (only on Windows!) - if (isempty (xlsinterfaces.COM)) + ## Check if MS-Excel COM ActiveX server runs (only on Windows!) + if (ispc && isempty (xlsinterfaces.COM)) xlsinterfaces.COM = 0; if (ispc) try app = actxserver ("Excel.application"); - # If we get here, the call succeeded & COM works. + ## If we get here, the call succeeded & COM works. xlsinterfaces.COM = 1; - # Close Excel. Yep this is inefficient when we need only one r/w action, - # but it quickly pays off when we need to do more with the same file - # (+, MS-Excel code is in OS cache anyway after this call so no big deal) + ## Close Excel. Yep this is inefficient when we need only one r/w action, + ## but it quickly pays off when we need to do more with the same file + ## (+, MS-Excel code is in OS cache anyway after this call so no big deal) app.Quit(); delete(app); printf ("COM"); if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif catch - # COM non-existent. Only print message if COM is explicitly requested (tmp1==[]) + ## COM non-existent. Only print message if COM is explicitly requested (tmp1==[]) if (~isempty (tmp1)) printf ("ActiveX not working; no Excel installed?\n"); endif @@ -109,52 +112,52 @@ endif if (isempty (tmp1)) - # Try if Java package works properly by invoking javaclasspath + ## Try if Java package works properly by invoking javaclasspath try - jcp = javaclasspath ('-all'); # For java pkg > 1.2.7 - if (isempty (jcp)), jcp = javaclasspath; endif # For java pkg < 1.2.8 - # If we get here, at least Java works. Now check for proper version (>= 1.6) - jver = char (java_invoke ('java.lang.System', 'getProperty', 'java.version')); + jcp = javaclasspath ("-all"); ## For java pkg > 1.2.7 + if (isempty (jcp)), jcp = javaclasspath; endif ## For java pkg < 1.2.8 + ## If we get here, at least Java works. Now check for proper version (>= 1.6) + jver = char (java_invoke ("java.lang.System", "getProperty", "java.version")); cjver = strsplit (jver, '.'); - if (sscanf (cjver{2}, '%d') < 6) + if (sscanf (cjver{2}, "%d") < 6) 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 - # must first be split up. In java 1.2.8+ javaclasspath is already a cell array + ## Now check for proper entries in class path. Under *nix the classpath + ## must first be split up. In java 1.2.8+ javaclasspath is already a cell array if (isunix && ~iscell (jcp)); jcp = strsplit (char (jcp), pathsep); endif tmp1 = 1; catch - # No Java support found + ## No Java support found tmp1 = 0; if (isempty (xlsinterfaces.POI) || isempty (xlsinterfaces.JXL)... || isempty (xlsinterfaces.OXS) || isempty (xlsinterfaces.UNO)) - # Some or all Java-based interface(s) explicitly requested but no Java support - warning (' No working Java support found. Java pkg properly installed?'); + ## Some or all Java-based interface(s) explicitly requested but no Java support + warning (" No working Java support found. Java pkg properly installed?"); endif - # Set Java interfaces to 0 anyway as there's no Java support + ## Set Java interfaces to 0 anyway as there's no Java support xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; xlsinterfaces.OXS = 0; xlsinterfaces.UNO = 0; printf ("\n"); - # No more need to try any Java interface + ## No more need to try any Java interface return end_try_catch endif - # Try Java & Apache POI + ## Try Java & Apache POI if (isempty (xlsinterfaces.POI)) xlsinterfaces.POI = 0; - # Check basic .xls (BIFF8) support + ## Check basic .xls (BIFF8) support entries = {"poi-3", "poi-ooxml-3"}; - # Only under *nix we might use brute force: e.g., strfind (classname, classpath); - # under Windows we need the following more subtle, platform-independent approach: + ## Only under *nix we might use brute force: e.g., strfind (classname, classpath); + ## under Windows we need the following more subtle, platform-independent approach: if (chk_jar_entries (jcp, entries) >= numel (entries)) xlsinterfaces.POI = 1; printf ("POI"); endif - # Check OOXML support + ## Check OOXML support entries = {"xbean", "poi-ooxml-schemas", "dom4j"}; if (chk_jar_entries (jcp, entries) >= numel (entries)), printf (" (& OOXML)"); endif if (xlsinterfaces.POI) @@ -162,7 +165,7 @@ endif endif - # Try Java & JExcelAPI + ## Try Java & JExcelAPI if (isempty (xlsinterfaces.JXL)) xlsinterfaces.JXL = 0; entries = {"jxl"}; @@ -173,7 +176,7 @@ endif endif - # Try Java & OpenXLS + ## Try Java & OpenXLS if (isempty (xlsinterfaces.OXS)) xlsinterfaces.OXS = 0; entries = {"openxls"}; @@ -184,19 +187,25 @@ endif endif - # Try Java & UNO + ## Try Java & UNO if (isempty (xlsinterfaces.UNO)) xlsinterfaces.UNO = 0; - # entries0(1) = not a jar but a directory (<00o_install_dir/program/>) - entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + ## entries0(1) = not a jar but a directory (<00o_install_dir/program/>) + entries = {"program", "unoil", "jurt", "juh", "unoloader", "ridl"}; if (chk_jar_entries (jcp, entries) >= numel (entries)) xlsinterfaces.UNO = 1; - printf ('UNO'); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; uno_1st_time = min (++uno_1st_time, 2); endif + printf ("UNO"); + if (deflt); + printf ("; "); + else + printf ("*; "); + deflt = 1; + uno_1st_time = min (++uno_1st_time, 2); + endif endif endif - # ---- Other interfaces here, similar to the ones above + ## ---- Other interfaces here, similar to the ones above if (deflt), printf ("(* = active interface)\n"); endif
--- a/main/io/inst/private/parse_sp_range.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/parse_sp_range.m Wed Oct 24 21:43:38 2012 +0000 @@ -23,79 +23,79 @@ function [topleft, nrows, ncols, toprow, lcol] = parse_sp_range (range_org) - range = deblank (toupper (range_org)); - range_error = 0; nrows = 0; ncols = 0; + range = deblank (upper (range_org)); + range_error = 0; nrows = 0; ncols = 0; - # Basic checks - if (index (range, ':') == 0) - if (isempty (range)) - range_error = 0; - leftcol = 'A'; - rightcol = 'A'; - else - # Only upperleft cell given, just complete range to 1x1 - # (needed for some routines) - range = [range ":" range]; - endif - endif + # Basic checks + if (index (range, ':') == 0) + if (isempty (range)) + range_error = 0; + leftcol = 'A'; + rightcol = 'A'; + else + # Only upperleft cell given, just complete range to 1x1 + # (needed for some routines) + range = [range ":" range]; + endif + endif - # Split up both sides of the range - [topleft, lowerright] = strtok (range, ':'); + # Split up both sides of the range + [topleft, lowerright] = strtok (range, ':'); - # Get toprow and clean up left column - [st, en] = regexp (topleft, '\d+'); - toprow = str2num (topleft(st:en)); - leftcol = deblank (topleft(1:st-1)); - [st, en1] = regexp( leftcol,'\s+'); - if (isempty (en1)) - en1=0; - endif - [st, en2] = regexp (leftcol,'\D+'); - leftcol = leftcol(en1+1:en2); + # Get toprow and clean up left column + [st, en] = regexp (topleft, '\d+'); + toprow = str2num (topleft(st:en)); + leftcol = deblank (topleft(1:st-1)); + [st, en1] = regexp (leftcol, '\s+'); + if (isempty (en1)) + en1=0 ; + endif + [st, en2] = regexp (leftcol,'\D+'); + leftcol = leftcol(en1+1:en2); - # Get bottom row and clean up right column - [st, en] = regexp (lowerright,'\d+'); - bottomrow = str2num (lowerright(st:en)); - rightcol = deblank (lowerright(2:st-1)); - [st, en1] = regexp (rightcol,'\s+'); - if (isempty (en1)) - en1=0; - endif - [st, en2] = regexp (rightcol,'\D+'); - rightcol = rightcol(en1+1:en2); + # Get bottom row and clean up right column + [st, en] = regexp (lowerright, '\d+'); + bottomrow = str2num (lowerright(st:en)); + rightcol = deblank (lowerright(2:st-1)); + [st, en1] = regexp (rightcol, '\s+'); + if (isempty (en1)) + en1 = 0; + endif + [st, en2] = regexp (rightcol, '\D+'); + rightcol = rightcol(en1+1:en2); - # Check nr. of rows - nrows = bottomrow - toprow + 1; - if (nrows < 1) - range_error = 1; - endif + # Check nr. of rows + nrows = bottomrow - toprow + 1; + if (nrows < 1) + range_error = 1; + endif - if (range_error == 0) - # Get left column nr. - [st, en] = regexp (leftcol, '\D+'); - lcol = (leftcol(st:st) - 'A' + 1); - while (++st <= en) - lcol = lcol * 26 + (leftcol(st:st) - 'A' + 1); - endwhile + if (range_error == 0) + # Get left column nr. + [st, en] = regexp (leftcol, '\D+'); + lcol = (leftcol(st:st) - 'A' + 1); + while (++st <= en) + lcol = lcol * 26 + (leftcol(st:st) - 'A' + 1); + endwhile - # Get right column nr. - [st, en] = regexp (rightcol, '\D+'); - rcol = (rightcol(st:st) - 'A' + 1); - while (++st <= en) - rcol = rcol * 26 + (rightcol(st:st) - 'A' + 1); - endwhile + # Get right column nr. + [st, en] = regexp (rightcol, '\D+'); + rcol = (rightcol(st:st) - 'A' + 1); + while (++st <= en) + rcol = rcol * 26 + (rightcol(st:st) - 'A' + 1); + endwhile - # Check - ncols = rcol - lcol + 1; - if (ncols < 1) - range_error = 1; - endif - endif + # Check + ncols = rcol - lcol + 1; + if (ncols < 1) + range_error = 1; + endif + endif - if (range_error > 0) - ncols = 0; nrows = 0; - error ("Spreadsheet range error! "); - endif + if (range_error > 0) + ncols = 0; nrows = 0; + error ("Spreadsheet range error!"); + endif endfunction @@ -114,4 +114,3 @@ %!test %! [a b c d e] = parse_sp_range ('BvV12798 : xFd1054786'); %! assert ([b c d e], [1041989, 14439, 12798, 1946]); -
--- a/main/io/inst/private/spsh_chkrange.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/spsh_chkrange.m Wed Oct 24 21:43:38 2012 +0000 @@ -35,11 +35,12 @@ ## 2011-03-29 Bug fix - unrecognized pointer struct & wrong type error msg ## 2011-05-15 Experimental UNO support added (OpenOffice.org & clones) ## 2011-09-18 Updated UNO data row capacity for LibreOffice 3.4+ (now 1,048,576 rows) +## 2012-10-23 Style fixes function [ topleft, nrows, ncols, trow, lcol ] = spsh_chkrange (crange, nr, nc, intf, filename=[]) if (nargin == 4) - # File pointer input assumed + ## File pointer input assumed if (isstruct (intf)) xtype = intf.xtype; filename = intf.filename; @@ -47,30 +48,30 @@ error ("Too few or improper arguments supplied."); endif else - # Interface type & filename supplied + ## Interface type & filename supplied xtype = intf; endif - # Define max row & column capacity from interface type & file suffix + ## Define max row & column capacity from interface type & file suffix switch xtype case { 'COM', 'POI' } if (strmatch (tolower (filename(end-3:end)), '.xls')) - # BIFF5 & BIFF8 + ## BIFF5 & BIFF8 ROW_CAP = 65536; COL_CAP = 256; else - # OOXML (COM needs Excel 2007+ for this) + ## OOXML (COM needs Excel 2007+ for this) ROW_CAP = 1048576; COL_CAP = 16384; endif case { 'JXL', 'OXS' } - # JExcelAPI & OpenXLS can only process BIFF5 & BIFF8 + ## JExcelAPI & OpenXLS can only process BIFF5 & BIFF8 ROW_CAP = 65536; COL_CAP = 256; case { 'OTK', 'JOD' } - # ODS + ## ODS ROW_CAP = 65536; COL_CAP = 1024; 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 its Java classes haven't been updated + ## ODS; LibreOffice has a higher row capacity + ## FIXME - use UNO calls to check physical row capacity + ## FIXME - LibreOffice has higher row capacity but its Java classes haven't been updated ROW_CAP = 1048576; COL_CAP = 1024; otherwise error (sprintf ("Unknown interface type - %s\n", xtype)); @@ -83,7 +84,7 @@ ncols = nc; topleft = 'A1'; elseif (isempty (strfind (deblank (crange), ':'))) - # Only top left cell specified + ## Only top left cell specified [topleft, dummy1, dummy2, trow, lcol] = parse_sp_range (crange); nrows = nr; ncols = nc; @@ -93,10 +94,10 @@ if (trow > ROW_CAP || lcol > COL_CAP) error ("Topleft cell (%s) beyond spreadsheet limits."); endif - # Check spreadsheet capacity beyond requested topleft cell + ## Check spreadsheet capacity beyond requested topleft cell nrows = min (nrows, ROW_CAP - trow + 1); ncols = min (ncols, COL_CAP - lcol + 1); - # Check array size and requested range + ## Check array size and requested range nrows = min (nrows, nr); ncols = min (ncols, nc);
--- a/main/io/inst/private/spsh_prstype.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/private/spsh_prstype.m Wed Oct 24 21:43:38 2012 +0000 @@ -33,46 +33,50 @@ ## Updates: ## 2010-08-25 Corrected help text (square -> rectangular; stressed "internal" use) ## 2011-04-21 Formulas now don't need closing ")" (e.g., =A1+B1 is OK as well) -## " Formula ptrs in output arg now OK (cellfun(@(x).... skips empty cells) +## '' Formula ptrs in output arg now OK (cellfun(@(x).... skips empty cells) +## 2012-10-23 Style fixes function [ typearr ] = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts) - # ctype index: - # 1 = numeric - # 2 = boolean - # 3 = text - # 4 = formula - # 5 = error / NaN / empty + ## ctype index: + ## 1 = numeric + ## 2 = boolean + ## 3 = text + ## 4 = formula + ## 5 = error / NaN / empty - typearr = ctype(5) * ones (nrows, ncols); # type "EMPTY", provisionally - obj2 = cell (size (obj)); # Temporary storage for strings + 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" - obj2(txtptr) = obj(txtptr); obj(txtptr) = ctype(3); # Save strings in a safe place + 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 + obj(emptr) = ctype(5); ## Set empty cells to NUMERIC - lptr = cellfun ("islogical" , obj); # Find logicals... - obj2(lptr) = obj(lptr); # .. and set them to BOOLEAN - - ptr = cellfun ("isnan", obj); # Find NaNs & set to BLANK - typearr(ptr) = ctype(5); typearr(~ptr) = ctype(1); # All other cells are now numeric + lptr = cellfun ("islogical" , obj); ## Find logicals... + obj2(lptr) = obj(lptr); ## .. and set them to BOOLEAN - 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 + ptr = cellfun ("isnan", obj); ## Find NaNs & set to BLANK + typearr(ptr) = ctype(5); + typearr(~ptr) = ctype(1); ## All other cells are now numeric - typearr(txtptr) = ctype(3); # ...and clean up - typearr(emptr) = ctype(5); # EMPTY - typearr(lptr) = ctype(2); # BOOLEAN + 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 + + typearr(txtptr) = ctype(3); ## ...and clean up + typearr(emptr) = ctype(5); ## EMPTY + typearr(lptr) = ctype(2); ## BOOLEAN if ~(spsh_opts.formulas_as_text) - # Find formulas (designated by a string starting with "=" and ending in ")") - #fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) && strncmp (x(end:end), ")", 1), obj); - # Find formulas (designated by a string starting with "=") + ## Find formulas (designated by a string starting with "=" and ending in ")") + ## fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) + ## && strncmp (x(end:end), ")", 1), obj); + ## Find formulas (designated by a string starting with "=") fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1), obj); - typearr(fptr) = ctype(4); # FORMULA + typearr(fptr) = ctype(4); ## FORMULA endif endfunction
--- a/main/io/inst/xls2oct.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/xls2oct.m Wed Oct 24 21:43:38 2012 +0000 @@ -134,13 +134,16 @@ ## 2012-06-06 Implemented "formulas_as_text" option for COM ## 2012-06-07 Replaced all tabs by double space ## 2012-10-12 Moved all interface-specific subfubcs into ./private +## 2012-10-24 Style fixes ## ## Latest subfunc update: 2012-10-12 -function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) +function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange="", spsh_opts=[]) - # Check if xls struct pointer seems valid - if (~isstruct (xls)), error ("File ptr struct expected for arg @ 1"); endif + ## Check if xls struct pointer seems valid + if (~isstruct (xls)) + error ("File ptr struct expected for arg @ 1"); + endif test1 = ~isfield (xls, "xtype"); test1 = test1 || ~isfield (xls, "workbook"); test1 = test1 || isempty (xls.workbook); @@ -150,47 +153,57 @@ 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 - if (~(isempty (datrange) || ischar (datrange))), error ("Character string (range) expected for arg # 3"); endif + ## Check worksheet ptr + if (~(ischar (wsh) || isnumeric (wsh))) + error ("Integer (index) or text (wsh name) expected for arg # 2"); + endif + ## Check range + if (~(isempty (datrange) || ischar (datrange))) + error ("Character string expected for arg # 3 (range)"); + endif - # Check & setup options struct + ## Check & setup options struct if (nargin < 4 || isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; spsh_opts.strip_array = 1; - # Future options: + ## Future options: + elseif (isstruct (spsh_opts)) - if (~isfield (spsh_opts', 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif - if (~isfield (spsh_opts', 'strip_array')), spsh_opts.strip_array = 1; endif - % Future options: + if (~isfield (spsh_opts, "formulas_as_text")) + spsh_opts.formulas_as_text = 0; + endif + if (~isfield (spsh_opts, "strip_array")) + spsh_opts.strip_array = 1; + endif + ## Future options: + else - error ("Structure expected for arg # 4"); + error ("Structure expected for arg # 4 (options)"); endif - # Select the proper interfaces - if (strcmp (xls.xtype, 'COM')) - # Call Excel tru COM / ActiveX server + ## Select the proper interfaces + if (strcmp (xls.xtype, "COM")) + ## Call Excel tru COM / ActiveX server [rawarr, xls, rstatus] = __COM_spsh2oct__ (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'POI')) - # Read xls file tru Java POI + elseif (strcmp (xls.xtype, "POI")) + ## Read xls file tru Java POI [rawarr, xls, rstatus] = __POI_spsh2oct__ (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'JXL')) - # Read xls file tru JExcelAPI + elseif (strcmp (xls.xtype, "JXL")) + ## Read xls file tru JExcelAPI [rawarr, xls, rstatus] = __JXL_spsh2oct__ (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'OXS')) - # Read xls file tru OpenXLS + elseif (strcmp (xls.xtype, "OXS")) + ## Read xls file tru OpenXLS [rawarr, xls, rstatus] = __OXS_spsh2oct__ (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'UNO')) - # Read xls file tru OpenOffice.org UNO (Java) bridge + elseif (strcmp (xls.xtype, "UNO")) + ## Read xls file tru OpenOffice.org UNO (Java) bridge [rawarr, xls, rstatus] = __UNO_spsh2oct__ (xls, wsh, datrange, spsh_opts); -# elseif ---- <Other interfaces here> - # Call to next interface + ##elseif ---- <Other interfaces here> + ## Call to next interface else error (sprintf ("xls2oct: unknown Excel .xls interface - %s.", xls.xtype)); endif - # Optionally strip empty outer rows and columns & keep track of original data location + ## Optionally strip empty outer rows and columns & keep track of original data location if (spsh_opts.strip_array) emptr = cellfun ('isempty', rawarr); if (all (all (emptr))) @@ -207,7 +220,7 @@ icolr = ncols; while (all (emptr(:, icolr))), icolr--; endwhile - # Crop output cell array and update limits + ## Crop output cell array and update limits rawarr = rawarr(irowt:irowb, icoll:icolr); xls.limits = xls.limits + [icoll-1, icolr-ncols; irowt-1, irowb-nrows]; endif
--- a/main/io/inst/xlsclose.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/xlsclose.m Wed Oct 24 21:43:38 2012 +0000 @@ -76,6 +76,7 @@ ## '' (in UNO section) web adresses need only two consecutive slashes ## 2012-10-12 Move most interface-specific code to ./private subfuncs ## '' Move "file ptr preserved" message to proper else clause +## 2012-10-24 Style fixes function [ xls ] = xlsclose (xls, varargs) @@ -83,60 +84,62 @@ if (nargin > 1) for ii=2:nargin - if (strcmp (lower (varargin{ii}), "force")) - # Close .xls anyway even if write errors occur + if (strcmpi (varargin{ii}, "force")) + ## Close .xls anyway even if write errors occur force = 1; + ## Interface-specific clauses here: elseif (~isempty (strfind (tolower (varargin{ii}), '.'))) - # Apparently a file name. First some checks.... + ## Apparently a file name. First some checks.... if (xls.changed == 0 || xls.changed > 2) warning ("File %s wasn't changed, new filename ignored.", xls.filename); - elseif (strcmp (xls.xtype, 'JXL')) + 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 ( lower (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 suffix lacking in filename %s', filename); + error (".xls or .xlsx suffix 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; - #endif - # Preprocessing / -checking ready. Assign filename arg to file ptr struct + ## 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; + ##endif + ## Preprocessing / -checking ready. Assign filename arg to file ptr struct xls.nfilename = filename; endif endif endfor endif - if (strcmp (xls.xtype, 'COM')) + if (strcmp (xls.xtype, "COM")) xls = __COM_spsh_close__ (xls); - elseif (strcmp (xls.xtype, 'POI')) + elseif (strcmp (xls.xtype, "POI")) xls = __POI_spsh_close__ (xls); - elseif (strcmp (xls.xtype, 'JXL')) + elseif (strcmp (xls.xtype, "JXL")) xls = __JXL_spsh_close__ (xls); - elseif (strcmp (xls.xtype, 'OXS')) + elseif (strcmp (xls.xtype, "OXS")) xls = __OXS_spsh_close__ (xls); - elseif (strcmp (xls.xtype, 'UNO')) + elseif (strcmp (xls.xtype, "UNO")) xls = __UNO_spsh_close__ (xls, force); -# elseif <other interfaces here> + ## elseif <other interfaces here> endif if (xls.changed && xls.changed < 3) - warning (sprintf ("File %s could not be saved. Read-only or in use elsewhere?", xls.filename)); + warning (sprintf ("File %s could not be saved. Read-only or in use elsewhere?",... + xls.filename)); if (force) xls = []; else - printf ("(File pointer preserved)\n"); + printf ("(File pointer preserved. Try saving again later...)\n"); endif else xls = [];
--- a/main/io/inst/xlsfinfo.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/xlsfinfo.m Wed Oct 24 21:43:38 2012 +0000 @@ -87,10 +87,11 @@ ## 2012-01-26 Fixed "seealso" help string ## 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 function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[]) - persistent str2; str2 = ' '; # 33 spaces + persistent str2; str2 = " "; # 33 spaces persistent lstr2; lstr2 = length (str2); xls = xlsopen (filename, 0, reqintf); @@ -98,25 +99,26 @@ toscreen = nargout < 1; - # If any valid xls-pointer struct has been returned, it must be a valid Excel spreadsheet - filetype = 'Microsoft Excel Spreadsheet'; fformat = ''; + ## If any valid xls-pointer struct has been returned, it must be a valid Excel spreadsheet + filetype = "Microsoft Excel Spreadsheet"; + fformat = ""; - if (strcmp (xls.xtype, 'COM')) + if (strcmp (xls.xtype, "COM")) [sh_names] = __COM_spsh_info__ (xls); - elseif (strcmp (xls.xtype, 'POI')) + elseif (strcmp (xls.xtype, "POI")) [sh_names] = __POI_spsh_info__ (xls); - elseif (strcmp (xls.xtype, 'JXL')) + elseif (strcmp (xls.xtype, "JXL")) [sh_names] = __JXL_spsh_info__ (xls); - elseif (strcmp (xls.xtype, 'OXS')) + elseif (strcmp (xls.xtype, "OXS")) [sh_names] = __OXS_spsh_info__ (xls); - elseif (strcmp (xls.xtype, 'UNO')) + elseif (strcmp (xls.xtype, "UNO")) [sh_names] = __UNO_spsh_info__ (xls); -# elseif <Other Excel interfaces below> +##elseif <Other Excel interfaces below> else error (sprintf ("xlsfinfo: unknown Excel .xls interface - %s.", xls.xtype)); @@ -125,11 +127,11 @@ sh_cnt = size (sh_names, 1); if (toscreen) - # Echo sheet names to screen + ## Echo sheet names to screen for ii=1:sh_cnt str1 = sprintf ("%3d: %s", ii, sh_names{ii, 1}); if (index (sh_names{ii, 2}, ":")) - str3 = ['(Used range ~ ' sh_names{ii, 2} ')']; + str3 = [ "(Used range ~ " sh_names{ii, 2} ")" ]; else str3 = sh_names{ii, 2}; endif @@ -137,16 +139,16 @@ endfor else if (sh_cnt > 0) - if (strcmpi (xls.filename(end-2:end), 'xls')) + if (strcmpi (xls.filename(end-2:end), "xls")) fformat = "xlWorkbookNormal"; - elseif (strcmpi (xls.filename(end-2:end), 'csv')) - fformat = "xlCSV"; # Works only with COM - elseif (strcmpi (xls.filename(end-3:end-1), 'xls')) + elseif (strcmpi (xls.filename(end-2:end), "csv")) + fformat = "xlCSV"; ## Works only with COM + elseif (strcmpi (xls.filename(end-3:end-1), "xls")) fformat = "xlOpenXMLWorkbook"; elseif (strmatch ('htm', lower (xls.filename(end-3:end)))) - fformat = "xlHtml"; # Works only with COM + fformat = "xlHtml"; ## Works only with COM else - fformat = ''; + fformat = ""; endif endif endif
--- a/main/io/inst/xlsopen.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/xlsopen.m Wed Oct 24 21:43:38 2012 +0000 @@ -113,11 +113,12 @@ ## make_absolute_filename (see bug #36677) ## 2012-10-07 Moved subfunc getxlsinterfaces to ./private ## '' Moved all interface-specific file open stanzas to separate ./private funcs +## 2012-10-24 Style fixes function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) persistent xlsinterfaces; persistent chkintf; persistent lastintf; - # xlsinterfaces.<intf> = [] (not yet checked), 0 (found to be unsupported) or 1 (OK) + ## xlsinterfaces.<intf> = [] (not yet checked), 0 (found to be unsupported) or 1 (OK) if (isempty (chkintf)); chkintf = 1; xlsinterfaces = struct ('COM', [], 'POI', [], 'JXL', [], 'OXS', [], 'UNO', []); @@ -133,13 +134,17 @@ endif if (~(islogical (xwrite) || isnumeric (xwrite))) - usage ("Numerical or logical value expected for arg # 2") + usage ("Numerical or logical value expected for arg ## 2 (readwrite)") endif if (~isempty (reqinterface)) - if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif - # Turn arg3 into cell array if needed - if (~iscell (reqinterface)), reqinterface = {reqinterface}; endif + if ~(ischar (reqinterface) || iscell (reqinterface)) + usage ("Arg ## 3 (interface) not recognized - character value required"); + endif + ## Turn arg3 into cell array if needed + if (~iscell (reqinterface)) + reqinterface = {reqinterface}; + endif ## Check if previously used interface matches a requested interface if (isempty (regexpi (reqinterface, lastintf, 'once'){1})) ## New interface requested @@ -147,8 +152,8 @@ xlsinterfaces.OXS = 0; xlsinterfaces.UNO = 0; for ii=1:numel (reqinterface) reqintf = toupper (reqinterface {ii}); - # Try to invoke requested interface(s) for this call. Check if it - # is supported anyway by emptying the corresponding var. + ## Try to invoke requested interface(s) for this call. Check if it + ## is supported anyway by emptying the corresponding var. if (strcmpi (reqintf, 'COM')) xlsinterfaces.COM = []; elseif (strcmpi (reqintf, 'POI')) @@ -160,23 +165,23 @@ elseif (strcmpi (reqintf, 'UNO')) xlsinterfaces.UNO = []; else - usage (sprintf ("Unknown .xls interface \"%s\" requested. Only COM, POI, JXL, OXS or UNO supported\n", reqinterface{})); + usage (sprintf (["Unknown .xls interface \"%s\" requested.\n" + "Only COM, POI, JXL, OXS or UNO supported\n"], reqinterface{})); endif endfor printf ("Checking requested interface(s):\n"); xlsinterfaces = getxlsinterfaces (xlsinterfaces); - # Well, is/are the requested interface(s) supported on the system? - # FIXME check for multiple interfaces + ## Well, is/are the requested interface(s) supported on the system? xlsintf_cnt = 0; for ii=1:numel (reqinterface) if (~xlsinterfaces.(toupper (reqinterface{ii}))) - # No it aint + ## No it aint printf ("%s is not supported.\n", upper (reqinterface{ii})); else ++xlsintf_cnt; endif endfor - # Reset interface check indicator if no requested support found + ## Reset interface check indicator if no requested support found if (~xlsintf_cnt) chkintf = []; xls = []; @@ -185,92 +190,103 @@ endif endif - # Var xwrite is really used to avoid creating files when wanting to read, or - # not finding not-yet-existing files when wanting to write. + ## Var readwrite is really used to avoid creating files when wanting to read, + ## or not finding not-yet-existing files when wanting to write a new one. - # Check if Excel file exists. Adapt file open mode for readwrite argument - if (xwrite), fmode = 'r+b'; else fmode = 'rb'; endif + ## Check if Excel file exists. Adapt file open mode for readwrite argument + if (xwrite); fmode = 'r+b'; else fmode = 'rb'; endif fid = fopen (filename, fmode); - if (fid < 0) # File doesn't exist... - if (~xwrite) # ...which obviously is fatal for reading... + if (fid < 0) ## File doesn't exist... + if (~xwrite) ## ...which obviously is fatal for reading... error ( sprintf ("File %s not found\n", filename)); - else # ...but for writing, we need more info: - fid = fopen (filename, 'rb'); # Check if it exists at all... - if (fid < 0) # File didn't exist yet. Simply create it + else ## ...but for writing, we need more info: + fid = fopen (filename, 'rb'); ## Check if it exists at all... + if (fid < 0) ## File didn't exist yet. Simply create it printf ("Creating file %s\n", filename); xwrite = 3; - else # File exists, but is not writable => Error - fclose (fid); # Do not forget to close the handle neatly + else ## File exists, but isn't writable => Error + fclose (fid); ## Do not forget to close the handle neatly error (sprintf ("Write mode requested but file %s is not writable\n", filename)) endif endif else - # Close file anyway to avoid COM or Java errors + ## Close file anyway to avoid COM or Java errors fclose (fid); endif - # Check for the various Excel interfaces. No problem if they've already - # been checked, getxlsinterfaces (far below) just returns immediately then. + ## Check for the various Excel interfaces. No problem if they've already + ## been checked, getxlsinterfaces (far below) just returns immediately then. xlsinterfaces = getxlsinterfaces (xlsinterfaces); - # 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 + ## 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 - # Initialize file ptr struct - xls = struct ("xtype", 'NONE', "app", [], "filename", [], "workbook", [], "changed", 0, "limits", []); + ## Initialize file ptr struct + xls = struct ("xtype", 'NONE', + "app", [], + "filename", [], + "workbook", [], + "changed", 0, + "limits", []); - # Keep track of which interface is selected + ## Keep track of which interface is selected xlssupport = 0; - # Interface preference order is defined below: currently COM -> POI -> JXL -> OXS -> UNO - # chk1 & chk2 (xls file type) are conveyed depending on interface capabilities + ## Interface preference order is defined below: currently COM -> POI -> JXL -> OXS -> UNO + ## chk1 & chk2 (xls file type) are conveyed depending on interface capabilities if (xlsinterfaces.COM && ~xlssupport) - # Excel functioning has been tested above & file exists, so we just invoke it + ## 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 (xlsinterfaces.POI && ~xlssupport) + if (xlsinterfaces.POI && ~xlssupport && (chk1 || chk2)) [ xls, xlssupport, lastintf ] = __POI_spsh_open__ (xls, xwrite, filename, xlssupport, chk1, chk2, xlsinterfaces); + elseif ~(chk1 || chk2) + error ("Unsupported file format for Apache POI") endif - if (xlsinterfaces.JXL && ~xlssupport) + if (xlsinterfaces.JXL && ~xlssupport && chk1) [ xls, xlssupport, lastintf ] = __JXL_spsh_open__ (xls, xwrite, filename, xlssupport, chk1); + elseif (~chk1) + error ("Unsupported file format for JExcelAPI") endif - if (xlsinterfaces.OXS && ~xlssupport) + if (xlsinterfaces.OXS && ~xlssupport && chk1) [ xls, xlssupport, lastintf ] = __OXS_spsh_open__ (xls, xwrite, filename, xlssupport, chk1); + elseif (~chk1) + error ("Unsupported file format for OpenXLS") endif if (xlsinterfaces.UNO && ~xlssupport) [ xls, xlssupport, lastintf ] = __UNO_spsh_open__ (xls, xwrite, filename, xlssupport); endif - # if - # ---- other interfaces - # endif + ## if + ## ---- other interfaces + ## endif - # Rounding up. If none of the xlsinterfaces is supported we're out of luck. + ## Rounding up. If none of the xlsinterfaces is supported we're out of luck. if (~xlssupport) if (isempty (reqinterface)) + ## This message is appended after message from getxlsinterfaces() printf ("None.\n"); warning ("No support for Excel .xls I/O"); else warning ("File type not supported by %s %s %s %s %s", reqinterface{:}); endif xls = []; - # Reset found interfaces for re-testing in the next call. Add interfaces if needed. + ## Reset found interfaces for re-testing in the next call. Add interfaces if needed. chkintf = []; else - # From here on xwrite is tracked via xls.changed in the various lower - # level r/w routines and it is only used to determine if an informative - # message is to be given when saving a newly created xls file. + ## From here on xwrite is tracked via xls.changed in the various lower + ## level r/w routines xls.changed = xwrite; - # 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). + ## xls.changed = 0 (existing/only read from), 1 (existing/data added), 2 (new, + ## data added) or 3 (pristine, no data added). + ## Until something was written to existing files we keep status "unchanged". if (xls.changed == 1), xls.changed = 0; endif endif
--- a/main/io/inst/xlsread.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/xlsread.m Wed Oct 24 21:43:38 2012 +0000 @@ -144,6 +144,7 @@ ## 2011-09-08 Minor code cleanup; included UNO & OXS support in test ## 2012-01-26 Fixed "seealso" help string ## 2012-03-07 Updated texinfo help header +## 2012-10-24 Style fixes function [ numarr, txtarr, rawarr, lims ] = xlsread (fn, wsh, datrange, reqintf=[]) @@ -158,30 +159,30 @@ return elseif (nargin == 1) wsh = 1; - datrange = ''; + datrange = ""; elseif (nargin == 2) - # Find out whether 2nd argument = worksheet or range - if (isnumeric (wsh) || (isempty (findstr (wsh,':')) && ~isempty (wsh))) - # Apparently a worksheet specified - datrange = ''; + ## Find out whether 2nd argument = worksheet or range + if (isnumeric (wsh) || (isempty (findstr (wsh, ":" )) && ~isempty (wsh))) + ## Apparently a worksheet specified + datrange = ""; else - # Range specified + ## Range specified datrange = wsh; wsh = 1; endif endif - # A small gesture for Matlab compatibility. JExcelAPI supports BIFF5. - if (~isempty (reqintf) && ischar (reqintf) && strcmpi (reqintf, 'BASIC')) - reqintf= {"JXL"} ; - printf ("(BASIC (BIFF5) support request translated to JXL.) \n"); + ## A small gesture for Matlab compatibility. JExcelAPI supports BIFF5. + if (~isempty (reqintf) && ischar (reqintf) && strcmpi (reqintf, "BASIC")) + reqintf = {"JXL"}; + printf ("(BASIC (BIFF5) support request translated to JXL)\n"); endif - # Checks done. Get raw data into cell array "rawarr". xlsopen finds out - # what interface to use. If none found, just return as xlsopen will complain enough + ## Checks done. Get raw data into cell array "rawarr". xlsopen finds out + ## 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 + ## Get pointer array to Excel file xls_ok = 0; xls = xlsopen (fn, 0, reqintf); if (~isempty (xls)) @@ -190,32 +191,24 @@ return endif -# 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); - - # Save some results before xls is wiped - rawlimits = xls.limits; - xtype = xls.xtype; + ## Get data from Excel file & return handle + [rawarr, xls, rstatus] = xls2oct (xls, wsh, datrange); - if (rstatus) - [numarr, txtarr, lims] = parsecell (rawarr, rawlimits); - else - rawarr = {}; numarr = []; txtarr = {}; - endif + ## Save some results before xls is wiped + rawlimits = xls.limits; + xtype = xls.xtype; -# 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 + if (rstatus) + [numarr, txtarr, lims] = parsecell (rawarr, rawlimits); + else + rawarr = {}; numarr = []; txtarr = {}; + endif unwind_protect_cleanup - # Close Excel file - if (xls_ok) xls = xlsclose (xls); endif + ## Close Excel file + if (xls_ok) + xls = xlsclose (xls); + endif end_unwind_protect
--- a/main/io/inst/xlswrite.m Wed Oct 24 06:23:57 2012 +0000 +++ b/main/io/inst/xlswrite.m Wed Oct 24 21:43:38 2012 +0000 @@ -107,36 +107,37 @@ ## 2011-09-08 Minor code syntax updates ## 2012-01-26 Fixed "seealso" help string ## 2012-06-07 Replaced all tabs by double space +## 2012-10-24 Style fixes function [ rstatus ] = xlswrite (filename, arr, arg3, arg4, arg5) rstatus = 0; - # Sanity checks + ## Sanity checks if (nargin < 2) usage ("Insufficient arguments - see 'help xlswrite'"); elseif (~ischar (filename)) error ("First argument must be a filename (incl. suffix)"); elseif (nargin == 2) - # Assume first worksheet and full worksheet starting at A1 + ## Assume first worksheet and full worksheet starting at A1 wsh = 1; - if (strcmp (tolower (filename(end-4:end-1)), 'xls')) - crange = "A1:XFD1048576"; # OOXML has ridiculously large limits + if (strcmpi (filename(end-4:end-1), "xls")) + crange = "A1:XFD1048576"; ## OOXML has ridiculously large limits else - crange = "A1:IV65536"; # Regular xls limits + crange = "A1:IV65536"; ## Regular xls limits endif elseif (nargin == 3) - # Find out whether 3rd argument = worksheet or range - if (isnumeric (arg3) || (isempty (findstr (arg3, ':')) && ~isempty (arg3))) - # Apparently a worksheet specified + ## Find out whether 3rd argument = worksheet or range + if (isnumeric (arg3) || (isempty (findstr (arg3, ":")) && ~isempty (arg3))) + ## Apparently a worksheet specified wsh = arg3; - if (strcmp (tolower (filename(end-4:end-1)), 'xls')) - crange = "A1:XFD1048576"; # OOXML has ridiculously large limits + if (strcmpi (filename(end-4:end-1), "xls")) + crange = "A1:XFD1048576"; ## OOXML has ridiculously large limits else - crange = "A1:IV65536"; # Regular xls limits + crange = "A1:IV65536"; ## Regular xls limits endif else - # Range specified + ## Range specified wsh = 1; crange = arg3; endif @@ -150,20 +151,20 @@ reqintf = []; endif - # Parse range + ## Parse range [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); - # Check if arr fits in range + ## Check if arr fits in range [nr, nc] = size (arr); if ((nr > nrows) || (nc > ncols)) # Array too big; truncate nr = min (nrows, nr); nc = min (ncols, nc); warning ("xlswrite - array truncated to %d by %d to fit in range %s", ... - nrows, ncols, crange); + nrows, ncols, crange); endif - unwind_protect # Needed to be sure Excel can be closed i.c.o. errors + unwind_protect ## Needed to be sure Excel can be closed i.c.o. errors xls_ok = 0; xls = xlsopen (filename, 1, reqintf); xls_ok = 1; @@ -171,7 +172,9 @@ [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