1 ## Copyright (C) 2010,2011,2012 Philip Nienhuis <prnienhuis@users.sf.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @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})
18 ## (Internal function) Get and check various cell and range address parameters for spreadsheet input.
20 ## spsh_chkrange should not be invoked directly but rather through oct2xls or oct2ods.
25 ## [tl, nrw, ncl, trw, lcl] = spsh_chkrange (crange, nr, nc, xtype, fileptr);
30 ## Author: Philip Nienhuis <prnienhuis@users.sf.net>
31 ## Created: 2010-08-02
33 ## 2010-08-25 Option for supplying file pointer rather than interface_type & filename
34 ## (but this can be wasteful if the file ptr is copied)
35 ## 2011-03-29 Bug fix - unrecognized pointer struct & wrong type error msg
36 ## 2011-05-15 Experimental UNO support added (OpenOffice.org & clones)
37 ## 2011-09-18 Updated UNO data row capacity for LibreOffice 3.4+ (now 1,048,576 rows)
39 function [ topleft, nrows, ncols, trow, lcol ] = spsh_chkrange (crange, nr, nc, intf, filename=[])
42 # File pointer input assumed
45 filename = intf.filename;
47 error ("Too few or improper arguments supplied.");
50 # Interface type & filename supplied
54 # Define max row & column capacity from interface type & file suffix
57 if (strmatch (tolower (filename(end-3:end)), '.xls'))
59 ROW_CAP = 65536; COL_CAP = 256;
61 # OOXML (COM needs Excel 2007+ for this)
62 ROW_CAP = 1048576; COL_CAP = 16384;
65 # JExcelAPI & OpenXLS can only process BIFF5 & BIFF8
66 ROW_CAP = 65536; COL_CAP = 256;
69 ROW_CAP = 65536; COL_CAP = 1024;
71 # ODS; LibreOffice has a higher row capacity
72 # FIXME - use UNO calls to check physical row capacity
73 # FIXME - LibreOffice has higher row capacity but its Java classes haven't been updated
74 ROW_CAP = 1048576; COL_CAP = 1024;
76 error (sprintf ("Unknown interface type - %s\n", xtype));
79 if (isempty (deblank (crange)))
85 elseif (isempty (strfind (deblank (crange), ':')))
86 # Only top left cell specified
87 [topleft, dummy1, dummy2, trow, lcol] = parse_sp_range (crange);
91 [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange);
93 if (trow > ROW_CAP || lcol > COL_CAP)
94 error ("Topleft cell (%s) beyond spreadsheet limits.");
96 # Check spreadsheet capacity beyond requested topleft cell
97 nrows = min (nrows, ROW_CAP - trow + 1);
98 ncols = min (ncols, COL_CAP - lcol + 1);
99 # Check array size and requested range
100 nrows = min (nrows, nr);
101 ncols = min (ncols, nc);