1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
## Copyright (C) 2009-2025 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 3 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
## this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn{function file} @var{celladdr} = calccelladdress (@var{row}, @var{column})
##
## calccelladdress (row, column) - compute spreadsheet style cell address from
## row & column index (both 1-based).
##
## Max column index currently set to 18278 (max ODS: 1024, OOXML: 16384).
## Row limits for ODF and OOXML are 65536 and 1048576, resp.
##
## @end deftypefn
## Author: Philip Nienhuis <prnienhuis at users.sf.net>
## Created: 2009-12-12
function [ celladdress ] = calccelladdress (row, column)
if (nargin < 2)
error ("calccelladdress: Two arguments needed");
endif
if (column > 18278 || column < 1)
error ("calccelladdress: specified column out of range (1..18278)");
endif
if (row > 1048576 || row < 1)
error ("calccelladdress: specified row out of range (1..1048576)");
endif
celladdress = sprintf ("%s%d", num2col (column), row);
endfunction
%!test
%! a = calccelladdress (1, 1);
%! assert (a, "A1");
%!test
%! a = calccelladdress (378, 28);
%! assert (a, "AB378");
%!test
%! a = calccelladdress (65536, 1024);
%! assert (a, "AMJ65536");
%!test
%! a = calccelladdress (1048576, 16384);
%! assert (a, "XFD1048576");
%!test
%! a = calccelladdress (378, 26);
%! assert (a, "Z378");
%!test
%! a = calccelladdress (378, 702);
%! assert (a, "ZZ378");
%!test
%! a = calccelladdress (378, 701);
%! assert (a, "ZY378");
%!test
%! a = calccelladdress (378, 703);
%! assert (a, "AAA378");
%!test
%! a = calccelladdress (378, 676);
%! assert (a, "YZ378");
|