From: <prn...@us...> - 2010-08-03 21:29:12
|
Revision: 7495 http://octave.svn.sourceforge.net/octave/?rev=7495&view=rev Author: prnienhuis Date: 2010-08-03 21:29:06 +0000 (Tue, 03 Aug 2010) Log Message: ----------- Support function files to be invoked by the spreadsheet scripts, not directly by users. Added Paths: ----------- trunk/octave-forge/main/io/inst/spsh_chkrange.m trunk/octave-forge/main/io/inst/spsh_prstype.m Added: trunk/octave-forge/main/io/inst/spsh_chkrange.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_chkrange.m (rev 0) +++ trunk/octave-forge/main/io/inst/spsh_chkrange.m 2010-08-03 21:29:06 UTC (rev 7495) @@ -0,0 +1,82 @@ +## Copyright (C) 2010 Philip Nienhuis +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} [ @var{topleftaddr}, @var{nrows}, @var{ncols}, @var{toprow}, @var{leftcol} ] = spsh_chkrange ( @var{range}, @var{rowsize}, @var{colsize}, @var{intf-type}, @var{filename}) +## Get and check various cell and range address parameters for spreadsheet input. +## +## spsh_chkrange should not be invoked directly but rather through oct2xls or oct2ods. +## +## Example: +## +## @example +## [tl, nrw, ncl, trw, lcl] = spsh_chkrange (crange, nr, nc, xtype, filename); +## @end example +## +## @end deftypefn + +## Author: Philip Nienhuis, <prn...@us...> +## Created: 2010-08-02 +## Updates: +## + +function [ topleft, nrows, ncols, trow, lcol ] = spsh_chkrange (crange, nr, nc, xtype, filename) + + # 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 + ROW_CAP = 65536; COL_CAP = 256; + else + # OOXML (COM needs Excel 2007+ for this) + ROW_CAP = 1048576; COL_CAP = 16384; + endif + case 'JXL' + # JExcelAPI can only process BIFF5 & BIFF8 + ROW_CAP = 65536; COL_CAP = 256; + case {'OTK', 'JOD'} + # ODS + ROW_CAP = 65536; COL_CAP = 1024; + otherwise + error (sprintf ("Unknown interface type - %s\n", spptr.xtype)); + endswitch + + if (isempty (deblank (crange))) + trow = 1; + lcol = 1; + nrows = nr; + ncols = nc; + topleft= 'A1'; + elseif (isempty (strfind (deblank (crange), ':'))) + # Only top left cell specified + [topleft, dummy1, dummy2, trow, lcol] = parse_sp_range (crange); + nrows = nr; + ncols = nc; + else + [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); + endif + if (trow > ROW_CAP || lcol > COL_CAP) + error ("Topleft cell (%s) beyond spreadsheet limits."); + endif + # 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 + nrows = min (nrows, nr); + ncols = min (ncols, nc); + +endfunction Added: trunk/octave-forge/main/io/inst/spsh_prstype.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_prstype.m (rev 0) +++ trunk/octave-forge/main/io/inst/spsh_prstype.m 2010-08-03 21:29:06 UTC (rev 7495) @@ -0,0 +1,75 @@ +## Copyright (C) 2010 Philip Nienhuis +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} [ @var{type-array} ] = spsh_prstype ( @var{iarray}, @var{rowsize}, @var{colsize}, @var{celltypes}, @var{options}) +## Return a square array with codes for cell types in square input cell array @var{iarray}. +## Codes are contained in input vector in order of Numeric, Boolean, Text, Formula and Empty, resp. +## +## spsh_prstype should not be invoked directly but rather through oct2xls or oct2ods. +## +## Example: +## +## @example +## typarr = spsh_chkrange (cellarray, nr, nc, ctypes, options); +## @end example +## +## @end deftypefn + +## Author: Philip Nienhuis, <prn...@us...> +## Created: 2010-08-02 +## Updates: +## + +function [ typearr ] = spsh_prstype (obj, nrows, ncols, ctype, spsh_opts) + + # 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 + + txtptr = cellfun ('isclass', obj, 'char'); # type "STRING" replaced by "NUMERIC" + obj2(txtptr) = obj(txtptr); obj(txtptr) = ctype(3); # Save strings in a safe place + + emptr = cellfun ("isempty", obj); + obj(emptr) = ctype(5); # Set empty cells to NUMERIC + + lptr = cellfun ("islogical" , obj); # Find logicals... + 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 + + obj(txtptr) = obj2(txtptr); # Copy strings back into place + obj(lptr) = obj2(lptr); # Same for logicals + obj(emptr) = []; # And 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); + typearr(fptr) = ctype(4); # FORMULA + endif + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |