From: <prn...@us...> - 2011-01-03 20:39:25
|
Revision: 8047 http://octave.svn.sourceforge.net/octave/?rev=8047&view=rev Author: prnienhuis Date: 2011-01-03 20:39:19 +0000 (Mon, 03 Jan 2011) Log Message: ----------- Updates & corrections to info header text Modified Paths: -------------- trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2011-01-03 20:37:55 UTC (rev 8046) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2011-01-03 20:39:19 UTC (rev 8047) @@ -21,7 +21,7 @@ ## @deftypefnx {Function File} [ @var{rawarr}, @var{ods}, @var{rstatus} ] = ods2oct (@var{ods}, @var{wsh}, @var{range}, @var{options}) ## ## Read data contained within range @var{range} from worksheet @var{wsh} -## in an OpenOffice.org spreadsheet file pointed to in struct @var{ods}. +## in an OpenOffice_org spreadsheet file pointed to in struct @var{ods}. ## ## @var{wsh} is either numerical or text, in the latter case it is ## case-sensitive and it may be max. 31 characters long. @@ -111,6 +111,7 @@ ## 2010-08-27 Added ods3jotk2oct - internal function for odfdom-0.8.6.jar ## " Extended check on spsh_opts (must be a struct) ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to here +## 2010-12-06 Textual changes to info header ## ## (Latest update of subfunctions below: 2010-11-13) Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-01-03 20:37:55 UTC (rev 8046) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-01-03 20:39:19 UTC (rev 8047) @@ -19,7 +19,7 @@ ## @deftypefnx {Function File} @var{ods} = odsopen (@var{filename}, @var{readwrite}) ## @deftypefnx {Function File} @var{ods} = odsopen (@var{filename}, @var{readwrite}, @var{reqintf}) ## Get a pointer to an OpenOffice_org spreadsheet in the form of return -## argument @var{ods}. +## argument (file pointer struct) @var{ods}. ## ## Calling odsopen without specifying a return argument is fairly useless! ## @@ -76,6 +76,7 @@ ## 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 +## 2010-12-06 Textual changes to info header ## ## Latest change on subfunction below: 2010-09-27 Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-01-03 20:37:55 UTC (rev 8046) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-01-03 20:39:19 UTC (rev 8047) @@ -19,8 +19,8 @@ ## @deftypefnx {Function File} @var{xls} = xlsopen (@var{filename}, @var{readwrite}) ## @deftypefnx {Function File} @var{xls} = xlsopen (@var{filename}, @var{readwrite}, @var{reqintf}) ## Get a pointer to an Excel spreadsheet in the form of return argument -## @var{xls}. After processing the spreadsheet, the file pointer must be -## explicitly closed calling xlsclose(). +## (file pointer struct) @var{xls}. After processing the spreadsheet, +## the file pointer must be explicitly closed by calling xlsclose(). ## ## Calling xlsopen without specifying a return argument is fairly useless! ## @@ -87,6 +87,8 @@ ## 2010-11-05 Slight change to reporting to screen ## 2010-11-08 Tested with POI 3.7 (OK) ## 2010-11-10 Texinfo header updated +## 2010-12-01 Small bugfix - reset xlssupport in l. 102 +## 2010-12-06 Textual changes to info header ## ## 2010-11-05 Latest subfunction update @@ -98,6 +100,7 @@ xlsinterfaces = struct ( "COM", [], "POI", [], "JXL", [] ); chkintf = 1; endif + xlssupport = 0; if (nargout < 1) usage ("XLS = xlsopen (Xlfile [, Rw] [, reqintf]). But no return argument specified!"); @@ -106,7 +109,7 @@ usage ("Numerical or logical value expected for arg # 2") endif if (~isempty (reqinterface)) - if ~(ischar (reqinterface) || iscell(reqinterface)), usage ("Arg # 3 not recognized"); endif + if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif # Turn arg3 into cell array if needed if (~iscell (reqinterface)), reqinterface = {reqinterface}; endif xlsinterfaces.COM = 0; xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; @@ -121,7 +124,7 @@ elseif (strcmp (reqintf, 'JXL')) xlsinterfaces.JXL = []; else - usage (sprintf ("Unknown .xls interface \"%s\" requested. Only COM, POI or JXL supported", reqinterface{})); + usage (sprintf ("Unknown .xls interface \"%s\" requested. Only COM, POI or JXL supported\n", reqinterface{})); endif endfor printf ("Checking interface(s):\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-01-03 20:40:03
|
Revision: 8048 http://octave.svn.sourceforge.net/octave/?rev=8048&view=rev Author: prnienhuis Date: 2011-01-03 20:39:57 +0000 (Mon, 03 Jan 2011) Log Message: ----------- Small bugfixes + info header text corrections Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsclose.m Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-01-03 20:39:19 UTC (rev 8047) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-01-03 20:39:57 UTC (rev 8048) @@ -100,6 +100,7 @@ ## 2010-08-25 Improved help text (section on java memory usage) ## 2010-11-12 Moved ptr struct check into main func. More input validity checks ## 2010-11-13 Added check for 2-D input array +## 2010-12-01 Better check on file pointer struct (ischar (xls.xtype)) ## Last script file update (incl. subfunctions): 2011-11-12 @@ -120,11 +121,13 @@ error ("oct2xls: input array neither cell nor numeric array"); endif if (ndims (c_arr) > 2), error ("Only 2-dimensional arrays can be written to spreadsheet"); 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 Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-01-03 20:39:19 UTC (rev 8047) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-01-03 20:39:57 UTC (rev 8048) @@ -126,12 +126,13 @@ test1 = test1 || isempty (xls.workbook); test1 = test1 || isempty (xls.app); if test1 - error ("Invalid xls file struct"); + 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 & setup options struct if (nargin < 4 || isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; Modified: trunk/octave-forge/main/io/inst/xlsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsclose.m 2011-01-03 20:39:19 UTC (rev 8047) +++ trunk/octave-forge/main/io/inst/xlsclose.m 2011-01-03 20:39:57 UTC (rev 8048) @@ -77,7 +77,7 @@ warning ("JXL doesn't support changing filename, new filename ignored."); elseif ~(strcmp (xls.xtype, 'COM') || strmatch ('.xls', filename)) # Excel / ActiveX will write any filename extension - error ('No .xls or .xlsx filename extension specified'); + error ('No .xls or .xlsx extension lacking in filename %s', filename); else ### For multi-user environments, uncomment below AND relevant stanza in xlsopen # In case of COM, be sure to first close the open workbook This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-02-15 21:52:56
|
Revision: 8116 http://octave.svn.sourceforge.net/octave/?rev=8116&view=rev Author: prnienhuis Date: 2011-02-15 21:52:49 +0000 (Tue, 15 Feb 2011) Log Message: ----------- Adapted to new java-1.2.8 javaclasspath() calling style Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-02-14 22:14:26 UTC (rev 8115) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-02-15 21:52:49 UTC (rev 8116) @@ -78,7 +78,7 @@ ## " Added try-catch to file open sections to create fallback to other intf ## 2010-12-06 Textual changes to info header ## -## Latest change on subfunction below: 2010-09-27 +## Latest change on subfunction below: 2011-02-15 function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) @@ -181,7 +181,7 @@ ods.odfvsn = odsinterfaces.odfvsn; odssupport += 1; catch - if (xlsinterfaces.JOD && ~rw && chk2) + 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); @@ -301,6 +301,7 @@ ## " Rearranged code a bit; fixed typos in OTK detection code (odfdvsn -> odfvsn) ## 2010-09-27 More code cleanup ## 2010-11-12 Warning added about waning support for odfdom v. 0.7.5 +## 2011-02-15 Adapted to new java-1.2.8 javaclasspath() calling style function [odsinterfaces] = getodsinterfaces (odsinterfaces) @@ -313,7 +314,8 @@ # Check Java support try - tmp1 = javaclasspath; + tmp1 = javaclasspath ('-all'); # For java pkg > 1.2.7 + if (isempty (tmp1)), tmp1 = javaclasspath; endif # For java pkg < 1.2.8 # If we get here, at least Java works. Now check for proper entries # in class path. Under *nix the classpath must first be split up if (isunix) tmp1 = strsplit (char(tmp1), ":"); endif @@ -323,7 +325,7 @@ # No Java support odsinterfaces.OTK = 0; odsinterfaces.JOD = 0; - if ~(isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL)) + if ~(isempty (odsinterfaces.POI) && isempty (odsinterfaces.JXL)) # Some Java-based interface requested but Java support is absent error ('No Java support found.'); else Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-02-14 22:14:26 UTC (rev 8115) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-02-15 21:52:49 UTC (rev 8116) @@ -90,7 +90,7 @@ ## 2010-12-01 Small bugfix - reset xlssupport in l. 102 ## 2010-12-06 Textual changes to info header ## -## 2010-11-05 Latest subfunction update +## 2011-02-15 Latest subfunction update function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) @@ -340,6 +340,7 @@ ## 2010-09-27 More code cleanup ## 2010-10-20 Added check for minimum Java version (should be >= 6 / 1.6) ## 2010-11-05 Slight change to reporting to screen +## 2011-02-15 Adapted to javaclasspath calling style of java-1.2.8 pkg function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) @@ -372,7 +373,8 @@ if (isempty (tmp1)) # Check Java support. First try javaclasspath try - jcp = javaclasspath; + 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, '.'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-03-04 16:34:09
|
Revision: 8149 http://octave.svn.sourceforge.net/octave/?rev=8149&view=rev Author: prnienhuis Date: 2011-03-04 16:34:02 +0000 (Fri, 04 Mar 2011) Log Message: ----------- Minor textual changes in header Modified Paths: -------------- trunk/octave-forge/main/io/inst/calccelladdress.m trunk/octave-forge/main/io/inst/getusedrange.m trunk/octave-forge/main/io/inst/odsfinfo.m Modified: trunk/octave-forge/main/io/inst/calccelladdress.m =================================================================== --- trunk/octave-forge/main/io/inst/calccelladdress.m 2011-03-04 15:45:38 UTC (rev 8148) +++ trunk/octave-forge/main/io/inst/calccelladdress.m 2011-03-04 16:34:02 UTC (rev 8149) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip +## Copyright (C) 2009,2010,2011 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 @@ -14,7 +14,7 @@ ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. -## Compute spreadsheet style cell address from row & column index (both 1-based). +## Compute spreadsheet style cell address from 1-based row & column index. ## ## Max column index: 18278 (max ODS: 1024, OOXML: 16384). ## Max row index 1048576 (max ODS 1.2: 65536; OOXML / ODS 1.2-extended: 1048576). @@ -26,7 +26,7 @@ ## 2010-03-17 Simplified argument list, only row + column needed ## 2010-09-27 Made error message more comprehensible ## 2010-10-11 Added check for row range -## 2011-03-01 Textual fixes in header +## 2011-03-04 Textual fixes in header function [ celladdress ] = calccelladdress (row, column) Modified: trunk/octave-forge/main/io/inst/getusedrange.m =================================================================== --- trunk/octave-forge/main/io/inst/getusedrange.m 2011-03-04 15:45:38 UTC (rev 8148) +++ trunk/octave-forge/main/io/inst/getusedrange.m 2011-03-04 16:34:02 UTC (rev 8149) @@ -16,9 +16,8 @@ ## -*- texinfo -*- ## @deftypefn {Function File} [ @var{toprow#}, @var{bottomrow#}, @var{leftcol#}, @var{rightcol#} ] = getusedrange (@var{spptr}, @var{shindex#}) -## Find occupied data range in worksheet @var{shindex#} in a spreadsheet -## pointed to in struct @var{spptr} (either MS-Excel or -## OpenOffice Calc). +## Find occupied data range in a specific worksheet in a spreadsheet +## (either MS-Excel or OOo Calc). ## ## @var{shindex#} must be numeric and is 1-based. @var{spptr} can either ## refer to an MS-Excel spreadsheet (spptr returned by xlsopen) or an @@ -61,6 +60,7 @@ ## 2010-08-27 Added checks for input arguments ## " Indentation changed from tab to doublespace ## 2010-10-07 Added COM support (at last!) +## 2010-03-04 Textual adaptations in header ## ## Last subfunc update: 2010-12-01 (COM) Modified: trunk/octave-forge/main/io/inst/odsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/odsfinfo.m 2011-03-04 15:45:38 UTC (rev 8148) +++ trunk/octave-forge/main/io/inst/odsfinfo.m 2011-03-04 16:34:02 UTC (rev 8149) @@ -17,7 +17,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} [@var{filetype}] = odsfinfo (@var{filename} [, @var{reqintf}]) ## @deftypefnx {Function File} [@var{filetype}, @var{sh_names}] = odsfinfo (@var{filename} [, @var{reqintf}]) -## Query an OpenOffice_org spreadsheet file @var{filename} (with .ods +## Query an OpenOffice_org Calc spreadsheet file @var{filename} (with ods ## suffix) for some info about its contents. ## ## If @var{filename} is a recognizable OpenOffice.org spreadsheet file, @@ -70,6 +70,7 @@ ## 2010-03-20 "Beautified" output (for OTK ), used range now in more tabular form ## 2010-05-23 Updated jOpenDocument support (can also get occupied data range now) ## 2010-05-31 Added remark about delays when determining occupied data range +## 2011-03-04 Minor textual header change (deleted a ".") function [ filetype, sheetnames ] = odsfinfo (filename, reqintf=[]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-03-28 20:29:34
|
Revision: 8188 http://octave.svn.sourceforge.net/octave/?rev=8188&view=rev Author: prnienhuis Date: 2011-03-28 20:29:28 +0000 (Mon, 28 Mar 2011) Log Message: ----------- OpenXLS support added Modified Paths: -------------- trunk/octave-forge/main/io/inst/getusedrange.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsclose.m trunk/octave-forge/main/io/inst/xlsfinfo.m Modified: trunk/octave-forge/main/io/inst/getusedrange.m =================================================================== --- trunk/octave-forge/main/io/inst/getusedrange.m 2011-03-28 20:28:49 UTC (rev 8187) +++ trunk/octave-forge/main/io/inst/getusedrange.m 2011-03-28 20:29:28 UTC (rev 8188) @@ -1,4 +1,4 @@ -## Copyright (C) 2010 Philip Nienhuis, pr....@us... +## Copyright (C) 2010,2011 Philip Nienhuis, pr....@us... ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -16,8 +16,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} [ @var{toprow#}, @var{bottomrow#}, @var{leftcol#}, @var{rightcol#} ] = getusedrange (@var{spptr}, @var{shindex#}) -## Find occupied data range in a specific worksheet in a spreadsheet -## (either MS-Excel or OOo Calc). +## Find occupied data range in worksheet @var{shindex#} in a spreadsheet +## pointed to in struct @var{spptr} (either MS-Excel or +## OpenOffice Calc). ## ## @var{shindex#} must be numeric and is 1-based. @var{spptr} can either ## refer to an MS-Excel spreadsheet (spptr returned by xlsopen) or an @@ -60,9 +61,9 @@ ## 2010-08-27 Added checks for input arguments ## " Indentation changed from tab to doublespace ## 2010-10-07 Added COM support (at last!) -## 2010-03-04 Textual adaptations in header +## 2011-03-26 Added OpenXLS support ## -## Last subfunc update: 2010-12-01 (COM) +## Last subfunc update: 2011-03-26 (OXS) function [ trow, lrow, lcol, rcol ] = getusedrange (spptr, ii) @@ -79,6 +80,8 @@ [ trow, lrow, lcol, rcol ] = getusedrange_poi (spptr, ii); elseif (strcmp (spptr.xtype, 'JXL')) [ trow, lrow, lcol, rcol ] = getusedrange_jxl (spptr, ii); + elseif (strcmp (spptr.xtype, 'OXS')) + [ trow, lrow, lcol, rcol ] = getusedrange_oxs (spptr, ii); else error ('Only OTK, JOD, POI and JXL interface implemented'); endif @@ -114,12 +117,16 @@ ## 2010-11-13 Catched jOpenDocument bug (1.2bx) where string cells have no office:value-type ## attrib set (by JOD). Somehow OTK is more robust as it catches these cells; ## Currently this fix is just commented. +## 2011-03-23 Adapted to odfdom 0.8.7 (getXPath method call changed) function [ trow, lrow, lcol, rcol ] = getusedrange_otk (ods, ii) odfcont = ods.workbook; # Local copy just in case - - xpath = ods.app.getXPath; + if (strcmp (ods.odfvsn, '0.8.7')) + 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'); # Get table-rows in sheet no. wsh. Sheet count = 1-based (!) @@ -483,3 +490,41 @@ endif endfunction + + +## Copyright (C) 2011 Philip Nienhuis <prnienhuis at users.sf.net> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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/>. + +## getusedrange_oxs - get occupied data cell range from Excel sheet +## using java/OpenXLS + +## Author: Philip Nienhuis +## Created: 2011-03-26 + +function [ trow, brow, lcol, rcol ] = getusedrange_oxs (xls, wsh) + + sh = xls.workbook.getWorkSheet (wsh - 1); # OXS sheet count 0-based + if (sh.getNumRows) + trow = sh.getFirstRow () + 1; + brow = sh.getLastRow (); + lcol = sh.getFirstCol () + 1; + rcol = sh.getLastCol (); + else + # Might be a chart sheet + trow = brow = lcol = rcol = 0; + endif + +endfunction Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-03-28 20:28:49 UTC (rev 8187) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-03-28 20:29:28 UTC (rev 8188) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -114,8 +114,9 @@ ## 2010-11-07 More rigorous input checks. ## 2010-11-12 Moved pointer check into main func ## 2010-11-13 Catch empty sheets when no range was specified +## 2011-03-26 OpenXLS support added ## -## Latest subfunc update: 2010-11-14 (poi) +## Latest subfunc update: 2011-03-26 (OXS) function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) @@ -157,6 +158,9 @@ elseif (strcmp (xls.xtype, 'JXL')) # Read xls file tru JExcelAPI [rawarr, xls, rstatus] = xls2jxla2oct (xls, wsh, datrange, spsh_opts); + elseif (strcmp (xls.xtype, 'OXS')) + # Read xls file tru OpenXLS + [rawarr, xls, rstatus] = xls2oxs2oct (xls, wsh, datrange, spsh_opts); # elseif ---- <Other interfaces here> # Call to next interface else @@ -724,3 +728,112 @@ xls.limits = [lcol, rcol; firstrow, lastrow]; endfunction + + +## Copyright (C) 2011 Philip Nienhuis <prnienhuis at users.sf.net> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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{obj}, @var{rstatus}, @var{xls} ] = xls2oxs2oct (@var{xls}) +## @deftypefnx {Function File} [@var{obj}, @var{rstatus}, @var{xls} ] = xls2oxs2oct (@var{xls}, @var{wsh}) +## @deftypefnx {Function File} [@var{obj}, @var{rstatus}, @var{xls} ] = xls2oxs2oct (@var{xls}, @var{wsh}, @var{range}) +## Get cell contents in @var{range} in worksheet @var{wsh} in an Excel +## file pointed to in struct @var{xls} into the cell array @var{obj}. +## @var{range} can be a range or just the top left cell of the range. +## +## xls2oxs2oct should not be invoked directly but rather through xls2oct. +## + +## Author: Philip Nienhuis +## Created: 2011-03-26 +## Updates: + +function [ rawarr, xls, status ] = xls2oxs2oct (xls, wsh, cellrange=[], spsh_opts) + + persistent ctype; + if (isempty (ctype)) + ctype = cell (11, 1); + # Get enumerated cell types. Beware as they start at 0 not 1 + ctype( 1) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_STRING')); + ctype( 2) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FP')); + ctype( 3) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_INT')); + ctype( 4) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FORMULA')); + ctype( 5) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_BOOLEAN')); + ctype( 6) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_DOUBLE')); + endif + + status = 0; + wb = xls.workbook; + + # 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 + printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); + else + try + sh = wb.getWorkSheet (wsh); + catch + error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); + end_try_catch + end + + if (isempty (cellrange)) + # Get numeric sheet pointer (0-based) + wsh = sh.getTabIndex (); + # Get data rectangle row & column numbers (1-based) + [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh+1); + if (firstrow == 0 && lastrow == 0) + # Empty sheet + rawarr = {}; + printf ("Worksheet '%s' contains no data\n", shnames {wsh}); + rstatus = 1; + return; + else + nrows = lastrow - firstrow + 1; + ncols = rcol - lcol + 1; + endif + else + # 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 + 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 + for jj = lcol:rcol + for ii = firstrow:lastrow + try + scell = sh.getCell (ii-1, jj-1); + sctype = scell.getCellType (); + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getVal (); + if (sctype == ctype(2) || sctype == ctype(3) || sctype == ctype(6)) + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getDoubleVal (); + endif + catch + end_try_catch + endfor + endfor + + status = 1; + xls.limits = [lcol, rcol; firstrow, lastrow]; + +endfunction Modified: trunk/octave-forge/main/io/inst/xlsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsclose.m 2011-03-28 20:28:49 UTC (rev 8187) +++ trunk/octave-forge/main/io/inst/xlsclose.m 2011-03-28 20:29:28 UTC (rev 8188) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -9,7 +9,7 @@ ## 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/>. @@ -35,7 +35,7 @@ ## with JXL (JExcelAPI) interface. ## ## You need MS-Excel (95 - 2010), and/or the Java package > 1.2.6 plus Apache -## POI > 3.5 and/or JExcelAPI installed on your computer + proper +## POI > 3.5 and/or JExcelAPI and/or OpenXLS installed on your computer + proper ## javaclasspath set, to make this function work at all. ## ## @var{xls} must be a valid pointer struct made by xlsopen() in the same @@ -65,6 +65,7 @@ ## " untouched file ptr struct in case of errors rather than wipe it ## 2010-11-12 Replaced 'keepxls' by new filename arg; catch write errors and ## always keep file pointer in case of write errors +## 2011-03-26 Added OpenXLS support function [ xls ] = xlsclose (xls, filename=[]) @@ -136,8 +137,11 @@ if (xls.changed > 0 && xls.changed < 3) try xlsout = java_new ("java.io.FileOutputStream", xls.filename); + bufout = java_new ("java.io.BufferedOutputStream", xlsout); if (xls.changed == 2) printf ("Saving file %s...\n", xls.filename); endif - xls.workbook.write (xlsout); + xls.workbook.write (bufout); + bufout.flush (); + bufout.close (); xlsout.close (); xls.changed = 0; catch @@ -162,6 +166,25 @@ end_try_catch endif + elseif (strcmp (xls.xtype, 'OXS')) + if (xls.changed > 0 && xls.changed < 3) + try + xlsout = java_new ("java.io.FileOutputStream", xls.filename); + bufout = java_new ("java.io.BufferedOutputStream", xlsout); + if (xls.changed == 2) printf ("Saving file %s...\n", xls.filename); endif + xls.workbook.writeBytes (bufout); + xls.workbook.close (); + bufout.flush (); + bufout.close (); + xlsout.close (); + xls.changed = 0; + catch +# xlsout.close (); + end_try_catch + else + xls.workbook.close (); + endif + # elseif <other interfaces here> endif Modified: trunk/octave-forge/main/io/inst/xlsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-03-28 20:28:49 UTC (rev 8187) +++ trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-03-28 20:29:28 UTC (rev 8188) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -80,6 +80,7 @@ ## " Added occupieded range echo for COM interface (may be a bit off too) ## 2010-10-10 Made output arg2 contain only address ranges (or other sheet type names) ## 2010-11-01 Added other file type strings for return arg #3 (fformat) +## 2011-03-26 Added OpenXLS support function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[]) @@ -166,6 +167,22 @@ endif endfor if (sh_cnt > 0) fformat = "xlWorkbookNormal"; else, fformat = ''; endif + + elseif (strcmp (xls.xtype, 'OXS')) + 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_names(ii, 1) = char (sh.getSheetName()); + # 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)); + else + sh_names(ii, 2) = "Empty or Chart"; + endif + endfor + if (sh_cnt > 0) fformat = "xlWorkbookNormal"; else, fformat = ''; endif # elseif <Other Excel interfaces below> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-04-21 22:01:03
|
Revision: 8226 http://octave.svn.sourceforge.net/octave/?rev=8226&view=rev Author: prnienhuis Date: 2011-04-21 22:00:57 +0000 (Thu, 21 Apr 2011) Log Message: ----------- Tests added Modified Paths: -------------- trunk/octave-forge/main/io/inst/calccelladdress.m trunk/octave-forge/main/io/inst/parse_sp_range.m Modified: trunk/octave-forge/main/io/inst/calccelladdress.m =================================================================== --- trunk/octave-forge/main/io/inst/calccelladdress.m 2011-04-21 21:01:50 UTC (rev 8225) +++ trunk/octave-forge/main/io/inst/calccelladdress.m 2011-04-21 22:00:57 UTC (rev 8226) @@ -14,10 +14,11 @@ ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. -## Compute spreadsheet style cell address from 1-based row & column index. +## calccelladdress (R, C) - compute spreadsheet style cell address from +## row & column index (both 1-based). ## -## Max column index: 18278 (max ODS: 1024, OOXML: 16384). -## Max row index 1048576 (max ODS 1.2: 65536; OOXML / ODS 1.2-extended: 1048576). +## Max column index currently set to 18278 (max ODS: 1024, OOXML: 16384). +## Row limits for ODF and OOXML are 65536 and 1048576, resp. ## Author: Philip Nienhuis <prnienhuis at users.sf.net> ## Created: 2009-12-12 @@ -26,7 +27,6 @@ ## 2010-03-17 Simplified argument list, only row + column needed ## 2010-09-27 Made error message more comprehensible ## 2010-10-11 Added check for row range -## 2011-03-04 Textual fixes in header function [ celladdress ] = calccelladdress (row, column) @@ -48,4 +48,20 @@ endif celladdress = sprintf ("%s%d", str, row); -endfunction \ No newline at end of file +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'); Modified: trunk/octave-forge/main/io/inst/parse_sp_range.m =================================================================== --- trunk/octave-forge/main/io/inst/parse_sp_range.m 2011-04-21 21:01:50 UTC (rev 8225) +++ trunk/octave-forge/main/io/inst/parse_sp_range.m 2011-04-21 22:00:57 UTC (rev 8226) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009-2011 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -100,3 +100,20 @@ endif endfunction + +%!test +%! [a b c d e] = parse_sp_range ('A1:B2'); +%! assert ([a b c d e], ['A1', 2, 2, 1, 1]); + +%!test +%! [a b c d e] = parse_sp_range ('A1:AB200'); +%! assert ([a b c d e], ['A1', 200, 28, 1, 1]); + +%!test +%! [a b c d e] = parse_sp_range ('cd230:iY65536'); +%! assert ([a b c d e], ['CD230', 65307, 178, 230, 82]); + +%!test +%! [a b c d e] = parse_sp_range ('BvV12798 : xFd1054786'); +%! assert ([b c d e], [1041989, 14439, 12798, 1946]); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-05-06 14:39:05
|
Revision: 8246 http://octave.svn.sourceforge.net/octave/?rev=8246&view=rev Author: prnienhuis Date: 2011-05-06 14:38:58 +0000 (Fri, 06 May 2011) Log Message: ----------- strfind call bug fixes; experimental UNO support (currently only reading) Modified Paths: -------------- trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m trunk/octave-forge/main/io/inst/odsclose.m trunk/octave-forge/main/io/inst/odsopen.m Modified: trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m =================================================================== --- trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m 2011-05-06 12:24:17 UTC (rev 8245) +++ trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m 2011-05-06 14:38:58 UTC (rev 8246) @@ -1,15 +1,26 @@ % Check Octave / Matlab environment for spreadsheet I/O support. % -% usage: [ RETVAL ] = chk_spreadsheet_support ( [/PATH/TO/JARS], [,DEBUG_LEVEL] ) +% usage: [ RETVAL ] = chk_spreadsheet_support ( [/PATH/TO/JARS], [,DEBUG_LEVEL] [,PATH_TO_OOO]) % -% /PATH/TO/JARS = path (relative or absolute) to a subdirectory where -% java class libraries (.jar) for spreadsheet I/O reside -% DEBUG_LEVEL = integer between [0 (no output) .. 3 (full output] -% returns: +% Input arguments (all are optional): +% /PATH/TO/JARS = (string) path (relative or absolute) to a +% subdirectory where java class libraries (.jar) +% for spreadsheet I/O reside +% DEBUG_LEVEL = (integer) between [0 (no output) .. 3 (full output] +% PATH_TO_OOO = (string) installation directory of Openffice.org, +% usually (but not guaranteed): +% - Windows: C:\Program Files\OpenOffice.org +% - *nix: /usr/lib/ooo +% - Mac OSX: ????? +% IMPORTANT: PATH_TO_OOO should be such that both: +% 1. PATH_TO_OOO/program/ and +% 2. PATH_TO_OOO/ure/share/java/ridl.jar +% resolve OK +% Returns: % RETVAL = 0 No spreadsheet I/O support found % = 1 At least one spreadsheet I/O interface found % -% CHK_SPREADSHEET_SUPPORT first check ActiveX (native MS-Excel); then +% CHK_SPREADSHEET_SUPPORT first checks ActiveX (native MS-Excel); then % Java JRE presence, then Java support (builtin/activated - Matlab or % added tru octave-forge Java package (Octave); then check existing % javaclasspath for Java class libraries (.jar) needed for spreadsheet @@ -18,9 +29,11 @@ % javaclasspath. In that case the path name to the directory % containing these classes should be specified as input argument % with -TAKE NOTICE- /forward/ slashes. -% A second optional argument is the default debug level +% A second (optional) argument is the default debug level. +% A third (optional) argument is the installation directory of +% OpenOffice.org or clones. -function [ retval ] = chk_spreadsheet_support (path_to_jars, dbug=0) +function [ retval ] = chk_spreadsheet_support (path_to_jars, dbug, path_to_ooo) % Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> % @@ -46,12 +59,14 @@ % 2011-01-04 Adapted for general checks, debugging & set up, both Octave & ML % 2011-04-04 Rebuilt into general setup/debug tool for spreadsheet I/O support % and renamed chk_spreadsheet_support() -% +% 2011-05-04 Added in UNO support (OpenOffice.org & clones) +% '' Improved finding jar names in javaclasspath +% 2011-05-07 Improved help text jcp = []; retval = 0; + if (nargin < 2), dbug = 0; end %if isOctave = exist ('OCTAVE_VERSION', 'builtin') ~= 0; if (ispc), filesep = '\'; else, filesep = '/'; end %if - dbug = min (max (dbug, 0), 3); fprintf ('\n'); % Check if MS-Excel COM ActiveX server runs @@ -63,12 +78,11 @@ % Close Excel to avoid zombie Excel invocation app.Quit(); delete(app); - if (dbug), fprintf ('OK.\n\n'); end %if - retval = 1; + if (dbug), fprintf ('OK.\n\n'); retval = 1; end %if catch % COM not supported if (dbug), fprintf ('not working.\n\n'); end %if - end_try_catch + end %try_catch % Check Java if (dbug), fprintf ('Checking Java support...\n'); end %if @@ -76,24 +90,25 @@ % Try if Java is installed at all if (isOctave) if (ispc) - jtst = (!system ('java -version 2> nul')); + jtst = (system ('java -version 2> nul')); else - jtst = (!system ('java -version 2> /dev/null')); + jtst = (system ('java -version 2> /dev/null')); end %if else - jtst = (version -java) + tst1 = version ('-java'); + jtst = isempty (strfind (tst1, 'Java')); end %if - if (~jtst) - error ("\nApparently no Java JRE installed."); + if (jtst) + error ('Apparently no Java JRE installed.'); else if (dbug > 1), fprintf ('OK, found one.\n'); end %if end %if - if (dbug > 1), fprintf (' 2. Checking Octave Java support... '); end %if + if (dbug > 1 && isOctave), fprintf (' 2. Checking Octave Java support... '); end %if try - jcp = javaclasspath ('-all'); # For Octave java pkg > 1.2.7 - if (isempty (jcp)), jcp = javaclasspath; endif # For Octave java pkg < 1.2.8 + jcp = javaclasspath ('-all'); %# For Octave java pkg > 1.2.7 + if (isempty (jcp)), jcp = javaclasspath; end %if %# For Octave java pkg < 1.2.8 % If we get here, at least Java works. - if (dbug > 1), fprintf ('Java package seems to work OK.\n'); end %if + if (dbug > 1 && isOctave), fprintf ('Java package seems to work OK.\n'); end %if % Now check for proper version % (> 1.6.x.x) jver = char (javaMethod ('getProperty', 'java.lang.System', 'java.version')); @@ -117,8 +132,9 @@ if (isunix) jcp = strsplit (char (jcp), ':'); end %if if (dbug > 1) % Check JVM virtual memory settings - jmem = javaMethod ('getRuntime', 'java.lang.Runtime'); - jmem = jmem.maxMemory().doubleValue(); + jrt = javaMethod ('getRuntime', 'java.lang.Runtime'); + jmem = jrt.maxMemory (); + if (isOctave), jmem = jmem.doubleValue(); end %if jmem = int16 (jmem/1024/1024); fprintf (' Maximum JVM memory: %5d MiB; ', jmem); if (jmem < 400) @@ -134,14 +150,53 @@ end %if end %if if (dbug), fprintf ('Java support OK\n'); end %if - catch + catch error ('No Java support found.'); end %try_catch - if (dbug), fprintf ('\nChecking javaclasspath for .jar libraries needed for spreadsheet I/O...:\n'); end %if + if (dbug), fprintf ('\nChecking javaclasspath for .jar class libraries needed for spreadsheet I/O...:\n'); end %if + % Try Java & UNO + if (dbug > 1), fprintf ('UNO/Java (.ods, .xls, .xlsx, .sxc) <OpenOffice.org>:\n'); end %if + # entries0(1) = not a jar but a directory (<000_install_dir/program/>) + jpchk = 0; entries0 = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + missing0 = zeros (1, numel (entries0)); + % Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) + % as javaclasspath is one long string. Under Windows however classpath is a cell array + % so we need the following more subtle, platform-independent approach: + for jj=1:numel (entries0) + found = 0; + for ii=1:numel (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries0{jj})))) + jpchk = jpchk + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end %if + end %for + if (~found) + if (dbug > 2) + if (jj == 1) + # Just a dir + fprintf (' %s.... (directory) not found\n', entries0{jj}); + else + fprintf (' %s....jar missing\n', entries0{jj}); + end %if + end %if + missing0(jj) = 1; + end %if + end %for + if (dbug > 1) + if (jpchk >= numel (entries0)) + fprintf (' => UNO (OOo) OK\n'); + retval = 1; + else + fprintf (' => One or more UNO classes (.jar) missing in javaclasspath\n'); + end %if + end %if + % Try Java & Apache POI. First Check basic .xls (BIFF8) support - if (dbug > 1), fprintf ('Basic POI (.xls) <poi-3> <poi-ooxml>:\n'); end %if + if (dbug > 1), fprintf ('\nBasic POI (.xls) <poi-3> <poi-ooxml>:\n'); end %if jpchk1 = 0; entries1 = {'poi-3', 'poi-ooxml-3'}; missing1 = zeros (1, numel (entries1)); % Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) % as javaclasspath is one long string. Under Windows however classpath is a cell array @@ -149,7 +204,9 @@ for jj=1:length (entries1) found = 0; for ii=1:length (jcp) - if (strfind (lower (jcp{ii}), lower (entries1{jj}))) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries1{jj})))) jpchk1 = jpchk1 + 1; found = 1; if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if end %if @@ -159,10 +216,10 @@ missing1(jj) = 1; end %if end %for - retval = jpchk1 > 1; if (dbug > 1) - if (jpchk1 > 1) + if (jpchk1 >= numel (entries1)) fprintf (' => Apache (POI) OK\n'); + retval = 1; else fprintf (' => Not all classes (.jar) required for POI in classpath\n'); end %if @@ -174,7 +231,9 @@ for jj=1:length (entries2) found = 0; for ii=1:length (jcp) - if (strfind (lower (jcp{ii}), lower (entries2{jj}))) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries2{jj})))) jpchk2 = jpchk2 + 1; found = 1; if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if end %if @@ -185,7 +244,7 @@ end %if end % for if (dbug > 1) - if (jpchk2 > 2) + if (jpchk2 >= numel (entries2)) fprintf (' => POI OOXML OK\n'); else fprintf (' => Some classes for POI OOXML support missing\n'); @@ -198,7 +257,9 @@ for jj=1:length (entries3) found = 0; for ii=1:length (jcp) - if (strfind (lower (jcp{ii}), lower (entries3{jj}))) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries3{jj})))) jpchk = jpchk + 1; found = 1; if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if end % if @@ -208,9 +269,8 @@ missing3(jj) = 1; end %if end %for - retval = jpchk > 0; if (dbug > 1) - if (jpchk > 0) + if (jpchk >= numel (entries3)) fprintf (' => Java/JExcelAPI (JXL) OK.\n'); retval = 1; else @@ -218,13 +278,15 @@ end %if end %if - % Try Java & OpenXLS (experimental) - if (dbug > 1), fprintf ('\nOpenXLS (.xls (BIFF8)) <OpenXLS> (experimental):\n'); end %if + % Try Java & OpenXLS + if (dbug > 1), fprintf ('\nOpenXLS (.xls (BIFF8)) <OpenXLS>:\n'); end %if jpchk = 0; entries6 = {'OpenXLS'}; missing6 = zeros (1, numel (entries3)); for jj=1:length (entries6) found = 0; for ii=1:length (jcp) - if (strfind (lower (jcp{ii}), lower (entries6{jj}))) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries6{jj})))) jpchk = jpchk + 1; found = 1; if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if end % if @@ -234,9 +296,8 @@ missing6(jj) = 1; end %if end %for - retval = jpchk > 0; if (dbug > 1) - if (jpchk > 0) + if (jpchk >= numel (entries6)) fprintf (' => Java/OpenXLS (OXS) OK.\n'); retval = 1; else @@ -253,7 +314,9 @@ for jj=1:length (entries4) found = 0; for ii=1:length (jcp) - if (strfind ( lower (jcp{ii}), lower (entries4{jj}))) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind ( lower (jcpentry), lower (entries4{jj})))) jpchk = jpchk + 1; found = 1; if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if end %if @@ -263,7 +326,7 @@ missing4(jj) = 1; end %if end %for - if (jpchk >= 2) % Apparently all requested classes present. + if (jpchk >= numel (entries4)) % 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 = ' '; @@ -274,8 +337,8 @@ % Worked in 0.7.5 odfvsn = javaMethod ('getApplicationVersion', 'org.odftoolkit.odfdom.Version'); end %try_catch - if ~(strcmp (odfvsn, '0.7.5') || strcmp (odfvsn, '0.8.6') || strcmp (odfvsn, '0.8.7')) - warning (' *** odfdom version (%s) is not supported - use v. 0.7.5, or 0.8.6+.\n', odfvsn); + if ~(strcmp (odfvsn, '0.7.5') || strcmp (odfvsn, '0.8.6')) + warning (' *** odfdom version (%s) is not supported - use v. 0.7.5 or 0.8.6.\n', odfvsn); else if (dbug > 1), fprintf (' => ODFtoolkit (OTK) OK.\n'); end %if retval = 1; @@ -290,7 +353,9 @@ for jj=1:length (entries5) found = 0; for ii=1:length (jcp) - if (strfind (lower (jcp{ii}), lower (entries5{jj}))) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries5{jj})))) jpchk = jpchk + 1; found = 1; if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if end %if @@ -300,15 +365,106 @@ missing5(jj) = 1; end %if end %for - retval = jpchk >= 1; if (dbug > 1) - if (jpchk >= 1) + if (jpchk >= numel(entries5)) fprintf (' => jOpenDocument (JOD) OK.\n'); + retval = 1; else fprintf (' => Not all required classes (.jar) in classpath for JOD\n'); end %if end %if + # If requested, try to add UNO stuff to javaclasspath + ujars_complete = isempty (find (missing0)); + if (dbug > 1) + if (ujars_complete) + fprintf ('UNO bridge (OpenOffice.org) supported.\n\n'); + else + fprintf ('Some UNO class libs lacking yet...\n\n'); + end %if + end %if + + if (~ujars_complete && nargin > 0 && ~isempty (path_to_ooo)) + if (dbug), fprintf ('Trying to add missing UNO java class libs to javaclasspath...\n'); end %if + if (~ischar (path_to_jars)), error ('Path expected for arg # 1'); end %if + % Add missing jars to javaclasspath. First combine all entries + targt = sum (missing0); + if (missing0(1)) + # Add program dir (= where soffice or soffice.exe or ooffice resides) + programdir = [path_to_ooo filesep entries0{1}]; + if (fexist (programdir, 'd')) + if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', programdir); end %if + try + javaaddpath (programdir); + targt = targt - 1; + if (dbug > 2), fprintf ('OK\n'); end %if + catch + if (dbug > 2), fprintf ('FAILED\n'); end %if + end% try_catch + else + if (dbug > 2), fprintf (' ? %s directory ?\n', entries0{1}); end %if + end %if + end %if + % Rest of missing entries. Find where URE is located + uredirlst = dir ([path_to_ooo]); + jj = 1; + while (jj < size (uredirlst, 1) && jj > 0) + uredir = uredirlst(jj).name; + if (uredirlst(jj).isdir && ~isempty (strfind (lower (uredirlst(jj).name), 'ure'))) + uredir = uredirlst(jj).name; + jj = 0; + else + ++jj; + endif + endwhile + # Now search for UNO jars + for ii=2:length (entries0) + if (missing0(ii)) + if (ii == 2) + # Special case as unoil.jar usuaally resides in ./Basis.../program/classes + # Find out the exact name of Basis..... + basisdirlst = dir ([path_to_ooo filesep 'basis' '*']); + jj = 1; + while (jj < size (basisdirlst, 1) && jj > 0) + # basisdir = basisdirlst(jj).name; + if (basisdirlst(jj).isdir) + basisdir = basisdirlst(jj).name; + jj = 0; + else + ++jj; + endif + endwhile + unojarpath = [ path_to_ooo filesep basisdir filesep 'program' filesep 'classes' filesep ] + file = dir ([ unojarpath entries0{ii} '*' ]); + else + # Rest of jars in ./ure/share/java (case not sure) + unojarpath = [ path_to_ooo filesep uredir filesep 'java' filesep ]; + file = dir ([unojarpath entries0{ii} '*']); + end %if + if (isempty (file)) + if (dbug > 2), fprintf (' ? %s<...>.jar ?\n', entries0{ii}); end %if + else + if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', file.name); end %if + try + javaaddpath ([unojarpath file.name]); + targt = targt - 1; + if (dbug > 2), fprintf ('OK\n'); end %if + catch + if (dbug > 2), fprintf ('FAILED\n'); end %if + end %try_catch + end %if + end %if + end %for + if (dbug) + if (targt) + fprintf ('Some class libs still lacking...\n\n'); + else + fprintf ('All interfaces fully supported.now.\n\n'); + retval = 1; + end %f + end %if + + # Rest of Java interfaces missing = [missing1 missing2 missing3 missing4 missing5 missing6]; jars_complete = isempty (find (missing)); if (dbug) @@ -319,7 +475,7 @@ end %if end %if - if (~jars_complete && nargin > 0) + if (~jars_complete && nargin > 0 && ~isempty (path_to_jars)) if (dbug), fprintf ('Trying to add missing java class libs to javaclasspath...\n'); end %if if (~ischar (path_to_jars)), error ('Path expected for arg # 1'); end %if % Add missing jars to javaclasspath. First combine all entries @@ -330,15 +486,16 @@ if (missing(ii)) file = dir ([path_to_jars filesep entries{ii} '*']); if (isempty (file)) - if (dbug > 2), fprintf ('\n'); end %if + if (dbug > 2), fprintf (' ? %s<...>.jar ?\n', entries{ii}); end %if else - if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath\n', file.name); end %if + if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', file.name); end %if try javaaddpath ([path_to_jars filesep file.name]); targt = targt - 1; + if (dbug > 2), fprintf ('OK\n'); end %if catch - if (dbug > 2), fprintf ('\n'); end %if - end_try_catch + if (dbug > 2), fprintf ('FAILED\n'); end %if + end% try_catch end %if end %if end %for @@ -348,6 +505,7 @@ else fprintf ('All interfaces fully supported.now.\n\n'); retval = 1; + end %if end %f end %if Modified: trunk/octave-forge/main/io/inst/odsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/odsclose.m 2011-05-06 12:24:17 UTC (rev 8245) +++ trunk/octave-forge/main/io/inst/odsclose.m 2011-05-06 14:38:58 UTC (rev 8246) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -28,6 +28,9 @@ ## You need the Java package > 1.2.6 plus odfdom.jar + xercesImpl.jar ## and/or jopendocument-<version>.jar installed on your computer + ## proper javaclasspath set, to make this function work at all. +## For UNO support, Octave-Java package 1.2.8 + latest fixes is imperative; +## furthermore the relevant classes had best be added to the javaclasspath by +## utility function chk_spreadsheet_support(). ## ## @var{ods} must be a valid pointer struct made by odsopen() in the same ## octave session. @@ -53,6 +56,8 @@ ## 2010-10-27 Improved file change tracking tru ods.changed ## 2010-11-12 Keep ods file pointer when write errors occur. ## " Added optional filename arg to change filename to be written to +## 2011-05-06 Experimental UNO support +## 2011-05-07 Soffice now properly closed using xDesk function [ ods ] = odsclose (ods, filename=[]) @@ -95,6 +100,39 @@ catch end_try_catch + elseif (strcmp (ods.xtype, 'UNO')) + # Java & UNO bridge + try + if (ods.changed && ods.changed < 3) +keyboard + # Workaround: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XModel'); + xModel = ods.workbook.queryInterface (unotmp); + 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() ? + xStore = ods.app.queryInterface (unotmp); + xStore.store; # storeAsURL ? + endif + endif + ods.changed = -1; # Needed for check op properly shutting down OOo + # Workaround: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XModel'); + xModel = ods.app.xComp.queryInterface (unotmp); + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.util.XCloseable'); + xClosbl = xModel.queryInterface (unotmp); + xClosbl.close (true); + # xModel.dispose(); # Is this needed? Consistently gives com.sun.star.lang.DisposedException + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XDesktop'); + xDesk = ods.app.aLoader.queryInterface (unotmp); + xDesk.terminate(); + ods.changed = 0; + catch + warning ("Error closing ods pointer (UNO)"); + return + end_try_catch + # elseif ---- < Other interfaces here > else Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-05-06 12:24:17 UTC (rev 8245) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-05-06 14:38:58 UTC (rev 8246) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ ## @deftypefnx {Function File} @var{ods} = odsopen (@var{filename}, @var{readwrite}) ## @deftypefnx {Function File} @var{ods} = odsopen (@var{filename}, @var{readwrite}, @var{reqintf}) ## Get a pointer to an OpenOffice_org spreadsheet in the form of return -## argument (file pointer struct) @var{ods}. +## argument @var{ods}. ## ## Calling odsopen without specifying a return argument is fairly useless! ## @@ -28,6 +28,9 @@ ## installed on your computer + proper javaclasspath set. These interfaces are ## referred to as OTK and JOD, resp., and are preferred in that order by default ## (depending on their presence). +## For (currently experimental) UNO support, Octave-Java package 1.2.8 + latest +## fixes is imperative; furthermore the relevant classes had best be added to +## the javaclasspath by utility function chk_spreadsheet_support(). ## ## @var{filename} must be a valid .ods OpenOffice.org file name including ## .ods suffix. If @var{filename} does not contain any directory path, @@ -76,15 +79,15 @@ ## 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 -## 2010-12-06 Textual changes to info header +## 2011-05-06 Experimental UNO support ## -## Latest change on subfunction below: 2011-02-15 +## Latest change on subfunction below: 2011-05-06 function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) persistent odsinterfaces; persistent chkintf; if (isempty (chkintf)) - odsinterfaces = struct ( "OTK", [], "JOD", [] ); + odsinterfaces = struct ( "OTK", [], "JOD", [], "UNO", [] ); chkintf = 1; endif @@ -99,10 +102,13 @@ # is supported anyway by emptying the corresponding var. if (strcmp (tolower (reqinterface), tolower ('OTK'))) printf ("Java/ODFtoolkit interface requested... "); - odsinterfaces.OTK = []; odsinterfaces.JOD = 0; + odsinterfaces.OTK = []; odsinterfaces.JOD = 0; odsinterfaces.UNO = 0; elseif (strcmp (tolower (reqinterface), tolower ('JOD'))) printf ("Java/jOpenDocument interface requested... "); - odsinterfaces.OTK = 0; odsinterfaces.JOD = []; + odsinterfaces.OTK = 0; odsinterfaces.JOD = []; odsinterfaces.UNO = 0; + elseif (strcmp (tolower (reqinterface), tolower ('UNO'))) + printf ("Java/UNO bridge interface requested... "); + odsinterfaces.OTK = 0; odsinterfaces.JOD = 0; odsinterfaces.UNO = []; else usage (sprintf ("Unknown .ods interface \"%s\" requested. Only OTK or JOD supported", reqinterface)); endif @@ -181,7 +187,7 @@ ods.odfvsn = odsinterfaces.odfvsn; odssupport += 1; catch - if (odsinterfaces.JOD && ~rw && chk2) + if (xlsinterfaces.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); @@ -223,6 +229,38 @@ end_try_catch endif + if (odsinterfaces.UNO && ~odssupport) + # First the file name must be transformed into a URL + filename = 'file:///c:/Home/philip/MyDocs/octave/spreadsheet-tst/foo3_.ods'; + try + xContext = java_invoke ("com.sun.star.comp.helper.Bootstrap", "bootstrap") + xMCF = xContext.getServiceManager () + oDesktop = xMCF.createInstanceWithContext ("com.sun.star.frame.Desktop", xContext); + # Workaround: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XComponentLoader'); + aLoader = oDesktop.queryInterface (unotmp); + # 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', "Hidden", 0, true, []); + lProps(1) = lProp; + # save in ods struct: + xComp = aLoader.loadComponentFromURL (filename, "_blank", 0, lProps); + # Workaround: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheetDocument'); + # save in ods struct: + xSpdoc = xComp.queryInterface (unotmp); + ods.workbook = xSpdoc; # Needed to be able to close soffice in odsclose() + ods.filename = filename; + ods.xtype = 'UNO'; + ods.app.xComp = xComp; # Needed to be able to close soffice in odsclose() + ods.app.aLoader = aLoader; # Needed to be able to close soffice in odsclose() + ods.odfvsn = 'UNO'; + odssupport += 4; + catch + error ('Couldn''t open file %s using UNO', filename); + end_try_catch + endif + # if # <other interfaces here> @@ -249,7 +287,7 @@ endfunction -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -277,6 +315,7 @@ ## Currently implemented interfaces comprise: ## - Java & ODFtoolkit (www.apache.org) ## - Java & jOpenDocument (www.jopendocument.org) +## - Java & UNO bridge (OpenOffice.org) ## ## Examples: ## @@ -301,7 +340,8 @@ ## " Rearranged code a bit; fixed typos in OTK detection code (odfdvsn -> odfvsn) ## 2010-09-27 More code cleanup ## 2010-11-12 Warning added about waning support for odfdom v. 0.7.5 -## 2011-02-15 Adapted to new java-1.2.8 javaclasspath() calling style +## 2011-05-06 Fixed wrong strfind tests +## " Experimental UNO support added function [odsinterfaces] = getodsinterfaces (odsinterfaces) @@ -314,26 +354,51 @@ # Check Java support try - tmp1 = javaclasspath ('-all'); # For java pkg > 1.2.7 - if (isempty (tmp1)), tmp1 = javaclasspath; endif # For java pkg < 1.2.8 + jcp = javaclasspath; # If we get here, at least Java works. Now check for proper entries # in class path. Under *nix the classpath must first be split up - if (isunix) tmp1 = strsplit (char(tmp1), ":"); endif + if (isunix) jcp = strsplit (char(tmp1), ":"); endif ## FIXME implement more rigid Java version check a la xlsopen. ## ods / Java stuff is less critical than xls / Java, however catch # No Java support - odsinterfaces.OTK = 0; - odsinterfaces.JOD = 0; - if ~(isempty (odsinterfaces.POI) && isempty (odsinterfaces.JXL)) + if ~(isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD)) # Some Java-based interface requested but Java support is absent error ('No Java support found.'); else # No specific Java-based interface requested. Just return return; endif + odsinterfaces.OTK = 0; + odsinterfaces.JOD = 0; + odsinterfaces.UNO = 0; end_try_catch + # Try Java & UNO + if (isempty (odsinterfaces.UNO)) + # entries0(1) = not a jar but a directory (<000_install_dir/program/>) + jpchk = 0; entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + # Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) + # as javaclasspath is one long string. Under Windows however classpath is a cell array + # so we need the following more subtle, platform-independent approach: + for jj=1:numel (entries) + for ii=1:numel (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries{jj})))) + jpchk = jpchk + 1; + endif + endfor + endfor + if (jpchk >= numel (entries)) + odsinterfaces.UNO = 1; + fprintf (' => UNO (OOo) OK\n'); + chk1 = 1; + else + warning ('\nOne or more UNO classes (.jar) missing in javaclasspath'); + endif + endif + # Try Java & ODF toolkit if (isempty (odsinterfaces.OTK)) odsinterfaces.OTK = 0; @@ -342,10 +407,10 @@ # under Windows we need the following more subtle, platform-independent approach: for ii=1:length (tmp1) for jj=1:length (entries) - if (strfind ( tmp1{ii}, entries{jj})), ++jpchk; endif + if (~isempty (strfind ( tmp1{ii}, entries{jj}))), ++jpchk; endif endfor endfor - if (jpchk >= 2) # Apparently all requested classes present. + if (jpchk >= 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 = ' '; @@ -377,10 +442,10 @@ jpchk = 0; entries = {"jOpenDocument"}; for ii=1:length (tmp1) for jj=1:length (entries) - if (strfind (tmp1{ii}, entries{jj})), ++jpchk; endif + if (~isempty (strfind (tmp1{ii}, entries{jj}))), ++jpchk; endif endfor endfor - if (jpchk >= 1) + if (jpchk >= numel(entries)) odsinterfaces.JOD = 1; printf (" Java/jOpenDocument (JOD) OK. "); chk1 = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-05-15 20:36:58
|
Revision: 8263 http://octave.svn.sourceforge.net/octave/?rev=8263&view=rev Author: prnienhuis Date: 2011-05-15 20:36:51 +0000 (Sun, 15 May 2011) Log Message: ----------- Experimental UNO support added Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/spsh_chkrange.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-05-15 20:36:29 UTC (rev 8262) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-05-15 20:36:51 UTC (rev 8263) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -108,6 +108,8 @@ ## 2010-11-12 Better input argument checks ## 2010-11-13 Reset ods.limits when read was successful ## 2010-11-13 Added check for 2-D input array +## 2011-03-23 First try of odfdom 0.8.7 +## 2011-05-15 Experimental UNO support added ## ## Last update of subfunctions below: 2012-12-08 @@ -158,16 +160,23 @@ switch ods.odfvsn case "0.7.5" [ ods, rstatus ] = oct2jotk2ods (c_arr, ods, wsh, crange, spsh_opts); - case "0.8.6" + case {"0.8.6", "0.8.7"} [ ods, rstatus ] = oct3jotk2ods (c_arr, ods, wsh, crange, spsh_opts); otherwise error ("Unsupported odfdom version"); endswitch + elseif (strcmp (ods.xtype, 'JOD')) # Write ods file tru Java & jOpenDocument. API still leaves lots to be wished... [ ods, rstatus ] = oct2jod2ods (c_arr, ods, wsh, crange); + + elseif (strcmp (ods.xtype, 'UNO')) + # Write ods file tru Java & UNO bridge (OpenOffice.org & clones) + [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts); + # elseif # ---- < Other interfaces here > + else error (sprintf ("ods2oct: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); endif @@ -657,7 +666,8 @@ ## 2010-08-22 odfdom 0.8.6 is there... seems to work with just one bug, easily worked around ## 2010-10-27 Improved file change tracking tru ods.changed ## 2010-11-12 Improved file change tracking tru ods.changed -#3 2010-12-08 Bugfixes (obj -> arg L.715; removed stray arg in call to spsh_prstype L.719) +## 2010-12-08 Bugfixes (obj -> arg L.715; removed stray arg in call to spsh_prstype L.719) +## 2011-03-23 First try of odfdom 0.8.7 function [ ods, rstatus ] = oct3jotk2ods (c_arr, ods, wsh, crange, spsh_opts) @@ -674,7 +684,11 @@ # makes physical copies only when needed (?) odfroot = odfcont.getRootElement (); offsprdsh = ods.app.getContentRoot(); - spsh = odfcont.getOdfDocument (); + if (strcmp (ods.odfvsn, '0.8.7')) + spsh = odfcont.getDocument (); + else + spsh = odfcont.getOdfDocument (); + endif # Get some basic spreadsheet data from the pointer using ODFtoolkit autostyles = odfcont.getOrCreateAutomaticStyles(); @@ -970,3 +984,138 @@ endif endfunction + + +## Copyright (C) 2011 Philip Nienhuis <prn...@us...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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/>. + +## oct2uno2ods - transfer data to ods or xls file using Java/UNO bridge +## with OpenOffice_org & clones + +## Author: Philip Nienhuis <prn...@us...> +## Created: 2011-05-15 + +function [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts) + + changed = 0; + newsh = 0; + ctype = [1, 2, 3, 4, 5]; # Float, Logical, String, Formula, Empty + + # Get handle to sheet, create a new one if needed + sheets = ods.workbook.getSheets (); + sh_names = sheets.getElementNames (); + # 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 + 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; + while (ii <= maxtry) + shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); + if (isempty (strmatch (wsh, {sh_names}))) + ii = 10; + else + ++ii; + endif + endwhile + if (ii > maxtry + 1) + error ("Could not add sheet with a unique name to file %s"); + endif + endif + wsh = shname; + newsh = 1; + else + # turn wsh index into the associated sheet name + wsh = sh_names (wsh); + endif + else + # wsh is a sheet name. See if it exists already + if (isempty (strmatch (wsh, {sh_names}))) + # 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 + shptr = java_new ("java.lang.Short", sprintf ("%d", numel (sh_names) + 1)); + sh = sheets.insertNewByName (wsh, shptr); + sheets = ods.workbook.getSheets (); + sh_names = sheets.getElementNames (); + 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'); + sh = sheets.getByName (wsh).getObject.queryInterface (unotmp); + + # 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 # + 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; + 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), c_arr); + typearr(fptr) = ctype(4); # FORMULA + endif + + # 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 + XCell.setValue (c_arr{ii, jj}); + case 2 # Logical. Convert to float + XCell.setValue (double (c_arr{ii, jj})); + 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 + if (spsh_opts.formulas_as_text) + 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 + endswitch + changed = 1; + catch + printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); + keyboard + end_try_catch + endfor + endfor + + if (changed) + ods.changed = max (min (ods.changed, 2), changed); # Preserve 2 (new file), 1 (existing) + rstatus = 1; + endif + +endfunction Modified: trunk/octave-forge/main/io/inst/spsh_chkrange.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_chkrange.m 2011-05-15 20:36:29 UTC (rev 8262) +++ trunk/octave-forge/main/io/inst/spsh_chkrange.m 2011-05-15 20:36:51 UTC (rev 8263) @@ -1,4 +1,4 @@ -## Copyright (C) 2010 Philip Nienhuis +## Copyright (C) 2010,2011 Philip Nienhuis <prn...@us...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -28,14 +28,13 @@ ## ## @end deftypefn -## Author: Philip Nienhuis, <prn...@us...> +## Author: Philip Nienhuis <prn...@us...> ## Created: 2010-08-02 ## Updates: ## 2010-08-25 Option for supplying file pointer rather than interface_type & filename ## (but this can be wasteful if the file ptr is copied) ## 2011-03-29 Bug fix - unrecognized pointer struct & wrong type error msg -## 2011-04-21 Bug fix - wouldn't properly detect OOXML from extension -## '' Added tests +## 2011-05-15 Experimental UNO support added (OpenOffice.org & clones) function [ topleft, nrows, ncols, trow, lcol ] = spsh_chkrange (crange, nr, nc, intf, filename=[]) @@ -54,20 +53,24 @@ # Define max row & column capacity from interface type & file suffix switch xtype - case {'COM', 'POI'} - if (strcmp ('xls', tolower (filename(end-2:end)))) + 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', 'OXS'} + case { 'JXL', 'OXS' } # JExcelAPI & OpenXLS can only process BIFF5 & BIFF8 ROW_CAP = 65536; COL_CAP = 256; - case {'OTK', 'JOD'} + case { 'OTK', 'JOD' } # 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 + ROW_CAP = 65536; COL_CAP = 1024; otherwise error (sprintf ("Unknown interface type - %s\n", xtype)); endswitch @@ -97,52 +100,3 @@ ncols = min (ncols, nc); endfunction - -# Test COM using ptr struct -%!test -%! intf = struct ("xtype", 'COM', "app", [], "filename", 'test.xls', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D2:IY67356'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 65536, 257, intf); -%! assert ([a1, a2, a3, a4, a5], ['D2', 65535, 253, 2, 4]); - -# Test COM using ptr struct -%!test -%! intf = struct ("xtype", 'COM', "app", [], "filename", 'test.xls', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D2:IY67356'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 65536, 257, 'COM', 'filename.xls'); -%! assert ([a1, a2, a3, a4, a5], ['D2', 65535, 253, 2, 4]); - -# Test POI using ptr struct -%!test -%! intf = struct ("xtype", 'POI', "app", [], "filename", 'test.xls', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D2:IY67356'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 65536, 257, intf); -%! assert ([a1, a2, a3, a4, a5], ['D2', 65535, 253, 2, 4]); - -# Test POI OOXML using ptr struct -%!test -%! intf = struct ("xtype", "POI", "app", [], "filename", 'test.xlsx', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D3:xfe1058888'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 1200000, 20000, intf); -%! assert ([a1, a2, a3, a4, a5], ['D3', 1048574, 16381, 3, 4]); - -# Test JXL using ptr struct -%!test -%! intf = struct ("xtype", "JXL", "app", [], "filename", 'test.xls', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D2:IY67356'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 65536, 257, intf); -%! assert ([a1, a2, a3, a4, a5], ['D2', 65535, 253, 2, 4]); - -# Test OTK using ptr struct -%!test -%! intf = struct ("xtype", 'OTK', "app", [], "filename", 'test.ods', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D2:AML67356'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 65536, 1200, intf); -%! assert ([a1, a2, a3, a4, a5], ['D2', 65535, 1021, 2, 4]); - -# Test JOD using ptr struct -%!test -%! intf = struct ("xtype", 'JOD', "app", [], "filename", 'test.ods', "workbook", [], "changed", 0, "limits", []); -%! tstrange = 'D2:AML67356'; -%! [a1, a2, a3, a4, a5] = spsh_chkrange (tstrange, 65536, 1200, intf); -%! assert ([a1, a2, a3, a4, a5], ['D2', 65535, 1021, 2, 4]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-05-18 20:19:43
|
Revision: 8272 http://octave.svn.sourceforge.net/octave/?rev=8272&view=rev Author: prnienhuis Date: 2011-05-18 20:19:36 +0000 (Wed, 18 May 2011) Log Message: ----------- Experimental UNO support added, incl. newly created files Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsclose.m trunk/octave-forge/main/io/inst/xlsfinfo.m trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-05-18 20:18:47 UTC (rev 8271) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-05-18 20:19:36 UTC (rev 8272) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -69,11 +69,12 @@ ## Beware that -if invoked- Excel invocations may be left running silently ## in case of COM errors. Invoke xlsclose with proper pointer struct to ## close them. -## When using java, note that large data array sizes elements may exhaust -## the java shared memory space for the default java memory settings. +## When using Java, note that large data array sizes elements may exhaust +## the Java shared memory space for the default java memory settings. ## For larger arrays, appropriate memory settings are needed in the file -## java.opts; then the maximum array size for the java-based spreadsheet -## options may be in the order of 10^6 elements. +## java.opts; then the maximum array size for the Java-based spreadsheet +## options may be in the order of 10^6 elements. In caso of UNO this +## limit is not applicable and spreadsheets may be much larger. ## ## Examples: ## @@ -103,8 +104,9 @@ ## 2010-12-01 Better check on file pointer struct (ischar (xls.xtype)) ## 2011-03-29 OpenXLS support added. Works but saving to file (xlsclose) doesn't work yet ## " Bug fixes (stray variable c_arr, and wrong test for valid xls struct) +## 2011-05-18 Experimental UNO support -## Last script file update (incl. subfunctions): 2011-03-29 (oct2oxs2xls) +## Last script file update (incl. subfunctions): 2011-05-18 (oct2uno2xls) function [ xls, rstatus ] = oct2xls (obj, xls, wsh=1, crange=[], spsh_opts=[]) @@ -160,9 +162,13 @@ elseif (strcmp (xls.xtype, 'JXL')) # Invoke Java and JExcelAPI [xls, rstatus] = oct2jxla2xls (obj, xls, wsh, crange, spsh_opts); -# elseif (strcmp (xls.xtype, 'OXS')) + elseif (strcmp (xls.xtype, 'OXS')) # # Invoke Java and OpenXLS ##### Not complete, saving file doesn't work yet! + printf ('Sorry, writing with OpenXLS not supported yet\n'); # [xls, rstatus] = oct2oxs2xls (obj, xls, wsh, crange, spsh_opts); + elseif (strcmp (xls.xtype, 'UNO')) + # Invoke Java and UNO bridge (OpenOffice.org) + [xls, rstatus] = oct2uno2xls (obj, xls, wsh, crange, spsh_opts); # elseif (strcmp'xls.xtype, '<whatever>')) # <Other Excel interfaces> else @@ -869,3 +875,137 @@ rstatus = 1; endfunction + + +## Copyright (C) 2011 Philip Nienhuis <prn...@us...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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/>. + +## oct2uno2xls + +## Author: Philip Nienhuis <prn...@us...> +## Created: 2011-05-18 + +function [ xls, rstatus ] = oct2uno2xls (c_arr, xls, wsh, crange, spsh_opts) + + changed = 0; + newsh = 0; + ctype = [1, 2, 3, 4, 5]; # Float, Logical, String, Formula, Empty + + # Get handle to sheet, create a new one if needed + sheets = xls.workbook.getSheets (); + sh_names = sheets.getElementNames (); + # 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 + 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; + while (ii <= maxtry) + shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); + if (isempty (strmatch (wsh, {sh_names}))) + ii = 10; + else + ++ii; + endif + endwhile + if (ii > maxtry + 1) + error ("Could not add sheet with a unique name to file %s"); + endif + endif + wsh = shname; + newsh = 1; + else + # turn wsh index into the associated sheet name + wsh = sh_names (wsh); + endif + else + # wsh is a sheet name. See if it exists already + if (isempty (strmatch (wsh, {sh_names}))) + # 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 + shptr = java_new ("java.lang.Short", sprintf ("%d", numel (sh_names) + 1)); + sh = sheets.insertNewByName (wsh, shptr); + sheets = xls.workbook.getSheets (); + sh_names = sheets.getElementNames (); + 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'); + sh = sheets.getByName (wsh).getObject.queryInterface (unotmp); + + # 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 # + 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; + 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), c_arr); + typearr(fptr) = ctype(4); # FORMULA + endif + + # 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 + XCell.setValue (c_arr{ii, jj}); + case 2 # Logical. Convert to float + XCell.setValue (double (c_arr{ii, jj})); + 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 + if (spsh_opts.formulas_as_text) + 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 + endswitch + changed = 1; + catch + printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); + keyboard + end_try_catch + endfor + endfor + + if (changed) + xls.changed = max (min (xls.changed, 2), changed); # Preserve 2 (new file), 1 (existing) + rstatus = 1; + endif + +endfunction Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-05-18 20:18:47 UTC (rev 8271) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-05-18 20:19:36 UTC (rev 8272) @@ -116,8 +116,9 @@ ## 2010-11-13 Catch empty sheets when no range was specified ## 2011-03-26 OpenXLS support added ## 2011-03-29 Test for proper input xls struct extended +## 2011-05-18 Experimental UNO support added ## -## Latest subfunc update: 2011-03-26 (OXS) +## Latest subfunc update: 2011-05-18 (UNO) function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) @@ -163,6 +164,9 @@ elseif (strcmp (xls.xtype, 'OXS')) # Read xls file tru OpenXLS [rawarr, xls, rstatus] = xls2oxs2oct (xls, wsh, datrange, spsh_opts); + elseif (strcmp (xls.xtype, 'UNO')) + # Read xls file tru OpenOffice.org UNO (Java) bridge + [rawarr, xls, rstatus] = xls2uno2oct (xls, wsh, datrange, spsh_opts); # elseif ---- <Other interfaces here> # Call to next interface else @@ -843,3 +847,115 @@ xls.limits = [lcol, rcol; firstrow, lastrow]; endfunction + + +## Copyright (C) 2011 Philip Nienhuis <prn...@us...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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/>. + +## xls2uno2oct + +## Author: Philip Nienhuis <prn...@us...> +## Created: 2011-05-05 +## Updates: +## + +function [rawarr, xls, rstatus] = xls2uno2oct (xls, wsh, datrange, spsh_opts) + + sheets = xls.workbook.getSheets (); + sh_names = sheets.getElementNames (); + + # 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)); + endif + else + ii = strmatch (wsh, {sh_names}); + 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'); + sh = sheets.getByName(sh_names(wsh)).getObject.queryInterface (unotmp); + + 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... + Cellflgs = javaObject ("java.lang.Short", "23"); + ccells = xRQ.queryContentCells (Cellflgs); + addrs = ccells.getRangeAddressesAsString (); + + # Strip sheet name from addresses + adrblks = strsplit (addrs, ','); + if (isempty (adrblks)) + 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 + [ 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 + else + [dummy, nrows, ncols, srow, scol] = parse_sp_range (datrange); + # 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 + endif + # Create storage for data at Octave side + rawarr = cell (nrows, ncols); + + # 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 (); + switch cType + 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'); + rawarr{ii-trow+2, jj-lcol+2} = XCell.queryInterface (unotmp).getString (); + case 3 # Formula + if (spsh_opts.formulas_as_text) + rawarr{ii-trow+2, jj-lcol+2} = XCell.getFormula (); + else + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); + rawarr{ii-trow+2, jj-lcol+2} = XCell.queryInterface (unotmp).getString (); + endif + otherwise + # Empty cell + endswitch + endfor + endfor + + # Keep track of data rectangle limits + xls.limits = [lcol, rcol; trow, brow]; + + rstatus = ~isempty (rawarr); + +endfunction Modified: trunk/octave-forge/main/io/inst/xlsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsclose.m 2011-05-18 20:18:47 UTC (rev 8271) +++ trunk/octave-forge/main/io/inst/xlsclose.m 2011-05-18 20:19:36 UTC (rev 8272) @@ -17,6 +17,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} [@var{xls}] = xlsclose (@var{xls}) ## @deftypefnx {Function File} [@var{xls}] = xlsclose (@var{xls}, @var{filename}) +## @deftypefnx {Function File} [@var{xls}] = xlsclose (@var{xls}, "FORCE") ## Close the Excel spreadsheet pointed to in struct @var{xls}, if needed ## write the file to disk. Based on information contained in @var{xls}, ## xlsclose will determine if the file should be written to disk. @@ -26,23 +27,25 @@ ## However if errors occurred, the file pinter will be ontouched so you can ## clean up before a next try with xlsclose(). ## Be warned that until xlsopen is called again with the same @var{xls} pointer -## struct and @var{_keepxls_} omitted or set to false, hidden Excel or Java -## applications with associated (possibly large) memory chunks are kept alive -## taking up resources. +## struct, hidden Excel or Java applications with associated (possibly large) +## memory chunks are kept in memory, taking up resources. +## If (string) argument "FORCE" is supplied, the file pointer will be reset +## regardless, whether the possibly modified file has been saved successfully +## or not. Hidden Excel (COM) or OpenOffice.org (UNO) invocations may live on, +## possibly even impeding proper shutdown of Octave. ## ## @var{filename} can be used to write changed spreadsheet files to ## an other file than opened with xlsopen(); unfortunately this doesn't work ## with JXL (JExcelAPI) interface. ## -## You need MS-Excel (95 - 2010), and/or the Java package > 1.2.6 plus Apache -## POI > 3.5 and/or JExcelAPI and/or OpenXLS installed on your computer + proper -## javaclasspath set, to make this function work at all. +## You need MS-Excel (95 - 2010), and/or the Java package => 1.2.8 plus Apache +## POI > 3.5 and/or JExcelAPI and/or OpenXLS and/or OpenOffice.org or clones +## installed on your computer + proper javaclasspath set, to make this +## function work at all. ## ## @var{xls} must be a valid pointer struct made by xlsopen() in the same ## octave session. ## -## Beware: Excel invocations may be left running invisibly in case of COM errors. -## ## Examples: ## ## @example @@ -66,31 +69,56 @@ ## 2010-11-12 Replaced 'keepxls' by new filename arg; catch write errors and ## always keep file pointer in case of write errors ## 2011-03-26 Added OpenXLS support +## 2011-05-18 Added experimental UNO support, incl. saving newly created files -function [ xls ] = xlsclose (xls, filename=[]) +function [ xls ] = xlsclose (xls, varargs) - if (~isempty (filename)) - if (ischar (filename)) - if (xls.changed == 0) - warning ("File %s wasn't changed, new filename ignored.", filename); - else - if (strcmp (xls.xtype, 'JXL')) - warning ("JXL doesn't support changing filename, new filename ignored."); - elseif ~(strcmp (xls.xtype, 'COM') || strmatch ('.xls', filename)) - # Excel / ActiveX will write any filename extension - error ('No .xls or .xlsx extension lacking in filename %s', filename); + force = 0; + + if (nargin > 1) + for ii=2:nargin + if (strcmp (lower (varargin{ii}), "force")) + # Close .ods anyway even if write errors occur + force = 1; + elseif (~isempty (strfind (tolower (varargin{ii}), '.'))) + # Apparently a file name + if (xls.changed == 0 || xls.changed > 2) + printf ("File %s wasn't changed, new filename ignored.", xls.filename); + elseif (strcmp (xls.xtype, 'JXL')) + error ("JXL doesn't support changing filename, new filename ignored."); + elseif ~((strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'UNO')) && isempty (strfind ('filename', '.xls'))) + # Excel/ActiveX && OOo (UNO bridge) will write any valid filetype; POI/JXL/OXS need .xls[x] + error ('.xls or .xlsx extension lacking in filename %s', filename); else ### For multi-user environments, uncomment below AND relevant stanza in xlsopen # In case of COM, be sure to first close the open workbook - #if (strcmp (xls.xtype, \xC7OM')) + #if (strcmp (xls.xtype, 'COM')) # xls.app.Application.DisplayAlerts = 0; # xls.workbook.close(); # xls.app.Application.DisplayAlerts = 0; #endif + if (strcmp (xls.xtype, 'UNO')) + # If needed, turn filename into URL + 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) + else + # Transform into URL form + fname = canonicalize_file_name (strsplit (filename, filesep){end}); + # 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) = '/'; + filename = [ 'file://' tmp{:} ]; + endif + endif + endif xls.filename = filename; endif endif - endif + endfor endif if (strcmp (xls.xtype, 'COM')) @@ -185,12 +213,62 @@ xls.workbook.close (); endif + elseif (strcmp (xls.xtype, 'UNO')) + # Java & UNO bridge + try + if (xls.changed && xls.changed < 3) + # 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'); + xModified = xModel.queryInterface (unotmp); + if (xModified.isModified ()) + 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, []); + lProps(1) = lProp; + # OK, store file + xStore.storeAsURL (xls.filename, lProps); + else + xStore.store (); + 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'); + xModel = xls.app.xComp.queryInterface (unotmp); + 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'); + 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'); + xDesk = xls.app.aLoader.queryInterface (unotmp); + xDesk.terminate(); + else + warning ("Error closing xls pointer (UNO)"); + endif + return + end_try_catch + # elseif <other interfaces here> endif - if (xls.changed) + if (xls.changed && xls.changed < 3) warning (sprintf ("File %s could not be saved. Read-only or in use elsewhere?\nFile pointer preserved.", xls.filename)); + if (force) + xls = []; + endif else xls = []; endif Modified: trunk/octave-forge/main/io/inst/xlsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-05-18 20:18:47 UTC (rev 8271) +++ trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-05-18 20:19:36 UTC (rev 8272) @@ -81,6 +81,7 @@ ## 2010-10-10 Made output arg2 contain only address ranges (or other sheet type names) ## 2010-11-01 Added other file type strings for return arg #3 (fformat) ## 2011-03-26 Added OpenXLS support +## 2011-05-18 Experimental UNO support function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[]) @@ -88,7 +89,8 @@ persistent lstr2; lstr2 = length (str2); xls = xlsopen (filename, 0, reqintf); - + if (isempty (xls)); return; endif + toscreen = nargout < 1; xlWorksheet = -4167; xlChart = 4; @@ -182,7 +184,23 @@ sh_names(ii, 2) = "Empty or Chart"; endif endfor - if (sh_cnt > 0) fformat = "xlWorkbookNormal"; else, fformat = ''; endif + if (sh_cnt > 0); fformat = "xlWorkbookNormal"; else; fformat = ''; endif + + elseif (strcmp (xls.xtype, 'UNO')) + sheets = xls.workbook.getSheets (); + 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)); + else + sh_names(ii, 2) = "Empty or Chart"; + endif + endfor + if (sh_cnt > 0); fformat = "xlWorkbookNormal"; else; fformat = ''; endif # elseif <Other Excel interfaces below> @@ -190,6 +208,7 @@ error (sprintf ("xlsfinfo: unknown Excel .xls interface - %s.", xls.xtype)); endif + if (toscreen) # Echo sheet names to screen for ii=1:sh_cnt Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-05-18 20:18:47 UTC (rev 8271) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-05-18 20:19:36 UTC (rev 8272) @@ -25,19 +25,22 @@ ## Calling xlsopen without specifying a return argument is fairly useless! ## ## To make this function work at all, you need MS-Excel (95 - 2003), and/or -## the Java package > 1.2.6 plus either Apache POI > 3.5 or JExcelAPI or OpenXLS -## installed on your computer + proper javaclasspath set. These interfaces -## are referred to as COM, POI, JXL and OXS, resp., and are preferred in that -## order by default (depending on their presence). +## the Java package >= 1.2.8 plus Apache POI >= 3.5 and/or JExcelAPI and/or +## OpenXLS and/or OpenOffice.org (or clones) installed on your computer + +## proper javaclasspath set. These interfaces are referred to as COM, POI, +## JXL, OXS, and UNO, resp., and are preferred in that order by default +## (depending on their presence). ## For OOXML support, in addition to Apache POI support you also need the ## following jars in your javaclasspath: poi-ooxml-schemas-3.5.jar, -## xbean.jar and dom4j-1.6.1.jar (or later versions). +## xbean.jar and dom4j-1.6.1.jar (or later versions). Later OpenOffice.org +## versions (UNO) have support for OOXML as well. ## ## @var{filename} should be a valid .xls or xlsx Excel file name (including -## extension); but if you use the COM interface you can specify any extension -## that your installed Excel version can read AND write, using the Java -## interfaces only .xls or .xlsx are allowed. If @var{filename} does not -## contain any directory path, the file is saved in the current directory. +## extension). But if you use the COM interface you can specify any extension +## that your installed Excel version can read AND write; the same goes for UNO +## (OpenOffice.org). Using the other Java interfaces, only .xls or .xlsx are +## allowed. If @var{filename} does not contain any directory path, the file +## is saved in the current directory. ## ## If @var{readwrite} is set to 0 (default value) or omitted, the Excel file ## is opened for reading. If @var{readwrite} is set to True or 1, an Excel @@ -45,11 +48,13 @@ ## ## Optional input argument @var{reqintf} can be used to override the Excel ## interface that otherwise is automatically selected by xlsopen. Currently -## implemented interfaces (in order of preference) are 'COM' (Excel / COM), -## 'POI' (Java / Apache POI), 'JXL' (Java / JExcelAPI) or 'OXS' (OpenXLS). +## implemented interfaces (in order of preference) are 'COM' (Excel/COM), +## 'POI' (Java/Apache POI), 'JXL' (Java/JExcelAPI), 'OXS' (Java/OpenXLS), or +## 'UNO' (Java/OpenOffice.org). ## -## Beware: Excel invocations may be left running invisibly in case of COM errors -## or forgetting to close the file pointer. +## Beware: Excel invocations may be left running invisibly in case of COM +## errors or forgetting to close the file pointer. Similarly for OpenOffice.org +## which may even prevent Octave from being closed. ## ## Examples: ## @@ -68,8 +73,8 @@ ## Author: Philip Nienhuis ## Created: 2009-11-29 -## Updates: -## 2010-01-03 Added OOXML support +## Updates: +## 2010-01-03 Added OOXML support ## 2010-01-10 Changed (java) interface preference order to COM->POI->JXL ## 2010-01-16 Removed echoeing debug info in POI stanza ## 2010-03-01 Removed javaclasspath check for rt.jar @@ -90,8 +95,9 @@ ## 2010-12-01 Small bugfix - reset xlssupport in l. 102 ## 2010-12-06 Textual changes to info header ## 2011-03-26 OpenXLS support added +## 2011-05-18 Experimental UNO support added, incl. creating new spreadsheets ## -## 2011-03-26 Latest subfunction update +## 2011-05-18 Latest subfunction update function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) @@ -99,7 +105,7 @@ # xlsinterfaces.<intf> = [] (not yet checked), 0 (found to be unsupported) or 1 (OK) if (isempty (chkintf)); chkintf = 1; - xlsinterfaces = struct ('COM', [], 'POI', [], 'JXL', [], 'OXS', []); + xlsinterfaces = struct ('COM', [], 'POI', [], 'JXL', [], 'OXS', [], 'UNO', []); endif xlssupport = 0; @@ -114,7 +120,8 @@ if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif # Turn arg3 into cell array if needed if (~iscell (reqinterface)), reqinterface = {reqinterface}; endif - xlsinterfaces.COM = 0; xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; xlsinterfaces.OXS = 0; + xlsinterfaces.COM = 0; xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; + 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 @@ -127,8 +134,10 @@ xlsinterfaces.JXL = []; elseif (strcmp (reqintf, 'OXS')) xlsinterfaces.OXS = []; + elseif (strcmp (reqintf, 'UNO')) + xlsinterfaces.UNO = []; else - usage (sprintf ("Unknown .xls interface \"%s\" requested. Only COM, POI, JXL or OXS supported\n", reqinterface{})); + usage (sprintf ("Unknown .xls interface \"%s\" requested. Only COM, POI, JXL, OXS or UNO supported\n", reqinterface{})); endif endfor printf ("Checking interface(s):\n"); @@ -139,7 +148,7 @@ for ii=1:numel (reqinterface) if (~xlsinterfaces.(toupper (reqinterface{ii}))) # No it aint - warning ("%s is not supported!", reqinterface{ii}); + warning ("%s is not supported!", toupper (reqinterface{ii})); else ++xlsintf_cnt; endif @@ -147,6 +156,7 @@ # Reset interface check indicator if no requested support found if (~xlsintf_cnt) chkintf = []; + xls = []; return endif endif @@ -189,7 +199,7 @@ # Keep track of which interface is selected xlssupport = 0; - # Interface preference order is defined below: currently COM -> POI -> JXL -> OXS + # Interface preference order is defined below: currently COM -> POI -> JXL -> OXS -> UNO if (xlsinterfaces.COM && ~xlssupport) # Excel functioning has been tested above & file exists, so we just invoke it app = actxserver ("Excel.Application"); @@ -292,6 +302,55 @@ end_try_catch endif + if (xlsinterfaces.UNO && ~xlssupport) + # 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) + else + # Transform into URL form + fname = canonicalize_file_name (strsplit (filename, filesep){end}); + # 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) = '/'; + filename = [ 'file://' tmp{:} ]; + endif + 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: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XComponentLoader'); + aLoader = oDesktop.queryInterface (unotmp); + # 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', "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: + 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() + 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'; + xlssupport += 16; + catch + error ('Couldn''t open file %s using UNO', filename); + end_try_catch + endif + # if # ---- other interfaces # endif @@ -354,6 +413,7 @@ ## - Java & Apache POI ## - Java & JExcelAPI ## - Java & OpenXLS (only JRE >= 1.4 needed) +## - Java & UNO bridge (OpenOffice.org invocation) ## ## Examples: ## @@ -372,6 +432,7 @@ ## 2011-02-15 Adapted to javaclasspath calling style of java-1.2.8 pkg ## 2011-03-26 OpenXLS support added ## '' Bug fix: javaclasspath change wasn't picked up between calls with req.intf +## 2011-05-18 Experimental UNO support added function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) @@ -424,7 +485,9 @@ xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; xlsinterfaces.OXS = 0; - if ~(isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS)) + xlsinterfaces.UNO = 0; + if ~(isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL)... + && isempty (xlsinterfaces.OXS) && isempty (xlsinterfaces.UNO)) # Some Java-based interface requested but Java support is absent error ('No Java support found.'); else @@ -503,7 +566,34 @@ warning ("\n Not all classes (.jar) required for OXS in classpath"); endif endif - + + # Try Java & UNO + if (isempty (xlsinterfaces.UNO)) + printf ("Java/UNO bridge... "); + xlsinterfaces.UNO = 0; + # entries0(1) = not a jar but a directory (<00o_install_dir/program/>) + jpchk = 0; entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + # Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) + # as javaclasspath is one long string. Under Windows however classpath is a cell array + # so we need the following more subtle, platform-independent approach: + for jj=1:numel (entries) + for ii=1:numel (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries{jj})))) + jpchk = jpchk + 1; + endif + endfor + endfor + if (jpchk >= numel (entries)) + xlsinterfaces.UNO = 1; + fprintf ('OK\n'); + chk1 = 1; + else + warning ('\nOne or more UNO classes (.jar) missing in javaclasspath'); + endif + endif + # ---- Other interfaces here, similar to the ones above endfunction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-04 20:01:42
|
Revision: 8493 http://octave.svn.sourceforge.net/octave/?rev=8493&view=rev Author: prnienhuis Date: 2011-09-04 20:01:36 +0000 (Sun, 04 Sep 2011) Log Message: ----------- Always allow interface rediscovery if no ods/xls support was found; fixed statement order in Java detection stanzas Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-09-04 12:38:43 UTC (rev 8492) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-09-04 20:01:36 UTC (rev 8493) @@ -87,8 +87,10 @@ ## 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) ## -## Latest change on subfunction below: 2011-05-07 +## Latest change on subfunction below: 2011-09-03 function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) @@ -316,7 +318,7 @@ if (ods.changed == 1) ods.changed = 0; endif endif - if (~isempty (reqinterface)) + if (~isempty (reqinterface) || ~odssupport) # Reset all found interfaces for re-testing in the next call. Add interfaces if needed. chkintf = []; endif @@ -383,6 +385,8 @@ ## 2011-06-06 Fix for javaclasspath format in *nix w. java-1.2.8 pkg ## " Implemented more rigid Java check ## " Tamed down verbosity +## 2011-09-03 Fixed order of odsinterfaces.<member> statement in Java detection try-catch +## " Reset tmp1 (always allow interface rediscovery) for empty odsinterfaces arg function [odsinterfaces] = getodsinterfaces (odsinterfaces) @@ -390,8 +394,11 @@ persistent tmp1 = []; persistent jcp; if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) + # Assume no interface detection has happened yet printf ("Detected interfaces: "); + tmp1 = []; elseif (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) || isempty (odsinterfaces.UNO)) + # At least one interface is requested by user tmp1 = []; endif deflt = 0; @@ -410,19 +417,19 @@ 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 + if (isunix && ~iscell (jcp)), jcp = strsplit (char (jcp), pathsep ()); endif tmp1 = 1; catch # No Java support - odsinterfaces.OTK = 0; - odsinterfaces.JOD = 0; - odsinterfaces.UNO = 0; if ~(isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) # Some Java-based interface requested but Java support is absent error ('No Java support found.'); else - # No specific Java-based interface requested. Just return (This is needed if - # ever a non-Java based interfaces will be implemented + # No specific Java-based interface requested. Just return (needed for if + # ever a non-Java based interfaces will be implemented) + odsinterfaces.OTK = 0; + odsinterfaces.JOD = 0; + odsinterfaces.UNO = 0; return; endif end_try_catch @@ -491,9 +498,6 @@ odsinterfaces.UNO = 0; # entries(1) = not a jar but a directory (<000_install_dir/program/>) jpchk = 0; entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; - # Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) - # as javaclasspath is one long string. Under Windows however classpath is a cell array - # so we need the following more subtle, platform-independent approach: for jj=1:numel (entries) for ii=1:numel (jcp) jcplst = strsplit (jcp{ii}, filesep); @@ -508,7 +512,7 @@ printf ("UNO"); if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif else - warning ('\nOne or more UNO classes (.jar) missing in javaclasspath'); + warning ("\nOne or more UNO classes (.jar) missing in javaclasspath"); endif endif Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-04 12:38:43 UTC (rev 8492) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-04 20:01:36 UTC (rev 8493) @@ -100,8 +100,10 @@ ## 2011-05-18 Experimental UNO support added, incl. creating new spreadsheets ## 2011-05-22 Textual changes in header ## 2011-05-29 Cleanup of comments & messages +## 2011-09-03 Reset chkintf to [] if no xls support was discovered (to allow +## rediscovery of interfaces between xlsopen calls, e.g. javaclasspath changes) ## -## 2011-06-13 Latest subfunction update +## 2011-09-03 Latest subfunction update function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) @@ -292,7 +294,7 @@ if (xlsinterfaces.OXS && ~xlssupport) if (~chk1) - error ("OXS can only read reliably from .xls files") + error ("OXS can only read from .xls files") endif try wb = javaObject ('com.extentech.ExtenXLS.WorkBookHandle', filename); @@ -381,7 +383,7 @@ # Rounding up. If none of the xlsinterfaces is supported we're out of luck. - if (~isempty (reqinterface)) + if (~isempty (reqinterface) || ~xlssupport) # Reset found interfaces for re-testing in the next call. Add interfaces if needed. chkintf = []; endif @@ -418,7 +420,7 @@ ## - Java & Apache POI ## - Java & JExcelAPI ## - Java & OpenXLS (only JRE >= 1.4 needed) -## - Java & UNO bridge (native OpenOffice.org in background) +## - Java & UNO bridge (native OpenOffice.org in background) - EXPERIMENTAL!! ## ## Examples: ## @@ -441,15 +443,19 @@ ## 2011-05-29 Reduced verbosity ## 2011-06-06 Fix for javaclasspath format in *nix w java-1.2.8 pkg ## 2011-06-13 Fixed potentially faulty tests for java classlib presence +## 2011-09-03 Fixed order of xlsinterfaces.<member> statements in Java detection try-catch +## '' Reset tmp1 (always allow interface rediscovery) for empty xlsinterfaces arg function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) + # tmp1 = [] (not initialized), 0 (No java detected), or 1 (Working Java found) persistent tmp1 = []; persistent jcp; # Java class path if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS)) printf ("Detected interfaces: "); + tmp1 = []; elseif (isempty (xlsinterfaces.COM) || isempty (xlsinterfaces.POI) || isempty (xlsinterfaces.JXL) || isempty (xlsinterfaces.OXS)) - tmp1 = []; # tmp1 = [] (not initialized), 0 (No java detected), or 1 (Working Java found) + tmp1 = []; endif deflt = 0; @@ -491,16 +497,16 @@ tmp1 = 1; catch # No Java support found - xlsinterfaces.POI = 0; - xlsinterfaces.JXL = 0; - xlsinterfaces.OXS = 0; - xlsinterfaces.UNO = 0; if ~(isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL)... && isempty (xlsinterfaces.OXS) && isempty (xlsinterfaces.UNO)) # Some Java-based interface requested but Java support is absent error (' No Java support found.'); else # No specific Java-based interface requested. Just return + xlsinterfaces.POI = 0; + xlsinterfaces.JXL = 0; + xlsinterfaces.OXS = 0; + xlsinterfaces.UNO = 0; return; endif tmp1 = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-08 17:35:43
|
Revision: 8512 http://octave.svn.sourceforge.net/octave/?rev=8512&view=rev Author: prnienhuis Date: 2011-09-08 17:35:32 +0000 (Thu, 08 Sep 2011) Log Message: ----------- Style, layout + copyright updates and minor bug fixes Modified Paths: -------------- trunk/octave-forge/main/io/inst/getusedrange.m trunk/octave-forge/main/io/inst/object2json.m trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/odsclose.m trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/odsread.m trunk/octave-forge/main/io/inst/odswrite.m trunk/octave-forge/main/io/inst/parsecell.m trunk/octave-forge/main/io/inst/spsh_chkrange.m trunk/octave-forge/main/io/inst/spsh_prstype.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsclose.m trunk/octave-forge/main/io/inst/xlsfinfo.m trunk/octave-forge/main/io/inst/xlsopen.m trunk/octave-forge/main/io/inst/xlsread.m trunk/octave-forge/main/io/inst/xlswrite.m Modified: trunk/octave-forge/main/io/inst/getusedrange.m =================================================================== --- trunk/octave-forge/main/io/inst/getusedrange.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/getusedrange.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -31,7 +31,7 @@ ## only be obtained using UNO interface. ## For the ActiveX (COM) interface the underlying Visual Basic call relies ## on cached range values and counts empty cells with only formatting too, -## so COM returns only approximate (but usually too big) range values. +## so COM returns only approximate (but then usually too big) range values. ## ## Examples: ## @@ -65,6 +65,7 @@ ## 2010-10-07 Added COM support (at last!) ## 2011-05-06 Experimental support for Java/UNO bridge ## 2011-06-13 OpenXLS support added +## 2011-09-08 Style & layout updates ## ## Last subfunc update: 2011-06-29 (OXS) @@ -94,7 +95,7 @@ endfunction -## Copyright (C) 2010 Philip Nienhuis, pr.nienhuis -at- users.sf.net +## Copyright (C) 2010,2011 Philip Nienhuis, pr.nienhuis -at- users.sf.net ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -158,7 +159,7 @@ # Get leftmost cell column number lcell = row.getFirstChild (); cl_char = char (lcell); - # Swap the following lines into comment to catch a jOpenDocument bug + # Swap the following lines into comment to catch a jOpenDocument bug which foobars OTK # (JOD doesn't set <office:value-type='string'> attribute when writing strings #if (isempty (findstr ('office:value-type', cl_char)) || isempty (findstr ('<text:', cl_char))) if (isempty (findstr ('office:value-type', cl_char))) @@ -602,7 +603,7 @@ sh = xls.workbook.getWorkSheet (wsh - 1); try - # Intriguing: sh.first<> is off by one, sh.getLast<> = OK... + # Intriguing: sh.getFirst<> is off by one, sh.getLast<> = OK.... 8-Z trow = sh.getFirstRow () + 1; brow = sh.getLastRow (); lcol = sh.getFirstCol () + 1; Modified: trunk/octave-forge/main/io/inst/object2json.m =================================================================== --- trunk/octave-forge/main/io/inst/object2json.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/object2json.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,137 +1,190 @@ -%% Copyright (C) 2010 Torre Herrera, Daniel de -%% -%% This program is free software; you can redistribute it and/or modify -%% it under the terms of the GNU General Public License as published by -%% the Free Software Foundation; either version 2 of the License, or -%% (at your option) any later version. -%% -%% This program is distributed in the hope that it will be useful, -%% but WITHOUT ANY WARRANTY; without even the implied warranty of -%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -%% GNU General Public License for more details. -%% -%% You should have received a copy of the GNU General Public License -%% along with Octave; see the file COPYING. If not, see -%% <http://www.gnu.org/licenses/>. -%% object2json.m -%% Ultima modificacion: 2010-12-06 - -function json=object2json(object) - % function json=object2json(object) - % This function returns a valid json string that will describe object - % The string will be in a compact form (i.e. no spaces or line breaks) - % - % It will map simple octave values this way: - % function handles: string with the name of the function - % double (numbers): depends: - % If it's real it will map to a string representing that number - % If it's complex it will map to an object with the next properties: - % real: real part of the number - % imag: imaginary part of the number - % char: A string enclosed by double quotes representing that character - % And will map more complex octave values this other way: - % struct: an object with properties equal to the struct's field names - % and value equal to the json counterpart of that field - % cell: it will be mapped depending on the value of the cell (for - % example {i} will be mapped to an object with real=0 and imag=1) - % vectors or cell arrays: it will map them to a corresponding js - % array (same size) with the values transformed to their json - % counterpart (Note: that in javascript all arrays are like octave's - % cells ,i.e. they can store different type and size variables) - % strings or char vectors: they will be mapped to the same string - % enclosed by double quotes - % Other octave values will be mapped to a string enclosed by double - % quuotes with the value that the class() function returns - - s=size(object); - if(all(s==1)) - % It's not a vector so we must check how to map it - % Depending on the class of the object we must do one or another thing - switch(class(object)) - case 'function_handle' - % For a function handle we will only print the name - fun=functions(object); - json=['"',fun.function,'"']; - case 'struct' - fields=fieldnames(object); - -results=cellfun(@object2json,struct2cell(object),"UniformOutput",false); - json='{'; - if(numel(fields)>1) - sep=','; - else - sep=''; - endif - for(tmp=1:numel(fields)) - json=[json,'"',fields{tmp},'":',results{tmp},sep]; - if(tmp>=numel(fields)-1) - sep=''; - endif - endfor - json(end+1)='}'; - case 'cell' - % We dereference the cell and use it as a new value - json=object2json(object{1}); - case 'double' - if(isreal(object)) - json=num2str(object); - else - if(iscomplex(object)) - -json=['{"real":',num2str(real(object)),',"imag":',num2str(imag(object)),'}']; - endif - endif - case 'char' - % Here we handle a single char - json=['"',object,'"']; - otherwise - % We don't know what is it so we'll put the class name - json=['"',class(object),'"']; - endswitch - else - % It's a vector so it maps to an array - sep=''; - if(numel(s)>2) - json='['; - for(tmp=1:s(1)) - json=[json,sep,object2json(reshape(object(tmp,:),s(2:end)))]; - sep=','; - endfor - json(end+1)=']'; - else - % We can have three cases here: - % Object is a row -> array with all the elements - % Object is a column -> each element is an array in it's own - % Object is a 2D matrix -> separate each row - if(s(1)==1) - % Object is a row - if(ischar(object)) - % If it's a row of chars we will take it as a string - json=['"',object,'"']; - else - json='['; - for(tmp=1:s(2)) - json=[json,sep,object2json(object(1,tmp))]; - sep=','; - endfor - json(end+1)=']'; - endif - elseif(s(2)==1) - % Object is a column - json='['; - for(tmp=1:s(1)) - json=[json,'[',object2json(object(tmp,1)),']']; - endfor - json(end+1)=']'; - else - % Object is a 2D matrix - json='['; - for(tmp=1:s(1)) - json=[json,sep,object2json(object(tmp,:))]; - sep=','; - endfor - json(end+1)=']'; - endif - endif - endif -endfunction +%% Copyright (C) 2010 Torre Herrera, Daniel de +%% +%% This program is free software; you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation; either version 2 of the License, or +%% (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with Octave; see the file COPYING. If not, see +%% <http://www.gnu.org/licenses/>. +%% object2json.m +%% Created: 2010-12-06 +%% Updates: +%% 2011-01-23 Added support for especial chars and escaped sequences +%% 2011-04-01 Fixed error: Column vectors not working correctly +%% 2011-09-08 (Philip Nienhuis) layout & style changes cf. Octave coding style + +function json = object2json (object) + + % function json = object2json (object) + % This function returns a valid json string that will describe object + % The string will be in a compact form (i.e. no spaces or line breaks) + % + % It will map simple octave values this way: + % function handles: string with the name of the function + % double (numbers): depends: + % If it's real it will map to a string representing that number + % If it's complex it will map to an object with the next properties: + % real: real part of the number + % imag: imaginary part of the number + % char: A string enclosed by double quotes representing that character + % And will map more complex octave values this other way: + % struct: an object with properties equal to the struct's field names + % and value equal to the json counterpart of that field + % cell: it will be mapped depending on the value of the cell (for + % example {i} will be mapped to an object with real=0 and imag=1) + % vectors or cell arrays: it will map them to a corresponding js + % array (same size) with the values transformed to their json + % counterpart (Note: that in javascript all arrays are like octave's + % cells ,i.e. they can store different type and size variables) + % strings or char vectors: they will be mapped to the same string + % enclosed by double quotes + % Other octave values will be mapped to a string enclosed by double + % quotes with the value that the class() function returns + % It can handle escape sequences and special chars automatically. + % If they're valid in JSON it will keep them if not they'll be + % escaped so they can become valid + + s = size (object); + if (all (s==1)) + % It's not a vector so we must check how to map it + % Depending on the class of the object we must do one or another thing + switch (class (object)) + case 'function_handle' + % For a function handle we will only print the name + fun = functions (object); + json = [ '"', fun.function, '"' ]; + + case 'struct' + fields = fieldnames (object); + results = cellfun (@object2json, struct2cell (object), "UniformOutput", false); + json = '{'; + if (numel (fields) > 1) + sep = ','; + else + sep = ''; + endif + for (tmp = 1:numel (fields)) + json = [ json, '"', fields{tmp}, '":', results{tmp}, sep ]; + if(tmp >= numel (fields)-1) + sep = ''; + endif + endfor + json(end+1) = '}'; + + case 'cell' + % We dereference the cell and use it as a new value + json = object2json (object{1}); + + case 'double' + if (isreal (object)) + json = num2str (object); + else + if (iscomplex (object)) + json = [ '{"real":', num2str(real(object)), ',"imag":' , num2str(imag(object)), '}' ]; + endif + endif + + case 'char' + % Here we handle a single char + % JSON only admits the next escape sequences: + % \", \\, \/, \b, \f, \n, \r, \t and \u four-hex-digits + % so we must be sure that every other sequence gets replaced + object = replace_non_JSON_escapes (object); + json = [ '"', object, '"' ]; + + otherwise + % We don't know what is it so we'll put the class name + json = [ '"', class(object), '"' ]; + endswitch + + else + % It's a vector so it maps to an array + sep = ''; + if (numel (s) > 2) + json = '['; + for (tmp=1:s(1)) + json = [ json, sep, object2json(reshape(object(tmp, :), s(2:end))) ]; + sep = ','; + endfor + json(end+1) = ']'; + + else + % We can have three cases here: + % Object is a row -> array with all the elements + % Object is a column -> each element is an array in it's own + % Object is a 2D matrix -> separate each row + if (s(1) == 1) + % Object is a row + if (ischar (object)) + % If it's a row of chars we will take it as a string + % JSON only admits the next escape sequences: + % \", \\, \/, \b, \f, \n, \r, \t and \u four-hex-digits + % so we must be sure that every other sequence gets replaced + object = replace_non_JSON_escapes (object); + json = [ '"', object, '"']; + + else + json = '['; + for (tmp=1:s(2)) + json = [ json, sep, object2json(object(1, tmp)) ]; + sep = ','; + endfor + json(end+1) = ']'; + endif + + elseif (s(2) == 1) + % Object is a column + json = '['; + for (tmp=1:s(1)) + json = [ json, sep, '[', object2json(object(tmp, 1)), ']' ]; + sep = ','; + endfor + json(end+1) = ']'; + + else + % Object is a 2D matrix + json = '['; + for (tmp=1:s(1)) + json = [ json, sep, object2json(object(tmp, :)) ]; + sep = ','; + endfor + json(end+1) = ']'; + + endif + endif + endif + +endfunction + + +% JSON only admits the next escape sequences: +% \", \\, \/, \b, \f, \n, \r, \t and \u four-hex-digits +% This function replace every escaped sequence that isn't on that list +% with a compatible version +% Note that this function uses typeinfo so it may need to be updated +% with each octave release + +function object = replace_non_JSON_escapes (object) + + if (strcmp (typeinfo (object), 'string')) + % It's a double quoted string so newlines and other chars need + % to be converted back into escape sequences before anything + object = undo_string_escapes (object); + endif + % This first regex handles double quotes and slashes that are not + % after a backslash and thus aren't escaped + object = regexprep (object, '(?<!\\)(["/])', "\\$1"); + % This regex handle double quotes and slashes that are after an even + % number of backslashes and thus aren't escaped + object = regexprep (object, '(?<!\\)(\\\\)*(["/])', "$1\\$2"); + % This last one regexp handle any other valid JSON escape sequence + object = regexprep (object, '(?<!\\)\\(?=(\\\\)*(?!([\"\\\/bfnrt]|([u][0-9A-Fa-f]{4}))+?))', "\\\\"); + +endfunction Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -111,7 +111,7 @@ ## 2011-03-23 First try of odfdom 0.8.7 ## 2011-05-15 Experimental UNO support added ## -## Last update of subfunctions below: 2012-12-08 +## Last update of subfunctions below: 2011-09-08 function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange=[], spsh_opts=[]) @@ -188,7 +188,7 @@ #============================================================================= -## Copyright (C) 2010 Philip Nienhuis <prn...@us...> +## Copyright (C) 2010,2011 Philip Nienhuis <prn...@us...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -630,7 +630,7 @@ #============================================================================= -## Copyright (C) 2009 Philip Nienhuis <prnienhuis _at- users.sf.net> +## Copyright (C) 2010,2011 Philip Nienhuis <prnienhuis _at- users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -828,7 +828,7 @@ #============================================================================= -## Copyright (C) 2009-2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -1007,6 +1007,9 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-05-15 +## Updates: +## 2011-summer <many many improvements> +## 2011-09-08 Stylistic changes function [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts) @@ -1018,7 +1021,7 @@ sheets = ods.workbook.getSheets (); sh_names = sheets.getElementNames (); # Check sheet pointer - # FIXME sheet capacity check needed + # FIXME sheet capacity check needed. How many can fit in an OOo sprsh.file? if (isnumeric (wsh)) if (wsh < 1) error ("Illegal sheet index: %d", wsh); @@ -1105,11 +1108,11 @@ otherwise # Empty cell endswitch - changed = 1; + changed = 1; catch printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); keyboard - end_try_catch + end_try_catch endfor endfor Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -105,6 +105,7 @@ ## 2011-03-29 OpenXLS support added. Works but saving to file (xlsclose) doesn't work yet ## " Bug fixes (stray variable c_arr, and wrong test for valid xls struct) ## 2011-05-18 Experimental UNO support +## 2011-09-08 Bug fix in range arg check; code cleanup ## Last script file update (incl. subfunctions): 2011-05-18 (oct2uno2xls) @@ -138,7 +139,7 @@ # Check worksheet ptr if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif # Check range - if (~(isempty (crange) || ischar (crange))), error ("Character string (range) expected for arg # 4"); endif + if (isempty (crange) || ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif # Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; @@ -164,7 +165,7 @@ [xls, rstatus] = oct2jxla2xls (obj, xls, wsh, crange, spsh_opts); elseif (strcmp (xls.xtype, 'OXS')) # # Invoke Java and OpenXLS ##### Not complete, saving file doesn't work yet! - printf ('Sorry, writing with OpenXLS not supported yet\n'); + printf ('Sorry, writing with OpenXLS not reliable => not supported yet\n'); # [xls, rstatus] = oct2oxs2xls (obj, xls, wsh, crange, spsh_opts); elseif (strcmp (xls.xtype, 'UNO')) # Invoke Java and UNO bridge (OpenOffice.org) @@ -243,7 +244,7 @@ function [ xls, status ] = oct2com2xls (obj, xls, wsh, crange, spsh_opts) # Preliminary sanity checks - if (~strmatch (tolower (xls.filename(end-4:end)), '.xls')) + if (~strmatch (lower (xls.filename(end-4:end)), '.xls')) error ("oct2com2xls can only write to Excel .xls or .xlsx files") endif if (isnumeric (wsh)) @@ -718,7 +719,7 @@ # First make sure formula functions are all uppercase obj{ii, jj} = toupper (obj{ii, jj}); # There's no guarantee for formula correctness, so.... - try # Actually JExcelAPI flags formula errors as warnings :-( + try # Actually JExcelAPI flags formula errors as mere warnings :-( tmp = java_new ('jxl.write.Formula', kk, ll, obj{ii, jj}); # ... while errors are actually detected in addCell(), so # that should be within the try-catch @@ -980,7 +981,7 @@ switch typearr(ii, jj) case 1 # Float XCell.setValue (c_arr{ii, jj}); - case 2 # Logical. Convert to float + case 2 # Logical. Convert to float as OOo has no Boolean type XCell.setValue (double (c_arr{ii, jj})); case 3 # String unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -194,7 +194,7 @@ #===================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis _at- users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis _at- users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -410,7 +410,7 @@ #=========================================================================== -## Copyright (C) 2010 Philip Nienhuis <prn...@us...> +## Copyright (C) 2010,2011 Philip Nienhuis <prn...@us...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -544,7 +544,7 @@ rawarr(ii-trow+1, jj-lcol+1) = ocell.getBooleanValue (); case 'string' rawarr(ii-trow+1, jj-lcol+1) = ocell.getStringValue (); -# # Code left in for in case odfdom 0.8.6 has similar bug +# # Code left in for in case odfdom 0.8.6+ has similar bug # # as 0.7.5 # cvalue = tcell.getOfficeStringValueAttribute (); # if (isempty (cvalue)) # Happens with e.g., hyperlinks @@ -577,7 +577,7 @@ #=========================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/io/inst/odsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/odsclose.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odsclose.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -63,6 +63,7 @@ ## 2011-05-06 Experimental UNO support ## 2011-05-07 In case of UNO, soffice now properly closed using xDesk ## 2011-05-18 Saving newly created files using UNO supported now +## 2011-09-08 FIXME - closing OOo kills all other OOo invocations (known Java-UNO issue) function [ ods ] = odsclose (ods, varargs) Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -242,7 +242,7 @@ catch # 1.2b2 has not ods.odfvsn = 2; - printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2b3+\n"); + printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2\n"); end_try_catch odssupport += 2; catch Modified: trunk/octave-forge/main/io/inst/odsread.m =================================================================== --- trunk/octave-forge/main/io/inst/odsread.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odsread.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -113,6 +113,7 @@ ## 2010-05-31 Updated help text (delays i.c.o. empty range due to getusedrange call) ## 2010-11-10 Updated help text (filename extension req'd) ## 2010-11-13 Added some input validity checks +## 2011-09-08 Catch empty ods structs after failed odsopen attempts function [ numarr, txtarr, rawarr, lim ] = odsread (filename, wsh=1, datrange=[], reqintf=[]) @@ -124,15 +125,19 @@ endif ods = odsopen (filename, 0, reqintf); + + if (~isempty (ods)) - [rawarr, ods, rstatus] = ods2oct (ods, wsh, datrange); + [rawarr, ods, rstatus] = ods2oct (ods, wsh, datrange); - if (rstatus) - [numarr, txtarr, lim] = parsecell (rawarr, ods.limits); - else - warning (sprintf ("No data read from %s.", filename)); - endif + if (rstatus) + [numarr, txtarr, lim] = parsecell (rawarr, ods.limits); + else + warning (sprintf ("No data read from %s.", filename)); + endif - ods = odsclose (ods); + ods = odsclose (ods); + endif + endfunction Modified: trunk/octave-forge/main/io/inst/odswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/odswrite.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/odswrite.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -88,6 +88,7 @@ ## 2010-08-25 Removed text about 31 char limit for sheet names (invalid) ## 2010-11-13 Added note about required file extension in help text ## 2010-11-13 Added some input arg checks +## 2011-09-08 Minor filename error text adaptation function [ rstatus ] = odswrite (filename, data, wsh=1, range=[], reqintf=[]) @@ -95,7 +96,7 @@ if (nargin < 2) usage ("Insufficient arguments - see 'help odswrite'"); elseif (~ischar (filename) || isempty (findstr ('.ods', tolower (filename)))) - error ("First argument must be a filename (incl. .ods suffix)"); + error ("First argument must be a filename (incl. .ods suffix for OTK & JOD)"); endif ods = odsopen (filename, 1, reqintf); Modified: trunk/octave-forge/main/io/inst/parsecell.m =================================================================== --- trunk/octave-forge/main/io/inst/parsecell.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/parsecell.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -61,6 +61,7 @@ ## 2010-10-15 Simplified code for numerical array ## 2011-05-17 Fixed subscript indexing bug in cropping section when rawarr is ## " numeric scalar +## 2011-09-08 Copyright string updated function [ numarr, txtarr, lim ] = parsecell (rawarr, arg2=[]) Modified: trunk/octave-forge/main/io/inst/spsh_chkrange.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_chkrange.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/spsh_chkrange.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -70,6 +70,7 @@ case { 'UNO' } # ODS; LibreOffice has a higher row capacity # FIXME - use UNO calls to check physical row capacity + # FIXME - LibreOffice has higher row capacity but it's Java classes haven't been updated ROW_CAP = 65536; COL_CAP = 1024; otherwise error (sprintf ("Unknown interface type - %s\n", xtype)); Modified: trunk/octave-forge/main/io/inst/spsh_prstype.m =================================================================== --- trunk/octave-forge/main/io/inst/spsh_prstype.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/spsh_prstype.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -42,30 +42,30 @@ # 1 = numeric # 2 = boolean # 3 = text - # 4 = formula + # 4 = formula # 5 = error / NaN / empty typearr = ctype(5) * ones (nrows, ncols); # type "EMPTY", provisionally obj2 = cell (size (obj)); # Temporary storage for strings - txtptr = cellfun ('isclass', obj, 'char'); # type "STRING" replaced by "NUMERIC" + txtptr = cellfun ('isclass', obj, 'char'); # type "STRING" replaced by "NUMERIC" obj2(txtptr) = obj(txtptr); obj(txtptr) = ctype(3); # Save strings in a safe place emptr = cellfun ("isempty", obj); obj(emptr) = ctype(5); # Set empty cells to NUMERIC - lptr = cellfun ("islogical" , obj); # Find logicals... + lptr = cellfun ("islogical" , obj); # Find logicals... obj2(lptr) = obj(lptr); # .. and set them to BOOLEAN - ptr = cellfun ("isnan", obj); # Find NaNs & set to BLANK + ptr = cellfun ("isnan", obj); # Find NaNs & set to BLANK typearr(ptr) = ctype(5); typearr(~ptr) = ctype(1); # All other cells are now numeric - obj(txtptr) = obj2(txtptr); # Copy strings back into place + obj(txtptr) = obj2(txtptr); # Copy strings back into place obj(lptr) = obj2(lptr); # Same for logicals - obj(emptr) = -1; # Add in a filler value for empty cells + obj(emptr) = -1; # Add in a filler value for empty cells - typearr(txtptr) = ctype(3); # ...and clean up - typearr(emptr) = ctype(5); # EMPTY + typearr(txtptr) = ctype(3); # ...and clean up + typearr(emptr) = ctype(5); # EMPTY typearr(lptr) = ctype(2); # BOOLEAN if ~(spsh_opts.formulas_as_text) Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -117,6 +117,7 @@ ## 2011-03-26 OpenXLS support added ## 2011-03-29 Test for proper input xls struct extended ## 2011-05-18 Experimental UNO support added +## 2011-09-08 Minor code layout ## ## Latest subfunc update: 2011-05-18 (UNO) @@ -132,6 +133,7 @@ if test1 error ("Invalid xls file pointer struct"); endif + # Check worksheet ptr if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 2"); endif # Check range @@ -467,7 +469,7 @@ type_of_cell = scell.getCellType (); if (type_of_cell == ctype(3)) # Formula if ~(spsh_opts.formulas_as_text) - try # Because not al Excel formulas have been implemented + try # Because not al Excel formulas have been implemented in POI cvalue = frm_eval.evaluate (scell); type_of_cell = cvalue.getCellType(); # Separate switch because form.eval. yields different type @@ -601,7 +603,7 @@ shnames = char (wb.getSheetNames ()); if (isnumeric (wsh)) if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif - sh = wb.getSheet (wsh - 1); # POI sheet count 0-based + sh = wb.getSheet (wsh - 1); # JXL sheet count 0-based printf ("(Reading from worksheet %s)\n", shnames {wsh}); else sh = wb.getSheet (wsh); Modified: trunk/octave-forge/main/io/inst/xlsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsclose.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsclose.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -24,7 +24,7 @@ ## ## If no errors occured during writing, the xls file pointer struct will be ## reset and -if COM interface was used- ActiveX/Excel will be closed. -## However if errors occurred, the file pinter will be ontouched so you can +## However if errors occurred, the file pinter will be untouched so you can ## clean up before a next try with xlsclose(). ## Be warned that until xlsopen is called again with the same @var{xls} pointer ## struct, hidden Excel or Java applications with associated (possibly large) @@ -70,6 +70,7 @@ ## always keep file pointer in case of write errors ## 2011-03-26 Added OpenXLS support ## 2011-05-18 Added experimental UNO support, incl. saving newly created files +## 2011-09-08 Bug fix in check for filename input arg function [ xls ] = xlsclose (xls, varargs) @@ -86,16 +87,16 @@ printf ("File %s wasn't changed, new filename ignored.", xls.filename); elseif (strcmp (xls.xtype, 'JXL')) error ("JXL doesn't support changing filename, new filename ignored."); - elseif ~((strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'UNO')) && isempty (strfind ('filename', '.xls'))) + elseif ~((strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'UNO')) && isempty (strfind ( lower (filename), '.xls'))) # Excel/ActiveX && OOo (UNO bridge) will write any valid filetype; POI/JXL/OXS need .xls[x] error ('.xls or .xlsx extension lacking in filename %s', filename); else ### For multi-user environments, uncomment below AND relevant stanza in xlsopen # In case of COM, be sure to first close the open workbook #if (strcmp (xls.xtype, 'COM')) - # xls.app.Application.DisplayAlerts = 0; - # xls.workbook.close(); - # xls.app.Application.DisplayAlerts = 0; + # xls.app.Application.DisplayAlerts = 0; + # xls.workbook.close(); + # xls.app.Application.DisplayAlerts = 0; #endif if (strcmp (xls.xtype, 'UNO')) # If needed, turn filename into URL @@ -115,6 +116,7 @@ endif endif endif + # Preprocessing / -checking ready. Assign filename arg to file ptr struct xls.filename = filename; endif endif Modified: trunk/octave-forge/main/io/inst/xlsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsfinfo.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -82,6 +82,7 @@ ## 2010-11-01 Added other file type strings for return arg #3 (fformat) ## 2011-03-26 Added OpenXLS support ## 2011-05-18 Experimental UNO support +## 2011-09-08 Some code simplifications function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[]) @@ -118,13 +119,13 @@ endif endfor if (ws_cnt > 0 || ch_cnt > 0) - if (strcmp (tolower (xls.filename(end-2:end)), 'xls')) + if (strcmpi (xls.filename(end-2:end), 'xls')) fformat = "xlWorkbookNormal"; - elseif (strcmp (tolower (xls.filename(end-2:end)), 'csv')) + elseif (strcmpi (xls.filename(end-2:end), 'csv')) fformat = "xlCSV"; # Works only with COM - elseif (strcmp (tolower (xls.filename(end-3:end-1)), 'xls')) + elseif (strcmpi (xls.filename(end-3:end-1), 'xls')) fformat = "xlOpenXMLWorkbook"; - elseif (strmatch ('htm', tolower (xls.filename(end-3:end)))) + elseif (strmatch ('htm', lower (xls.filename(end-3:end)))) fformat = "xlHtml"; # Works only with COM else fformat = ''; @@ -147,9 +148,9 @@ endif endfor if (sh_cnt > 0) - if (strcmp (tolower (xls.filename(end-2:end)), 'xls')) + if (strcmpi (xls.filename(end-2:end), 'xls')) fformat = "xlWorkbookNormal"; - elseif (strcmp (tolower (xls.filename(end-3:end-1)), 'xls')) + elseif (strcmpi (xls.filename(end-3:end-1), 'xls')) fformat = "xlOpenXMLWorkbook"; else fformat = ''; Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -102,6 +102,7 @@ ## 2011-05-29 Cleanup of comments & messages ## 2011-09-03 Reset chkintf to [] if no xls support was discovered (to allow ## rediscovery of interfaces between xlsopen calls, e.g. javaclasspath changes) +## 2011-09-08 Minor code cleanup ## ## 2011-09-03 Latest subfunction update @@ -119,9 +120,11 @@ if (nargout < 1) usage ("XLS = xlsopen (Xlfile [, Rw] [, reqintf]). But no return argument specified!"); endif + if (~(islogical (xwrite) || isnumeric (xwrite))) usage ("Numerical or logical value expected for arg # 2") endif + if (~isempty (reqinterface)) if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif # Turn arg3 into cell array if needed @@ -154,7 +157,7 @@ for ii=1:numel (reqinterface) if (~xlsinterfaces.(toupper (reqinterface{ii}))) # No it aint - printf ("%s is not supported.\n", toupper (reqinterface{ii})); + printf ("%s is not supported.\n", upper (reqinterface{ii})); else ++xlsintf_cnt; endif @@ -196,8 +199,8 @@ xlsinterfaces = getxlsinterfaces (xlsinterfaces); # Supported interfaces determined; Excel file type check moved to seperate interfaces. - chk1 = strcmpi (filename(end-3:end), '.xls'); - chk2 = strcmpi (filename(end-4:end-1), '.xls'); + chk1 = strcmpi (filename(end-3:end), '.xls'); # Regular (binary) BIFF + chk2 = strcmpi (filename(end-4:end-1), '.xls'); # Zipped XML / OOXML # Initialize file ptr struct xls = struct ("xtype", 'NONE', "app", [], "filename", [], "workbook", [], "changed", 0, "limits", []); @@ -245,8 +248,6 @@ wb = java_new ('org.apache.poi.hssf.usermodel.HSSFWorkbook'); elseif (chk2) wb = java_new ('org.apache.poi.xssf.usermodel.XSSFWorkbook'); - else - # Nothing; we let the user encounter the full java error text endif xls.app = 'new_POI'; else @@ -287,7 +288,7 @@ catch clear xlsin; if (xlsinterfaces.POI) - printf ('... No luck with JXL, unsupported file format.\n', filename); + printf ('... No luck with JXL either, unsupported file format.\n', filename); endif end_try_catch endif @@ -378,7 +379,7 @@ # Until something was written to existing files we keep status "unchanged". # xls.changed = 0 (existing/only read from), 1 (existing/data added), 2 (new, # data added) or 3 (pristine, no data added). - if (xls.changed == 1) xls.changed = 0; endif + if (xls.changed == 1), xls.changed = 0; endif endif # Rounding up. If none of the xlsinterfaces is supported we're out of luck. @@ -445,10 +446,11 @@ ## 2011-06-13 Fixed potentially faulty tests for java classlib presence ## 2011-09-03 Fixed order of xlsinterfaces.<member> statements in Java detection try-catch ## '' Reset tmp1 (always allow interface rediscovery) for empty xlsinterfaces arg +## 2011-09-08 Minor code cleanup function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) - # tmp1 = [] (not initialized), 0 (No java detected), or 1 (Working Java found) + # tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) persistent tmp1 = []; persistent jcp; # Java class path if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS)) @@ -488,7 +490,7 @@ jver = char (java_invoke ('java.lang.System', 'getProperty', 'java.version')); cjver = strsplit (jver, '.'); if (sscanf (cjver{2}, '%d') < 6) - warning ("\nJava version too old - you need at least Java 6 (v. 1.6.x.x)\n"); + warning ("\nJava version might be too old - you need at least Java 6 (v. 1.6.x.x)\n"); return endif # Now check for proper entries in class path. Under *nix the classpath @@ -502,7 +504,7 @@ # Some Java-based interface requested but Java support is absent error (' No Java support found.'); else - # No specific Java-based interface requested. Just return + # No specific Java-based interface requested xlsinterfaces.POI = 0; xlsinterfaces.JXL = 0; xlsinterfaces.OXS = 0; @@ -536,7 +538,7 @@ jpchk2 = 0; entries2 = {"xbean", "poi-ooxml-schemas", "dom4j"}; for ii=1:length (jcp) for jj=1:length (entries2) - if (isempty (strfind (tolower (jcp{ii}), entries2{jj}))), ++jpchk2; endif + if (isempty (strfind (lower (jcp{ii}), entries2{jj}))), ++jpchk2; endif endfor endfor if (jpchk2 > 2), printf (" (& OOXML)"); endif @@ -551,7 +553,7 @@ jpchk = 0; entries = {"jxl"}; for ii=1:length (jcp) for jj=1:length (entries) - if (isempty (strfind (tolower (jcp{ii}), entries{jj}))), ++jpchk; endif + if (isempty (strfind (lower (jcp{ii}), entries{jj}))), ++jpchk; endif endfor endfor if (jpchk > 0) @@ -567,7 +569,7 @@ jpchk = 0; entries = {"openxls"}; for ii=1:length (jcp) for jj=1:length (entries) - if (isempty (strfind (tolower (jcp{ii}), entries{jj}))), ++jpchk; endif + if (isempty (strfind (lower (jcp{ii}), entries{jj}))), ++jpchk; endif endfor endfor if (jpchk > 0) Modified: trunk/octave-forge/main/io/inst/xlsread.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsread.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlsread.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 by Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 by Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License @@ -146,16 +146,17 @@ ## 2010-11-13 Added some input checks ## 2011-04-11 Return upon empty xls struct from xlsopen() ## 2011-04-17 Suppress xlsopen messages (";" was missing) +## 2011-09-08 Minor code cleanup; included UNO & OXS support in test function [ numarr, txtarr, rawarr, lims ] = xlsread (fn, wsh, datrange, reqintf=[]) rstatus = 0; if (nargout < 1) - usage ("xlsread: no output argument(s) specified"); + usage ("xlsread: no output argument(s) specified that should receive data"); endif if (nargin < 1) - error ("xlsread: no arguments specified") + error ("xlsread: no input arguments specified") numarr = []; txtarr={}; rawarr = {}; return elseif (nargin == 1) @@ -163,7 +164,7 @@ datrange = ''; elseif (nargin == 2) # Find out whether 2nd argument = worksheet or range - if (isnumeric (wsh) || (isempty (findstr(wsh,':')) && ~isempty (wsh))) + if (isnumeric (wsh) || (isempty (findstr (wsh,':')) && ~isempty (wsh))) # Apparently a worksheet specified datrange = ''; else @@ -174,15 +175,13 @@ endif # A small gesture for Matlab compatibility. JExcelAPI supports BIFF5. - if (~isempty (reqintf) && ischar (reqintf) && strcmp (toupper(reqintf), 'BASIC')) + if (~isempty (reqintf) && ischar (reqintf) && strcmpi (reqintf, 'BASIC')) reqintf= {"JXL"} ; - printf ("BASIC (BIFF5) support request translated to JXL. \n"); + printf ("(BASIC (BIFF5) support request translated to JXL.) \n"); endif - - if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified as argument.\n"); endif # Checks done. Get raw data into cell array "rawarr". xlsopen finds out - # what interface to use. If none found, suggest csv + # what interface to use. If none found, just return as xlsopen will complain enough unwind_protect # Needed to catch COM errors & able to close stray Excel invocations # Get pointer array to Excel file @@ -194,7 +193,8 @@ return endif - if (strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'POI') || strcmp (xls.xtype, 'JXL')) +# if (strcmp (xls.xtype, 'COM') || strcmp (xls.xtype, 'POI') || strcmp (xls.xtype, 'JXL')... +# || strcmp (xls.xtype, 'OXS') || strcmp (xls.xtype, 'UNO')) # Get data from Excel file & return handle [rawarr, xls, rstatus] = xls2oct (xls, wsh, datrange); @@ -209,13 +209,13 @@ rawarr = {}; numarr = []; txtarr = {}; endif - else - printf ("Error XLSREAD: reading EXCEL file (BIFF- or OOXML Format) isn\'t supported on this system.\n"); - printf ("You need to convert the file into a tab- or comma delimited text file or .csv file\n"); - printf ("and then invoke csvread(), dlmread() or textread()\n\n"); +# else +# printf ("Error XLSREAD: reading EXCEL file (BIFF- or OOXML Format) isn\'t supported on this system.\n"); +# printf ("You need to convert the file into a tab- or comma delimited text file or .csv file\n"); +# printf ("and then invoke csvread(), dlmread() or textread()\n\n"); +# +# endif - endif - unwind_protect_cleanup # Close Excel file if (xls_ok) xls = xlsclose (xls); endif Modified: trunk/octave-forge/main/io/inst/xlswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/xlswrite.m 2011-09-08 16:20:47 UTC (rev 8511) +++ trunk/octave-forge/main/io/inst/xlswrite.m 2011-09-08 17:35:32 UTC (rev 8512) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -95,7 +95,8 @@ ## 2010-01-15 Fixed typos in texinfo ## 2010-08-18 Added check for existence of xls after call to xlsopen to ## avoid unneeded error message clutter -## 2010-10-27 Chnged range -> crange to unhide other range functions +## 2010-10-27 Changed range -> crange to unhide other range functions +## 2011-09-08 Minor code syntax updates function [ rstatus ] = xlswrite (filename, arr, arg3, arg4, arg5) @@ -160,7 +161,7 @@ [xls, rstatus] = oct2xls (arr(1:nr, 1:nc), xls, wsh, topleft); unwind_protect_cleanup - if (xls_ok) xls = xlsclose (xls); endif + if (xls_ok), xls = xlsclose (xls); endif end_unwind_protect This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-18 16:24:21
|
Revision: 8554 http://octave.svn.sourceforge.net/octave/?rev=8554&view=rev Author: prnienhuis Date: 2011-09-18 16:24:15 +0000 (Sun, 18 Sep 2011) Log Message: ----------- Added warning message about experimental status of UNO interface Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2011-09-18 16:23:11 UTC (rev 8553) +++ trunk/octave-forge/main/io/inst/odsopen.m 2011-09-18 16:24:15 UTC (rev 8554) @@ -90,7 +90,7 @@ ## 2011-09-03 Reset chkintf if no ods support was found to allow full interface rediscovery ## (otherwise javaclasspath additions will never be picked up) ## -## Latest change on subfunction below: 2011-09-03 +## Latest change on subfunctions below: 2011-09-18 function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) @@ -292,7 +292,7 @@ ods.filename = filename; ods.xtype = 'UNO'; ods.app.xComp = xComp; # Needed to be able to close soffice in odsclose() - ods.app.aLoader = aLoader; # Needed to be able to close soffice in odsclose() + ods.app.aLoader = aLoader; # Needed to be able to close soffice in odsclose() ods.odfvsn = 'UNO'; odssupport += 4; catch @@ -387,11 +387,12 @@ ## " Tamed down verbosity ## 2011-09-03 Fixed order of odsinterfaces.<member> statement in Java detection try-catch ## " Reset tmp1 (always allow interface rediscovery) for empty odsinterfaces arg +## 2011-09-18 Added temporary warning about UNO interface - function [odsinterfaces] = getodsinterfaces (odsinterfaces) persistent tmp1 = []; persistent jcp; + persistent uno_1st_time = []; if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) # Assume no interface detection has happened yet @@ -519,5 +520,16 @@ # ---- 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: + if (isempty (uno_1st_time) && odsinterfaces.UNO); + uno_1st_time = 1; + printf ("\nPLEASE NOTE: UNO (=OpenOffice.org-behind-the-scenes) is EXPERIMENTAL\n"); + printf ("After you've opened a spreadsheet file using the UNO interface,\n"); + printf ("odsclose on that file will kill ALL OpenOffice.org invocations,\n"); + printf ("also those that were started outside and/or before Octave!\n"); + printf ("Trying to quit Octave w/o invoking odsclose will only hang Octave.\n\n"); + endif endfunction Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-18 16:23:11 UTC (rev 8553) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2011-09-18 16:24:15 UTC (rev 8554) @@ -50,7 +50,7 @@ ## interface that otherwise is automatically selected by xlsopen. Currently ## implemented interfaces (in order of preference) are 'COM' (Excel/COM), ## 'POI' (Java/Apache POI), 'JXL' (Java/JExcelAPI), 'OXS' (Java/OpenXLS), or -## 'UNO' (Java/OpenOffice.org). +## 'UNO' (Java/OpenOffice.org - EXPERIMENTAL!). ## In most situations this parameter is unneeded as xlsopen automatically ## selects the most useful interface present. ## @@ -104,7 +104,7 @@ ## rediscovery of interfaces between xlsopen calls, e.g. javaclasspath changes) ## 2011-09-08 Minor code cleanup ## -## 2011-09-03 Latest subfunction update +## 2011-09-18 Latest subfunction update function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) @@ -447,11 +447,13 @@ ## 2011-09-03 Fixed order of xlsinterfaces.<member> statements in Java detection try-catch ## '' Reset tmp1 (always allow interface rediscovery) for empty xlsinterfaces arg ## 2011-09-08 Minor code cleanup +## 2011-09-18 Added temporary warning about UNO interface function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) # tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) persistent tmp1 = []; persistent jcp; # Java class path + persistent uno_1st_time; if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS)) printf ("Detected interfaces: "); @@ -602,4 +604,15 @@ 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: + if (isempty (uno_1st_time) && xlsinterfaces.UNO); + uno_1st_time = 1; + printf ("\nPLEASE NOTE: UNO (=OpenOffice.org-behind-the-scenes) is EXPERIMENTAL\n"); + printf ("After you've opened a spreadsheet file using the UNO interface,\n"); + printf ("xlsclose on that file will kill ALL OpenOffice.org invocations,\n"); + printf ("also those that were started outside and/or before Octave!\n"); + printf ("Trying to quit Octave w/o invoking xlsclose will only hang Octave.\n\n"); + endif + endfunction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-18 16:25:56
|
Revision: 8555 http://octave.svn.sourceforge.net/octave/?rev=8555&view=rev Author: prnienhuis Date: 2011-09-18 16:25:50 +0000 (Sun, 18 Sep 2011) Log Message: ----------- Adapted sh_names variable handling to support class changes in LibreOffice 3.4.+ Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/xls2oct.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-18 16:24:15 UTC (rev 8554) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-18 16:25:50 UTC (rev 8555) @@ -111,7 +111,7 @@ ## 2011-03-23 First try of odfdom 0.8.7 ## 2011-05-15 Experimental UNO support added ## -## Last update of subfunctions below: 2011-09-08 +## Last update of subfunctions below: 2011-09-18 function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange=[], spsh_opts=[]) @@ -136,7 +136,7 @@ test1 = test1 || isempty (ods.workbook); test1 = test1 || isempty (ods.app); if test1 - error ("Invalid ods file pointer struct"); + 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 @@ -1010,6 +1010,7 @@ ## Updates: ## 2011-summer <many many improvements> ## 2011-09-08 Stylistic changes +## 2011-09-18 Adapted sh_names type to LO 3.4.1 function [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts) @@ -1020,6 +1021,12 @@ # Get handle to sheet, create a new one if needed sheets = ods.workbook.getSheets (); sh_names = sheets.getElementNames (); + if (! iscell (sh_names)) + # Java array (LibreOffice 3.4.+); convert to cellstr + sh_names = char (sh_names); + else + sh_names = {sh_names}; + endif # Check sheet pointer # FIXME sheet capacity check needed. How many can fit in an OOo sprsh.file? if (isnumeric (wsh)) @@ -1028,13 +1035,13 @@ elseif (wsh > numel (sh_names)) # 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}); + 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; while (ii <= maxtry) shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); - if (isempty (strmatch (wsh, {sh_names}))) + if (isempty (strmatch (wsh, sh_names))) ii = 10; else ++ii; @@ -1052,7 +1059,7 @@ endif else # wsh is a sheet name. See if it exists already - if (isempty (strmatch (wsh, {sh_names}))) + if (isempty (strmatch (wsh, sh_names))) # Not found. New sheet to be added newsh = 1; endif @@ -1062,7 +1069,6 @@ shptr = java_new ("java.lang.Short", sprintf ("%d", numel (sh_names) + 1)); sh = sheets.insertNewByName (wsh, shptr); sheets = ods.workbook.getSheets (); - sh_names = sheets.getElementNames (); 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'); Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-18 16:24:15 UTC (rev 8554) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-18 16:25:50 UTC (rev 8555) @@ -107,7 +107,7 @@ ## 2011-05-18 Experimental UNO support ## 2011-09-08 Bug fix in range arg check; code cleanup -## Last script file update (incl. subfunctions): 2011-05-18 (oct2uno2xls) +## Last script file update (incl. subfunctions): 2011-09-18 function [ xls, rstatus ] = oct2xls (obj, xls, wsh=1, crange=[], spsh_opts=[]) @@ -898,6 +898,7 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-05-18 +## 2011-09-18 Adapted sh_names type to LO 3.4.1 function [ xls, rstatus ] = oct2uno2xls (c_arr, xls, wsh, crange, spsh_opts) @@ -908,6 +909,12 @@ # 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 + sh_names = char (sh_names); + else + sh_names = {sh_names}; + endif # Check sheet pointer # FIXME sheet capacity check needed if (isnumeric (wsh)) @@ -916,13 +923,13 @@ elseif (wsh > numel (sh_names)) # 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}); + 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; while (ii <= maxtry) shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); - if (isempty (strmatch (wsh, {sh_names}))) + if (isempty (strmatch (wsh, sh_names))) ii = 10; else ++ii; @@ -940,7 +947,7 @@ endif else # wsh is a sheet name. See if it exists already - if (isempty (strmatch (wsh, {sh_names}))) + if (isempty (strmatch (wsh, sh_names))) # Not found. New sheet to be added newsh = 1; endif @@ -950,7 +957,6 @@ shptr = java_new ("java.lang.Short", sprintf ("%d", numel (sh_names) + 1)); sh = sheets.insertNewByName (wsh, shptr); sheets = xls.workbook.getSheets (); - sh_names = sheets.getElementNames (); 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'); Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-18 16:24:15 UTC (rev 8554) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-18 16:25:50 UTC (rev 8555) @@ -113,7 +113,7 @@ ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to here ## 2011-05-06 Experimental UNO support ## -## (Latest update of subfunctions below: 2010-11-13) +## (Latest update of subfunctions below: 2011-09-18) function [ rawarr, ods, rstatus ] = ods2oct (ods, wsh=1, datrange=[], spsh_opts=[]) @@ -782,12 +782,18 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-05-05 ## Updates: -## +## 2011-09-18 Adapted sh_names type to LO 3.4.1 function [rawarr, ods, rstatus] = ods2uno2oct (ods, wsh, datrange, spsh_opts) sheets = ods.workbook.getSheets (); sh_names = sheets.getElementNames (); + if (! iscell (sh_names)) + # Java array (LibreOffice 3.4.+); convert to cellstr + sh_names = char (sh_names); + else + sh_names = {sh_names}; + endif # Check sheet pointer if (isnumeric (wsh)) @@ -795,7 +801,7 @@ error ("Sheet index %d out of range 1-%d", wsh, numel (sh_names)); endif else - ii = strmatch (wsh, {sh_names}); + ii = strmatch (wsh, sh_names); if (isempty (ii)), error ("Sheet '%s' not found", wsh); endif wsh = ii; endif Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-18 16:24:15 UTC (rev 8554) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-18 16:25:50 UTC (rev 8555) @@ -119,7 +119,7 @@ ## 2011-05-18 Experimental UNO support added ## 2011-09-08 Minor code layout ## -## Latest subfunc update: 2011-05-18 (UNO) +## Latest subfunc update: 2011-09-18 function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) @@ -872,12 +872,18 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-05-05 ## Updates: -## +## 2011-09-18 Adapted sh_names type to LO 3.4.1 function [rawarr, xls, rstatus] = xls2uno2oct (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 + sh_names = char (sh_names); + else + sh_names = {sh_names}; + endif # Check sheet pointer if (isnumeric (wsh)) @@ -885,7 +891,7 @@ error ("Sheet index %d out of range 1-%d", wsh, numel (sh_names)); endif else - ii = strmatch (wsh, {sh_names}); + ii = strmatch (wsh, sh_names); if (isempty (ii)), error ("Sheet '%s' not found", wsh); endif wsh = ii; endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-18 22:15:12
|
Revision: 8561 http://octave.svn.sourceforge.net/octave/?rev=8561&view=rev Author: prnienhuis Date: 2011-09-18 22:15:05 +0000 (Sun, 18 Sep 2011) Log Message: ----------- Adapted to LibreOffice 3.4+ features (mostly better ODS 1.2 compliance) Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/xls2oct.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-18 19:42:52 UTC (rev 8560) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-18 22:15:05 UTC (rev 8561) @@ -1027,52 +1027,70 @@ else sh_names = {sh_names}; endif - # Check sheet pointer - # FIXME sheet capacity check needed. How many can fit in an OOo sprsh.file? - if (isnumeric (wsh)) - if (wsh < 1) - error ("Illegal sheet index: %d", wsh); - elseif (wsh > numel (sh_names)) - # 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; - while (ii <= maxtry) - shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); - if (isempty (strmatch (wsh, sh_names))) - ii = 10; - else - ++ii; + + # Clear default 2 last sheets in case of a new spreadsheet file + if (ods.changed > 2) + ii = numel (sh_names); + while (ii > 1) + shnm = sh_names{ii}; + sheets.removeByName (shnm); + --ii; + endwhile + # 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'); + sh.queryInterface (unotmp).setName (wsh); + else + + # Check sheet pointer + # FIXME sheet capacity check needed. How many can fit in an OOo sprsh.file? + if (isnumeric (wsh)) + if (wsh < 1) + error ("Illegal sheet index: %d", wsh); + elseif (wsh > numel (sh_names)) + # 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; + while (ii <= maxtry) + shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); + if (isempty (strmatch (wsh, sh_names))) + ii = 10; + else + ++ii; + endif + endwhile + if (ii > maxtry + 1) + error ("Could not add sheet with a unique name to file %s"); endif - endwhile - if (ii > maxtry + 1) - error ("Could not add sheet with a unique name to file %s"); endif + wsh = shname; + newsh = 1; + else + # turn wsh index into the associated sheet name + wsh = sh_names (wsh); endif - wsh = shname; - newsh = 1; else - # turn wsh index into the associated sheet name - wsh = sh_names (wsh); + # wsh is a sheet name. See if it exists already + if (isempty (strmatch (wsh, sh_names))) + # Not found. New sheet to be added + newsh = 1; + endif endif - else - # wsh is a sheet name. See if it exists already - if (isempty (strmatch (wsh, sh_names))) - # Not found. New sheet to be added - newsh = 1; + if (newsh) + # 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); + else + # 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 endif - if (newsh) - # 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); - sheets = ods.workbook.getSheets (); - 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'); - sh = sheets.getByName (wsh).getObject.queryInterface (unotmp); # Check size of data array & range / capacity of worksheet & prepare vars [nr, nc] = size (c_arr); @@ -1090,7 +1108,7 @@ fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1), c_arr); typearr(fptr) = ctype(4); # FORMULA endif - +keyboard # Transfer data to sheet for ii=1:nrows for jj=1:ncols Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-18 19:42:52 UTC (rev 8560) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-18 22:15:05 UTC (rev 8561) @@ -915,52 +915,70 @@ else sh_names = {sh_names}; endif - # 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 - 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; - while (ii <= maxtry) - shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); - if (isempty (strmatch (wsh, sh_names))) - ii = 10; - else - ++ii; + + # Clear default 2 last sheets in case of a new spreadsheet file + if (ods.changed > 2) + ii = numel (sh_names); + while (ii > 1) + shnm = sh_names{ii}; + sheets.removeByName (shnm); + --ii; + endwhile + # 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'); + sh.queryInterface (unotmp).setName (wsh); + else + + # 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 + 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; + while (ii <= maxtry) + shname = sprintf ("Sheet%s%d", [filler "_"], numel (sh_names + 1)); + if (isempty (strmatch (wsh, sh_names))) + ii = 10; + else + ++ii; + endif + endwhile + if (ii > maxtry + 1) + error ("Could not add sheet with a unique name to file %s"); endif - endwhile - if (ii > maxtry + 1) - error ("Could not add sheet with a unique name to file %s"); endif + wsh = shname; + newsh = 1; + else + # turn wsh index into the associated sheet name + wsh = sh_names (wsh); endif - wsh = shname; - newsh = 1; else - # turn wsh index into the associated sheet name - wsh = sh_names (wsh); + # wsh is a sheet name. See if it exists already + if (isempty (strmatch (wsh, sh_names))) + # Not found. New sheet to be added + newsh = 1; + endif endif - else - # wsh is a sheet name. See if it exists already - if (isempty (strmatch (wsh, sh_names))) - # Not found. New sheet to be added - newsh = 1; + if (newsh) + # 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); + else + # 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 endif - if (newsh) - # 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); - sheets = xls.workbook.getSheets (); - 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'); - sh = sheets.getByName (wsh).getObject.queryInterface (unotmp); # Check size of data array & range / capacity of worksheet & prepare vars [nr, nc] = size (c_arr); Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-18 19:42:52 UTC (rev 8560) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-18 22:15:05 UTC (rev 8561) @@ -112,6 +112,7 @@ ## " Extended check on spsh_opts (must be a struct) ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to here ## 2011-05-06 Experimental UNO support +## 2011-09-18 Set rstatus var here ## ## (Latest update of subfunctions below: 2011-09-18) @@ -148,26 +149,28 @@ # Read ods file tru Java & ODF toolkit switch ods.odfvsn case '0.7.5' - [rawarr, ods, rstatus] = ods2jotk2oct (ods, wsh, datrange, spsh_opts); + [rawarr, ods] = ods2jotk2oct (ods, wsh, datrange, spsh_opts); case '0.8.6' - [rawarr, ods, rstatus] = ods3jotk2oct (ods, wsh, datrange, spsh_opts); + [rawarr, ods] = ods3jotk2oct (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 :-( - [rawarr, ods, rstatus] = ods2jod2oct (ods, wsh, datrange); + [rawarr, ods] = ods2jod2oct (ods, wsh, datrange); elseif (strcmp (ods.xtype, 'UNO')) # Read ods file tru Java & UNO - [rawarr, ods, rstatus] = ods2uno2oct (ods, wsh, datrange, spsh_opts); + [rawarr, ods] = ods2uno2oct (ods, wsh, datrange, spsh_opts); # 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 - if (spsh_opts.strip_array && ~isempty (rawarr)) + if (spsh_opts.strip_array && rstatus) emptr = cellfun ('isempty', rawarr); if (all (all (emptr))) rawarr = {}; @@ -225,14 +228,13 @@ ## 2010-03-19 More code cleanup & fixes for bugs introduced 18/3/2010 8-() ## 2010-08-03 Added preliminary support for reading back formulas as text strings ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to caller +## 2011-09-18 Remove rstatus var (now set in caller) -function [ rawarr, ods, rstatus ] = ods2jotk2oct (ods, wsh, crange, spsh_opts) +function [ rawarr, ods ] = ods2jotk2oct (ods, wsh, crange, spsh_opts) # Parts after user gfterry in # http://www.oooforum.org/forum/viewtopic.phtml?t=69060 - rstatus = 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 (?) @@ -433,11 +435,12 @@ ## Updates: ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to caller ## 2010-11-13 Added workaround for reading text cells in files made by jOpenDocument 1.2bx +## 2011-09-18 Comment out workaround for jOpenDocument bug (no OfficeValueAttr set) +## because this casts all numeric cells to string type for properly written ODS1.2 +## '' Remove rstatus var (now set in caller) -function [ rawarr, ods, rstatus ] = ods3jotk2oct (ods, wsh, crange, spsh_opts) +function [ rawarr, ods ] = ods3jotk2oct (ods, wsh, crange, spsh_opts) - rstatus = 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 (?) @@ -502,16 +505,16 @@ ocell = row.getCellByIndex (jj-1); if ~isempty (ocell) otype = deblank (tolower (ocell.getValueType ())); - if (spsh_opts.formulas_as_text) + if (spsh_opts.formulas_as_text) if ~isempty (ocell.getFormula ()) 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 +# # 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'} @@ -604,8 +607,11 @@ ## allows better cell type parsing and is therefore more reliable ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to here ## 2010-11-13 Added workaround for reading text cells in files made by jOpenDocument 1.2bx +## 2011-09-18 Comment out workaround for jOpenDocument bug (no OfficeValueAttr set) +## because this casts all numeric cells to string type for properly written ODS1.2 +## '' Remove rstatus var (now set in caller) -function [ rawarr, ods, rstatus] = ods2jod2oct (ods, wsh, crange) +function [ rawarr, ods] = ods2jod2oct (ods, wsh, crange) persistent months; months = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; @@ -674,10 +680,10 @@ try scell = sh.getCellAt (lcol+jj-2, trow+ii-2); sctype = char (scell.getValueType ()); - # Workaround for sheets written by jOpenDocument 1.2bx (no value-type attrb): - if (~isempty (scell)) - if (findstr ('<text:', char (scell))), sctype = STRING; endif - endif +# # Workaround for sheets written by jOpenDocument 1.2bx (no value-type attrb): +# if (~isempty (scell)) +# if (findstr ('<text:', char (scell))), sctype = STRING; endif +# endif switch sctype case { FLOAT, CURRENCY, PERCENTAGE } rawarr{ii, jj} = scell.getValue ().doubleValue (); @@ -755,8 +761,6 @@ # Keep track of data rectangle limits ods.limits = [lcol, rcol; trow, brow]; - - rstatus = ~isempty (rawarr); endfunction @@ -783,8 +787,10 @@ ## Created: 2011-05-05 ## Updates: ## 2011-09-18 Adapted sh_names type to LO 3.4.1 +## '' Remove default 2 last sheets (LibreOffice 3.4.+) +## '' Remove rstatus var (now set in caller) -function [rawarr, ods, rstatus] = ods2uno2oct (ods, wsh, datrange, spsh_opts) +function [rawarr, ods] = ods2uno2oct (ods, wsh, datrange, spsh_opts) sheets = ods.workbook.getSheets (); sh_names = sheets.getElementNames (); @@ -797,7 +803,7 @@ # Check sheet pointer if (isnumeric (wsh)) - if (wsh < 1 || wsh > numel (sh_names)) + if (wsh < 1 || wsh > numel (sh_names)) error ("Sheet index %d out of range 1-%d", wsh, numel (sh_names)); endif else @@ -806,7 +812,7 @@ wsh = ii; endif unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheet'); - sh = sheets.getByName(sh_names(wsh)).getObject.queryInterface (unotmp); + sh = sheets.getByName(sh_names{wsh}).getObject.queryInterface (unotmp); unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XCellRangesQuery'); xRQ = sh.queryInterface (unotmp); @@ -874,6 +880,4 @@ # Keep track of data rectangle limits ods.limits = [lcol, rcol; trow, brow]; - rstatus = ~isempty (rawarr); - endfunction Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-18 19:42:52 UTC (rev 8560) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-18 22:15:05 UTC (rev 8561) @@ -397,7 +397,7 @@ ## 2010-11-14 Fixed sheet # index (was offset by -1) in call to getusedrange() in case #3 of text sheet name arg -function [ rawarr, xls, status ] = xls2jpoi2oct (xls, wsh, cellrange=[], spsh_opts) +function [ rawarr, xls, rstatus ] = xls2jpoi2oct (xls, wsh, cellrange=[], spsh_opts) persistent ctype; if (isempty (ctype)) @@ -410,7 +410,7 @@ ctype(6) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_ERROR'); endif - status = 0; jerror = 0; + rstatus = 0; jerror = 0; wb = xls.workbook; # Check if requested worksheet exists in the file & if so, get pointer @@ -517,7 +517,7 @@ if (jerror > 0) warning (sprintf ("xls2oct: %d cached values instead of formula evaluations.\n", jerror)); endif - status = 1; + rstatus = 1; xls.limits = [lcol, rcol; firstrow, lastrow]; endfunction @@ -575,7 +575,7 @@ ## 2011-04-11 (Ron Goldman <ro...@oc...>) Fixed missing months var, wrong arg ## " order in strsplit, wrong isTime condition -function [ rawarr, xls, status ] = xls2jxla2oct (xls, wsh, cellrange=[], spsh_opts) +function [ rawarr, xls, rstatus ] = xls2jxla2oct (xls, wsh, cellrange=[], spsh_opts) persistent ctype; persistent months; if (isempty (ctype)) @@ -595,7 +595,7 @@ months = {'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'}; endif - status = 0; + rstatus = 0; wb = xls.workbook; # Check if requested worksheet exists in the file & if so, get pointer @@ -735,7 +735,7 @@ endfor endfor - status = 1; + rstatus = 1; xls.limits = [lcol, rcol; firstrow, lastrow]; endfunction @@ -772,7 +772,7 @@ ## Created: 2011-03-26 ## Updates: -function [ rawarr, xls, status ] = xls2oxs2oct (xls, wsh, cellrange=[], spsh_opts) +function [ rawarr, xls, rstatus ] = xls2oxs2oct (xls, wsh, cellrange=[], spsh_opts) persistent ctype; if (isempty (ctype)) @@ -786,7 +786,7 @@ ctype( 6) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_DOUBLE')); # 5 endif - status = 0; + rstatus = 0; wb = xls.workbook; # Check if requested worksheet exists in the file & if so, get pointer @@ -845,7 +845,7 @@ endfor endfor - status = 1; + rstatus = 1; xls.limits = [lcol, rcol; firstrow, lastrow]; endfunction @@ -887,7 +887,7 @@ # Check sheet pointer if (isnumeric (wsh)) - if (wsh < 1 || wsh > numel (sh_names)) + if (wsh < 1 || wsh > numel (sh_names)) error ("Sheet index %d out of range 1-%d", wsh, numel (sh_names)); endif else @@ -896,7 +896,7 @@ wsh = ii; endif unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheet'); - sh = sheets.getByName(sh_names(wsh)).getObject.queryInterface (unotmp); + sh = sheets.getByName(sh_names{wsh}).getObject.queryInterface (unotmp); unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XCellRangesQuery'); xRQ = sh.queryInterface (unotmp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-19 16:02:37
|
Revision: 8567 http://octave.svn.sourceforge.net/octave/?rev=8567&view=rev Author: prnienhuis Date: 2011-09-19 16:02:31 +0000 (Mon, 19 Sep 2011) Log Message: ----------- (UNO) try to decipher value type returned by formulas Modified Paths: -------------- trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/xls2oct.m Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-19 14:05:34 UTC (rev 8566) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2011-09-19 16:02:31 UTC (rev 8567) @@ -114,7 +114,7 @@ ## 2011-05-06 Experimental UNO support ## 2011-09-18 Set rstatus var here ## -## (Latest update of subfunctions below: 2011-09-18) +## (Latest update of subfunctions below: 2011-09-19) function [ rawarr, ods, rstatus ] = ods2oct (ods, wsh=1, datrange=[], spsh_opts=[]) @@ -789,6 +789,7 @@ ## 2011-09-18 Adapted sh_names type to LO 3.4.1 ## '' Remove default 2 last sheets (LibreOffice 3.4.+) ## '' Remove rstatus var (now set in caller) +## 2011-09-19 Try to decipher if formulas return numeric or string values function [rawarr, ods] = ods2uno2oct (ods, wsh, datrange, spsh_opts) @@ -868,8 +869,12 @@ 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'); 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 (~isnan (tmp)); rawarr{ii-trow+2, jj-lcol+2} = tmp; endif endif otherwise # Empty cell Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-19 14:05:34 UTC (rev 8566) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2011-09-19 16:02:31 UTC (rev 8567) @@ -119,7 +119,7 @@ ## 2011-05-18 Experimental UNO support added ## 2011-09-08 Minor code layout ## -## Latest subfunc update: 2011-09-18 +## Latest subfunc update: 2011-09-19 function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) @@ -873,6 +873,7 @@ ## Created: 2011-05-05 ## Updates: ## 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 function [rawarr, xls, rstatus] = xls2uno2oct (xls, wsh, datrange, spsh_opts) @@ -952,8 +953,12 @@ 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'); 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 (~isnan (tmp)); rawarr{ii-trow+2, jj-lcol+2} = tmp; endif endif otherwise # Empty cell This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-09-23 19:27:40
|
Revision: 8584 http://octave.svn.sourceforge.net/octave/?rev=8584&view=rev Author: prnienhuis Date: 2011-09-23 19:27:33 +0000 (Fri, 23 Sep 2011) Log Message: ----------- Stray debug statements removed Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-23 17:55:55 UTC (rev 8583) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-09-23 19:27:33 UTC (rev 8584) @@ -111,7 +111,7 @@ ## 2011-03-23 First try of odfdom 0.8.7 ## 2011-05-15 Experimental UNO support added ## -## Last update of subfunctions below: 2011-09-18 +## Last update of subfunctions below: 2011-09-23 function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange=[], spsh_opts=[]) @@ -1011,6 +1011,7 @@ ## 2011-summer <many many improvements> ## 2011-09-08 Stylistic changes ## 2011-09-18 Adapted sh_names type to LO 3.4.1 +## 2011-09-23 Removed stray debug statements function [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts) @@ -1108,7 +1109,7 @@ fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1), c_arr); typearr(fptr) = ctype(4); # FORMULA endif -keyboard + # Transfer data to sheet for ii=1:nrows for jj=1:ncols @@ -1135,7 +1136,6 @@ changed = 1; catch printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); - keyboard end_try_catch endfor endfor Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-23 17:55:55 UTC (rev 8583) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-09-23 19:27:33 UTC (rev 8584) @@ -107,7 +107,7 @@ ## 2011-05-18 Experimental UNO support ## 2011-09-08 Bug fix in range arg check; code cleanup -## Last script file update (incl. subfunctions): 2011-09-18 +## Last script file update (incl. subfunctions): 2011-09-23 function [ xls, rstatus ] = oct2xls (obj, xls, wsh=1, crange=[], spsh_opts=[]) @@ -899,6 +899,7 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-05-18 ## 2011-09-18 Adapted sh_names type to LO 3.4.1 +## 2011-09-23 Removed stray debug statements function [ xls, rstatus ] = oct2uno2xls (c_arr, xls, wsh, crange, spsh_opts) @@ -1020,11 +1021,10 @@ otherwise # Empty cell endswitch - changed = 1; + changed = 1; catch printf ("Error writing cell %s (typearr() = %d)\n", calccelladdress(trow+ii, lcol+jj), typearr(ii, jj)); - keyboard - end_try_catch + end_try_catch endfor endfor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2011-11-18 14:23:25
|
Revision: 9133 http://octave.svn.sourceforge.net/octave/?rev=9133&view=rev Author: prnienhuis Date: 2011-11-18 14:23:19 +0000 (Fri, 18 Nov 2011) Log Message: ----------- Fixed bug in checks for range input argument Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2011-11-18 10:32:52 UTC (rev 9132) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2011-11-18 14:23:19 UTC (rev 9133) @@ -141,7 +141,7 @@ # Check worksheet ptr if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif # Check range - if (~(isempty (crange) || ischar (crange))), error ("Character string (range) expected for arg # 4"); endif + if (~isempty (crange) && ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif # Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2011-11-18 10:32:52 UTC (rev 9132) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2011-11-18 14:23:19 UTC (rev 9133) @@ -139,7 +139,7 @@ # Check worksheet ptr if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif # Check range - if (isempty (crange) || ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif + if (~isempty (crange) && ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif # Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-01-26 19:55:22
|
Revision: 9569 http://octave.svn.sourceforge.net/octave/?rev=9569&view=rev Author: prnienhuis Date: 2012-01-26 19:55:15 +0000 (Thu, 26 Jan 2012) Log Message: ----------- Corrected "seealso" texinfo header text Modified Paths: -------------- trunk/octave-forge/main/io/inst/getusedrange.m trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/odsclose.m trunk/octave-forge/main/io/inst/odsfinfo.m trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/odsread.m trunk/octave-forge/main/io/inst/odswrite.m trunk/octave-forge/main/io/inst/parsecell.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsclose.m trunk/octave-forge/main/io/inst/xlsfinfo.m trunk/octave-forge/main/io/inst/xlsopen.m trunk/octave-forge/main/io/inst/xlsread.m trunk/octave-forge/main/io/inst/xlswrite.m Modified: trunk/octave-forge/main/io/inst/getusedrange.m =================================================================== --- trunk/octave-forge/main/io/inst/getusedrange.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/getusedrange.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -49,7 +49,7 @@ ## spreadsheet pointed to in struct xls3) ## @end example ## -## @seealso xlsopen, xlsclose, odsopen, odsclose, xlsfinfo, odsfinfo +## @seealso {xlsopen, xlsclose, odsopen, odsclose, xlsfinfo, odsfinfo} ## ## @end deftypefn @@ -66,6 +66,7 @@ ## 2011-05-06 Experimental support for Java/UNO bridge ## 2011-06-13 OpenXLS support added ## 2011-09-08 Style & layout updates +## 2012-01-26 Fixed "seealso" help string ## ## Last subfunc update: 2011-06-29 (OXS) Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011,2012 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -83,7 +83,7 @@ ## Put a character string into cell B15 in sheet Oldsheet3 ## @end example ## -## @seealso ods2oct, odsopen, odsclose, odsread, odswrite, odsfinfo +## @seealso {ods2oct, odsopen, odsclose, odsread, odswrite, odsfinfo} ## ## @end deftypefn @@ -111,6 +111,7 @@ ## 2011-03-23 First try of odfdom 0.8.7 ## 2011-05-15 Experimental UNO support added ## 2011-11-18 Fixed bug in test for range parameter being character string +## 2012-01-26 Fixed "seealso" help string ## ## Last update of subfunctions below: 2011-09-23 Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -82,7 +82,7 @@ ## [xlso, status] = xls2oct ('arr', xlsi, 'Third_sheet', 'AA31:AB278'); ## @end example ## -## @seealso xls2oct, xlsopen, xlsclose, xlsread, xlswrite, xlsfinfo +## @seealso {xls2oct, xlsopen, xlsclose, xlsread, xlswrite, xlsfinfo} ## ## @end deftypefn @@ -107,6 +107,7 @@ ## 2011-05-18 Experimental UNO support ## 2011-09-08 Bug fix in range arg check; code cleanup ## 2011-11-18 Fixed another bug in test for range parameter being character string +## 2012-01-26 Fixed "seealso" help string ## Last script file update (incl. subfunctions): 2011-09-23 @@ -215,7 +216,7 @@ ## xls = oct2com2xls (rand (10, 15), xls, 'Third_sheet', 'BF24'); ## @end example ## -## @seealso oct2xls, xls2oct, xlsopen, xlsclose, xlswrite, xlsread, xls2com2oct +## @seealso {oct2xls, xls2oct, xlsopen, xlsclose, xlswrite, xlsread, xls2com2oct} ## ## @end deftypefn @@ -241,6 +242,7 @@ ## " replaced by while loop ## " Added check for "live" ActiveX server ## 2010-11-12 Moved ptr struct check into main func +## 2012-01-26 Fixed "seealso" help string function [ xls, status ] = oct2com2xls (obj, xls, wsh, crange, spsh_opts) @@ -448,7 +450,7 @@ ## [xlso, status] = xls2jpoi2oct ('arr', xlsi, 'Third_sheet', 'AA31'); ## @end example ## -## @seealso oct2xls, xls2oct, xlsopen, xlsclose, xlsread, xlswrite +## @seealso {oct2xls, xls2oct, xlsopen, xlsclose, xlsread, xlswrite} ## ## @end deftypefn @@ -468,6 +470,7 @@ ## 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 function [ xls, rstatus ] = oct2jpoi2xls (obj, xls, wsh, crange, spsh_opts) @@ -610,7 +613,7 @@ ## [xlso, status] = oct2jxla2oct ('arr', xlsi, 'Third_sheet', 'AA31'); ## @end example ## -## @seealso oct2xls, xls2oct, xlsopen, xlsclose, xlsread, xlswrite, xls2jxla2oct +## @seealso {oct2xls, xls2oct, xlsopen, xlsclose, xlsread, xlswrite, xls2jxla2oct} ## ## @end deftypefn @@ -632,6 +635,7 @@ ## " internal variable 'changed' ## 2010-10-27 File change tracking again refined ## 2010-11-12 Moved ptr struct check into main func +## 2012-01-26 Fixed "seealso" help string function [ xls, rstatus ] = oct2jxla2xls (obj, xls, wsh, crange, spsh_opts) Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011,2012 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -91,7 +91,7 @@ ## [An, ods2, status] = ods2oct (ods2, 'Third_sheet'); ## @end example ## -## @seealso odsopen, odsclose, parsecell, odsread, odsfinfo, oct2ods, odswrite +## @seealso {odsopen, odsclose, parsecell, odsread, odsfinfo, oct2ods, odswrite} ## ## @end deftypefn @@ -113,6 +113,7 @@ ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to here ## 2011-05-06 Experimental UNO support ## 2011-09-18 Set rstatus var here +## 2012-01-26 Fixed "seealso" help string ## ## (Latest update of subfunctions below: 2011-09-19) Modified: trunk/octave-forge/main/io/inst/odsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/odsclose.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/odsclose.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -46,7 +46,7 @@ ## (Close spreadsheet file pointed to in pointer struct ods1; ods1 is reset) ## @end example ## -## @seealso odsopen, odsread, odswrite, ods2oct, oct2ods, odsfinfo, chk_spreadsheet_support +## @seealso {odsopen, odsread, odswrite, ods2oct, oct2ods, odsfinfo, chk_spreadsheet_support} ## ## @end deftypefn @@ -64,6 +64,7 @@ ## 2011-05-07 In case of UNO, soffice now properly closed using xDesk ## 2011-05-18 Saving newly created files using UNO supported now ## 2011-09-08 FIXME - closing OOo kills all other OOo invocations (known Java-UNO issue) +## 2012-01-26 Fixed "seealso" help string function [ ods ] = odsclose (ods, varargs) Modified: trunk/octave-forge/main/io/inst/odsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/odsfinfo.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/odsfinfo.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -55,7 +55,7 @@ ## list of sheet names) ## @end example ## -## @seealso odsread, odsopen, ods2oct, odsclose +## @seealso {odsread, odsopen, ods2oct, odsclose} ## ## @end deftypefn @@ -73,6 +73,7 @@ ## 2011-03-23 Adapted to odfdom 0.8.7 (changed getXPath method call) ## 2011-05-07 Experimental UNO support added ## 2011-09-03 Normal return in case of no ODS support (empty ods struct) +## 2012-01-26 Fixed "seealso" help string function [ filetype, sheetnames ] = odsfinfo (filename, reqintf=[]) Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/odsopen.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -59,7 +59,7 @@ ## the jOpenDocument interface is requested) ## @end example ## -## @seealso odsclose, odsread, ods2oct, odsfinfo, chk_spreadsheet_support +## @seealso {odsclose, odsread, ods2oct, odsfinfo, chk_spreadsheet_support} ## ## @end deftypefn @@ -89,6 +89,7 @@ ## " 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) +## 2012-01-26 Fixed "seealso" help string ## ## Latest change on subfunctions below: 2011-09-18 Modified: trunk/octave-forge/main/io/inst/odsread.m =================================================================== --- trunk/octave-forge/main/io/inst/odsread.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/odsread.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -101,7 +101,7 @@ ## cell array Ra and the ranges from where the actual data came in limits) ## @end example ## -## @seealso odsopen, ods2oct, oct2ods, odsclose, odswrite, odsfinfo, parsecell +## @seealso {odsopen, ods2oct, oct2ods, odsclose, odswrite, odsfinfo, parsecell} ## ## @end deftypefn @@ -115,6 +115,7 @@ ## 2010-11-13 Added some input validity checks ## 2011-09-08 Catch empty ods structs after failed odsopen attempts ## 2011-09-18 Return empty output arg in case of empty rawarr +## 2012-01-26 Fixed "seealso" help string function [ numarr, txtarr, rawarr, lim ] = odsread (filename, wsh=1, datrange=[], reqintf=[]) Modified: trunk/octave-forge/main/io/inst/odswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/odswrite.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/odswrite.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011,2012 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -76,7 +76,7 @@ ## True (= numerical 1) in status if al went well) ## @end example ## -## @seealso odsread, oct2ods, ods2oct, odsopen, odsclose, odsfinfo +## @seealso {odsread, oct2ods, ods2oct, odsopen, odsclose, odsfinfo} ## ## @end deftypefn @@ -89,6 +89,7 @@ ## 2010-11-13 Added note about required file extension in help text ## 2010-11-13 Added some input arg checks ## 2011-09-08 Minor filename error text adaptation +## 2012-01-26 Fixed "seealso" help string function [ rstatus ] = odswrite (filename, data, wsh=1, range=[], reqintf=[]) Modified: trunk/octave-forge/main/io/inst/parsecell.m =================================================================== --- trunk/octave-forge/main/io/inst/parsecell.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/parsecell.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -49,7 +49,7 @@ ## text data into array Tn.) ## @end example ## -## @seealso xlsread, odsread, xls2oct, ods2oct +## @seealso {xlsread, odsread, xls2oct, ods2oct} ## ## @end deftypefn @@ -62,6 +62,7 @@ ## 2011-05-17 Fixed subscript indexing bug in cropping section when rawarr is ## " numeric scalar ## 2011-09-08 Copyright string updated +## 2012-01-26 Fixed "seealso" help string function [ numarr, txtarr, lim ] = parsecell (rawarr, arg2=[]) Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011,12 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 @@ -97,7 +97,7 @@ ## [An, xls2, status] = xls2oct (xls2, 'Third_sheet'); ## @end example ## -## @seealso oct2xls, xlsopen, xlsclose, parsecell, xlsread, xlsfinfo, xlswrite +## @seealso {ct2xls, xlsopen, xlsclose, parsecell, xlsread, xlsfinfo, xlswrite } ## ## @end deftypefn @@ -118,8 +118,9 @@ ## 2011-03-29 Test for proper input xls struct extended ## 2011-05-18 Experimental UNO support added ## 2011-09-08 Minor code layout +## 2012-01-26 Fixed "seealso" help string ## -## Latest subfunc update: 2011-09-19 +## Latest subfunc update: 2012-01-26 function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) @@ -202,7 +203,7 @@ #==================================================================================== -## Copyright (C) 2009,2010 P.R. Nienhuis, <pr.nienhuis at hccnet.nl> +## Copyright (C) 2009,2010,2011,2012 P.R. Nienhuis, <pr.nienhuis at hccnet.nl> ## ## based on mat2xls by Michael Goffioul (2007) <mic...@sw...> ## @@ -235,7 +236,7 @@ ## Arr = xls2com2oct (xls, 'Second_sheet'); ## @end example ## -## @seealso xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite +## @seealso {xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite} ## ## @end deftypefn @@ -250,6 +251,7 @@ ## 2010-10-24 Added check for "live" ActiveX server ## 2010-11-12 Moved ptr struct check into main func ## 2010-11-13 Catch empty sheets when no range was specified +## 2012-01-26 Fixed "seealso" help string function [rawarr, xls, rstatus ] = xls2com2oct (xls, wsh, crange) @@ -346,7 +348,7 @@ #================================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -379,7 +381,7 @@ ## B = xls2jpoi2oct (xls, 'Second_sheet', 'B3'); ## @end example ## -## @seealso xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite, oct2jpoi2xls +## @seealso {xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite, oct2jpoi2xls} ## ## @end deftypefn @@ -395,7 +397,8 @@ ## 2010-11-12 Moved ptr struct check into main func ## 2010-11-13 Catch empty sheets when no range was specified ## 2010-11-14 Fixed sheet # index (was offset by -1) in call to getusedrange() in case -#3 of text sheet name arg +## of text sheet name arg +## 2012-01-26 Fixed "seealso" help string function [ rawarr, xls, rstatus ] = xls2jpoi2oct (xls, wsh, cellrange=[], spsh_opts) @@ -524,7 +527,7 @@ #================================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -557,7 +560,7 @@ ## B = xls2jxla2oct (xls, 'Second_sheet'); ## @end example ## -## @seealso xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite, oct2jxla2xls +## @seealso {xls2oct, oct2xls, xlsopen, xlsclose, xlsread, xlswrite, oct2jxla2xls} ## ## @end deftypefn @@ -574,6 +577,7 @@ ## 2010-11-13 Catch empty sheets when no range was specified ## 2011-04-11 (Ron Goldman <ro...@oc...>) Fixed missing months var, wrong arg ## " order in strsplit, wrong isTime condition +## 2012-01-26 Fixed "seealso" help string function [ rawarr, xls, rstatus ] = xls2jxla2oct (xls, wsh, cellrange=[], spsh_opts) Modified: trunk/octave-forge/main/io/inst/xlsclose.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsclose.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/xlsclose.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -53,7 +53,7 @@ ## (Close spreadsheet file pointed to in pointer struct xls1; xls1 is reset) ## @end example ## -## @seealso xlsopen, xlsread, xlswrite, xls2oct, oct2xls, xlsfinfo +## @seealso {xlsopen, xlsread, xlswrite, xls2oct, oct2xls, xlsfinfo} ## ## @end deftypefn @@ -71,6 +71,7 @@ ## 2011-03-26 Added OpenXLS support ## 2011-05-18 Added experimental UNO support, incl. saving newly created files ## 2011-09-08 Bug fix in check for filename input arg +## 2012-01-26 Fixed "seealso" help string function [ xls ] = xlsclose (xls, varargs) Modified: trunk/octave-forge/main/io/inst/xlsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsfinfo.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/xlsfinfo.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <pr.nienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011,2012 Philip Nienhuis <pr.nienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -64,7 +64,7 @@ ## list of sheet names and -types) ## @end example ## -## @seealso oct2xls, xlsread, xls2oct, xlswrite +## @seealso {oct2xls, xlsread, xls2oct, xlswrite} ## ## @end deftypefn @@ -83,6 +83,7 @@ ## 2011-03-26 Added OpenXLS support ## 2011-05-18 Experimental UNO support ## 2011-09-08 Some code simplifications +## 2012-01-26 Fixed "seealso" help string function [ filetype, sh_names, fformat ] = xlsfinfo (filename, reqintf=[]) Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -69,7 +69,7 @@ ## and the Apache POI interface are requested) ## @end example ## -## @seealso xlsclose, xlsread, xlswrite, xls2oct, oct2xls, xlsfinfo +## @seealso {xlsclose, xlsread, xlswrite, xls2oct, oct2xls, xlsfinfo} ## ## @end deftypefn @@ -105,6 +105,7 @@ ## 2011-09-08 Minor code cleanup ## ## 2011-09-18 Latest subfunction update +## 2012-01-26 Fixed "seealso" help string function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) @@ -392,7 +393,7 @@ endfunction -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 Modified: trunk/octave-forge/main/io/inst/xlsread.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsread.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/xlsread.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 by Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,2010,2011,2012 by Philip Nienhuis <prnienhuis at users.sf.net> ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License @@ -127,7 +127,7 @@ ## or COM interface (i.e, exclude POI interface). ## @end example ## -## @seealso xlswrite, xlsopen, xls2oct, xlsclose, xlsfinfo, oct2xls +## @seealso {xlswrite, xlsopen, xls2oct, xlsclose, xlsfinfo, oct2xls} ## ## @end deftypefn @@ -147,6 +147,7 @@ ## 2011-04-11 Return upon empty xls struct from xlsopen() ## 2011-04-17 Suppress xlsopen messages (";" was missing) ## 2011-09-08 Minor code cleanup; included UNO & OXS support in test +## 2012-01-26 Fixed "seealso" help string function [ numarr, txtarr, rawarr, lims ] = xlsread (fn, wsh, datrange, reqintf=[]) Modified: trunk/octave-forge/main/io/inst/xlswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/xlswrite.m 2012-01-25 18:34:47 UTC (rev 9568) +++ trunk/octave-forge/main/io/inst/xlswrite.m 2012-01-26 19:55:15 UTC (rev 9569) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -83,7 +83,7 @@ ## True (= numerical 1) in status if al went well) ## @end example ## -## @seealso xlsread, oct2xls, xls2oct, xlsopen, xlsclose, xlsfinfo +## @seealso {xlsread, oct2xls, xls2oct, xlsopen, xlsclose, xlsfinfo} ## ## @end deftypefn @@ -97,6 +97,7 @@ ## avoid unneeded error message clutter ## 2010-10-27 Changed range -> crange to unhide other range functions ## 2011-09-08 Minor code syntax updates +## 2012-01-26 Fixed "seealso" help string function [ rstatus ] = xlswrite (filename, arr, arg3, arg4, arg5) @@ -154,14 +155,14 @@ endif 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; + xls_ok = 0; + xls = xlsopen (filename, 1, reqintf); + xls_ok = 1; - [xls, rstatus] = oct2xls (arr(1:nr, 1:nc), xls, wsh, topleft); + [xls, rstatus] = oct2xls (arr(1:nr, 1:nc), xls, wsh, topleft); unwind_protect_cleanup - if (xls_ok), xls = xlsclose (xls); endif + if (xls_ok), xls = xlsclose (xls); endif end_unwind_protect This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-02-25 15:59:57
|
Revision: 9679 http://octave.svn.sourceforge.net/octave/?rev=9679&view=rev Author: prnienhuis Date: 2012-02-25 15:59:51 +0000 (Sat, 25 Feb 2012) Log Message: ----------- Updated help texts Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsfinfo.m trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/odswrite.m trunk/octave-forge/main/io/inst/xls2oct.m trunk/octave-forge/main/io/inst/xlsfinfo.m trunk/octave-forge/main/io/inst/xlsopen.m trunk/octave-forge/main/io/inst/xlsread.m trunk/octave-forge/main/io/inst/xlswrite.m Modified: trunk/octave-forge/main/io/inst/odsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/odsfinfo.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/odsfinfo.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -38,7 +38,7 @@ ## spreadsheet has to be parsed to get the sheet names, let alone exploring ## used data ranges. ## -## By specifying a value of 'jod' or 'otk' for @var{reqintf} the automatic +## By specifying a value of 'jod', 'otk' or 'uno' for @var{reqintf} the automatic ## selection of the java interface is bypassed and the specified interface ## will be used (if at all present). ## Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/odsopen.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -26,7 +26,7 @@ ## To make this function work at all, you need the Java package >= 1.2.5 plus ## ODFtoolkit (version 0.7.5 or 0.8.6) & xercesImpl, and/or jOpenDocument, and/or ## OpenOffice.org (or clones) installed on your computer + proper javaclasspath -## set. These interfaces are referred to as OTK, JOD, adn UNO resp., and are +## set. These interfaces are referred to as OTK, JOD, and UNO resp., and are ## preferred in that order by default (depending on their presence). ## For (currently experimental) UNO support, Octave-Java package 1.2.8 + latest ## fixes is imperative; furthermore the relevant classes had best be added to Modified: trunk/octave-forge/main/io/inst/odswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/odswrite.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/odswrite.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -57,7 +57,8 @@ ## ## The optional last argument @var{reqintf} can be used to override ## the automatic selection by odswrite of one interface out of the -## supported ones: Java/ODFtooolkit ('OTK'), or Java/jOpenDocument ('JOD'). +## supported ones: Java/ODFtooolkit ('OTK'), Java/jOpenDocument ('JOD'), +## or Java/OpenOffice.org ('UNO'). ## ## odswrite is a mere wrapper for various scripts which find out what ## ODS interface to use (ODF toolkit or jOpenDocument) plus code to mimic Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -72,7 +72,7 @@ ## Be aware that Excel trims @var{rawarr} from empty outer rows & columns, ## so any returned cell array may turn out to be smaller than requested ## in @var{range}. -## When using COM or POI interface, formulas in cells are evaluated; if +## When using COM, POI, or UNO interface, formulas in cells are evaluated; if ## that fails cached values are retrieved. These may be outdated ## depending on Excel's "Automatic calculation" settings when the ## spreadsheet was saved. Modified: trunk/octave-forge/main/io/inst/xlsfinfo.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsfinfo.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/xlsfinfo.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -35,10 +35,10 @@ ## string) unless @var{filename} is a readable Excel 97-2003 .xls file or ## an Excel 2007 .xlsx / .xlsb file in which case @var{fformat} is set to ## "xlWorkbookNormal". Excel 95 .xls files can only be read through the JXL -## (JExcelAPI) java-based interface. +## (JExcelAPI) or UNO (OpenOffice.org) Java-based interfaces. ## ## If no return arguments are specified the sheet names are echoed to the -## terminal screen; in case of java interfaces for each sheet the actual +## terminal screen; in case of Java interfaces for each sheet the actual ## occupied data range is echoed as well. The occupied cell range will have ## to be determined behind the scenes first; this can take some time for the ## Java-based interfaces. @@ -48,8 +48,9 @@ ## cell ranges in each worksheet using a java-based interface (the COM / ActiveX ## interface can't supply this information). ## -## For use on OOXML spreadsheets one needs full POI support (see xlsopen) and -## 'poi' needs to be specified for @var{reqintf}. For Excel 95 file use 'jxl'. +## For use on OOXML spreadsheets one needs full POI and/or UNO support (see +## xlsopen) and 'poi' or 'uno' needs to be specified for @var{reqintf}. For +## Excel 95 file use 'jxl' or 'uno'. ## ## Examples: ## Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -34,6 +34,7 @@ ## following jars in your javaclasspath: poi-ooxml-schemas-3.5.jar, ## xbean.jar and dom4j-1.6.1.jar (or later versions). Later OpenOffice.org ## versions (UNO) have support for OOXML as well. +## Excel'95 spreadsheets can only be read by JExcelAPI and OpenOffice.org. ## ## @var{filename} should be a valid .xls or xlsx Excel file name (including ## extension). But if you use the COM interface you can specify any extension Modified: trunk/octave-forge/main/io/inst/xlsread.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsread.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/xlsread.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -74,9 +74,9 @@ ## the automatic selection by xlsread of one interface out of the ## supported ones: COM/Excel, Java/Apache POI, or Java/JExcelAPI ## (in that built-in order of preference). -## For reading from OOXML files a value of 'poi' must be specified +## For reading from OOXML files a value of 'poi' or 'uno' must be specified ## for @var{reqintf} (see help for xlsopen); for Excel'95 files use -## 'com', or if Excel is not installed use 'jxl' or 'basic' (POI +## 'com', or if Excel is not installed use 'jxl', 'basic', or 'uno' (POI ## can't read Excel 95 but will try to fall back to JXL). ## As @var{reqintf} can also be a cell array of strings, one can ## select or exclude one or more interfaces. Modified: trunk/octave-forge/main/io/inst/xlswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/xlswrite.m 2012-02-24 20:52:30 UTC (rev 9678) +++ trunk/octave-forge/main/io/inst/xlswrite.m 2012-02-25 15:59:51 UTC (rev 9679) @@ -62,9 +62,12 @@ ## ## The optional last argument @var{reqintf} can be used to override ## the automatic selection by xlswrite of one interface out of the -## supported ones: COM/Excel, Java/Apache POI, or Java/JExcelAPI. -## For writing to OOXML files (.xlsx) a value of 'poi' (case-insensitive) -## must be specified for @var{reqintf}. +## supported ones: 'com' (ActiveX/Excel), 'poi' (Java/Apache POI), 'jxl' +## (Java/JExcelAPI), or 'uno' (Java/OpenOffice.org). 'oxs' (Java/OpenXLS) +## is implemented but disabled for writing. For writing to OOXML files +## (.xlsx) a value of 'poi' or 'uno' must be specified for @var{reqintf}. +## The value of @var{reqintf} is case-insensitive. Multiple interfaces +## can be selected if entered as a cell array of strings. ## ## xlswrite is a mere wrapper for various scripts which find out what ## Excel interface to use (COM, Java/POI) plus code to mimic the other This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-02-26 23:39:21
|
Revision: 9703 http://octave.svn.sourceforge.net/octave/?rev=9703&view=rev Author: prnienhuis Date: 2012-02-26 23:39:15 +0000 (Sun, 26 Feb 2012) Log Message: ----------- Bug fix when adding new sheet using UNO intf + texinfo header updates Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2012-02-26 23:38:23 UTC (rev 9702) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2012-02-26 23:39:15 UTC (rev 9703) @@ -102,7 +102,7 @@ ## 2010-08-15 Texinfo header edits ## 2010-08-16 Added check on presence of output argument ## 2010-08-23 Added check on validity of ods file ptr -## " Experimental support for odfdom 0.8.6 (in separate subfunc, to be integrated later) +## '' Experimental support for odfdom 0.8.6 (in separate subfunc, to be integrated later) ## 2010-08-25 Improved help text (java memory, ranges) ## 2010-10-27 Improved file change tracking tru ods.changed ## 2010-11-12 Better input argument checks @@ -114,7 +114,7 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral ## -## Last update of subfunctions below: 2012-02-25 +## Last update of subfunctions below: 2012-02-26 function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange='', spsh_opts=[]) @@ -1019,6 +1019,7 @@ ## 2011-09-18 Adapted sh_names type to LO 3.4.1 ## 2011-09-23 Removed stray debug statements ## 2012-02-25 Work around LO3.5rc1 Java Runtime Exception bug L.1043+ +## 2012-02-26 Bug fix when adding sheets near L.1101 (wrong if-else-end construct). function [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts) @@ -1096,11 +1097,10 @@ # 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); - else - # 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 + # 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 Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2012-02-26 23:38:23 UTC (rev 9702) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2012-02-26 23:39:15 UTC (rev 9703) @@ -1,4 +1,4 @@ -## Copyright (C) 2009,2010,2011 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -103,14 +103,14 @@ ## 2010-11-13 Added check for 2-D input array ## 2010-12-01 Better check on file pointer struct (ischar (xls.xtype)) ## 2011-03-29 OpenXLS support added. Works but saving to file (xlsclose) doesn't work yet -## " Bug fixes (stray variable c_arr, and wrong test for valid xls struct) +## '' Bug fixes (stray variable c_arr, and wrong test for valid xls struct) ## 2011-05-18 Experimental UNO support ## 2011-09-08 Bug fix in range arg check; code cleanup ## 2011-11-18 Fixed another bug in test for range parameter being character string ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral -## Last script file update (incl. subfunctions): 2012-02-25 +## Last script file update (incl. subfunctions): 2012-02-26 function [ xls, rstatus ] = oct2xls (obj, xls, wsh=1, crange='', spsh_opts=[]) @@ -913,6 +913,7 @@ ## 2011-09-23 Removed stray debug statements ## 2012-02-25 Fixed wrong var name in L.933 ## 2012-02-25 Catch stray Java RuntimeException when deleting sheets +## 2012-02-26 Bug fix when adding sheets near L.994 (wrong if-else-end construct). function [ xls, rstatus ] = oct2uno2xls (c_arr, xls, wsh, crange, spsh_opts) @@ -983,18 +984,17 @@ # wsh is a sheet name. See if it exists already if (isempty (strmatch (wsh, sh_names))) # Not found. New sheet to be added - newsh = 1; + newsh = 1; endif endif if (newsh) # 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); - else - # 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 + # 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-02-26 23:43:37
|
Revision: 9706 http://octave.svn.sourceforge.net/octave/?rev=9706&view=rev Author: prnienhuis Date: 2012-02-26 23:43:31 +0000 (Sun, 26 Feb 2012) Log Message: ----------- Texinfo header updates Modified Paths: -------------- trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/xls2oct.m Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2012-02-26 23:41:51 UTC (rev 9705) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2012-02-26 23:43:31 UTC (rev 9706) @@ -21,10 +21,13 @@ ## @deftypefnx {Function File} [ @var{rawarr}, @var{ods}, @var{rstatus} ] = ods2oct (@var{ods}, @var{wsh}, @var{range}, @var{options}) ## ## Read data contained within range @var{range} from worksheet @var{wsh} -## in an OpenOffice.org spreadsheet file pointed to in struct @var{ods}. +## in an OpenOffice_org Calc spreadsheet file pointed to in struct @var{ods}. ## +## @var{ods} is supposed to have been created earlier by odsopen in the +## same octave session. +## ## @var{wsh} is either numerical or text, in the latter case it is -## case-sensitive and it may be max. 31 characters long. +## case-sensitive. ## Note that in case of a numerical @var{wsh} this number refers to the ## position in the worksheet stack, counted from the left in a Calc ## window. The default is numerical 1, i.e. the leftmost worksheet @@ -36,30 +39,40 @@ ## determined behind the scenes first; this can take some time. ## ## Optional argument @var{options}, a structure, can be used to -## specify various read modes. Currently the only option field is -## "formulas_as_text"; if set to TRUE or 1, spreadsheet formulas -## (if at all present) are read as formula strings rather than the -## evaluated formula result values. This only works for the OTK (Open -## Document Toolkit) interface. +## specify various read modes by setting option fields in the struct +## to true (1) or false (0). Currently recognized option fields are: ## -## If only the first argument is specified, ods2oct will try to read -## all contents from the first = leftmost (or the only) worksheet (as -## if a range of @'' (empty string) was specified). +## @table @asis +## @item "formulas_as_text" +## If set to TRUE or 1, spreadsheet formulas (if at all present) +## are read as formula strings rather than the evaluated formula +## result values. This only works for the OTK and UNO interfaces. +## The default value is 0 (FALSE). +## +## @item 'strip_array' +## Set the value of this field set to TRUE or 1 to strip the returned +## output array @var{rawarr} from empty outer columns and rows. The +## spreadsheet cell rectangle limits from where the data actually +## came will be updated. The default value is FALSE or 0 (no cropping). +## @end table +## +## If only the first argument @var{ods} is specified, ods2oct will +## try to read all contents from the first = leftmost (or the only) +## worksheet (as if a range of @'' (empty string) was specified). ## ## If only two arguments are specified, ods2oct assumes the second ## argument to be @var{wsh}. In that case ods2oct will try to read ## all data contained in that worksheet. ## ## Return argument @var{rawarr} contains the raw spreadsheet cell data. +## Use parsecell() to separate numeric and text values from @var{rawarr}. +## ## Optional return argument @var{ods} contains the pointer struct. Field ## @var{ods}.limits contains the outermost column and row numbers of the ## actually read cell range. -## @var{rstatus} will be set to 1 if the requested data have been read -## successfully, 0 otherwise. -## Use parsecell() to separate numeric and text values from @var{rawarr}. ## -## @var{ods} is supposed to have been created earlier by odsopen in the -## same octave session. It is only referred to, not changed. +## Optional return argument @var{rstatus} will be set to 1 if the +## requested data have been read successfully, 0 otherwise. ## ## Erroneous data and empty cells turn up empty in @var{rawarr}. ## Date/time values in OpenOffice.org are returned as numerical values @@ -67,17 +80,10 @@ ## rewritten by OpenOffice.org into .ods format may have numerical date ## cells with base 01-01-1900 (same as MS-Excel). ## -## Be aware that ods2oct trims @var{rawarr} from empty outer rows & columns, -## so any returned cell array may turn out to be smaller than requested -## in @var{range}. -## ## When reading from merged cells, all array elements NOT corresponding ## to the leftmost or upper OpenOffice.org cell will be treated as if the ## "corresponding" cells are empty. ## -## ods2oct is a mere wrapper for interface-dependent scripts (e.g., -## ods2jotk2oct and ods2jod2oct) that do the actual reading. -## ## Examples: ## ## @example @@ -109,12 +115,13 @@ ## 2010-08-12 Added explicit support for jOpenDocument v 1.2b3+ ## 2010-08-25 Improved helptext (moved some text around) ## 2010-08-27 Added ods3jotk2oct - internal function for odfdom-0.8.6.jar -## " Extended check on spsh_opts (must be a struct) +## '' Extended check on spsh_opts (must be a struct) ## 2010-10-27 Moved cropping rawarr from empty outer rows & columns to here ## 2011-05-06 Experimental UNO support ## 2011-09-18 Set rstatus var here ## 2012-01-26 Fixed "seealso" help string ## 2012-02-25 Added 0.8.7 to supported odfdom versions in L.155 +## 2012-02-26 Updated texinfo header help text ## ## (Latest update of subfunctions below: 2012-02-25) Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2012-02-26 23:41:51 UTC (rev 9705) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2012-02-26 23:43:31 UTC (rev 9706) @@ -23,6 +23,9 @@ ## Read data contained within range @var{range} from worksheet @var{wsh} ## in an Excel spreadsheet file pointed to in struct @var{xls}. ## +## @var{xls} is supposed to have been created earlier by xlsopen in the +## same octave session. +## ## @var{wsh} is either numerical or text, in the latter case it is ## case-sensitive and it may be max. 31 characters long. ## Note that in case of a numerical @var{wsh} this number refers to the @@ -39,31 +42,41 @@ ## reliable in this respect albeit much slower. ## ## Optional argument @var{options}, a structure, can be used to -## specify various read modes. Currently the only option field is -## "formulas_as_text"; if set to TRUE or 1, spreadsheet formulas -## (if at all present) are read as formula strings rather than the -## evaluated formula result values. This only works for the Java -## based interfaces (POI and JXL). +## specify various read modes by setting option fields in the struct +## to true (1) or false (0). Currently recognized option fields are: ## -## If only the first argument is specified, xls2oct will try to read -## all contents from the first = leftmost (or the only) worksheet (as -## if a range of @'' (empty string) was specified). +## @table @asis +## @item "formulas_as_text" +## If set to TRUE or 1, spreadsheet formulas (if at all present) +## are read as formula strings rather than the evaluated formula +## result values. This only works for the Java based interfaces +## POI, JXL and UNO. The default value is 0 (FALSE). +## +## @item 'strip_array' +## Set the value of this field set to TRUE or 1 to strip the returned +## output array @var{rawarr} from empty outer columns and rows. The +## spreadsheet cell rectangle limits from where the data actually +## came will be updated. The default value is FALSE or 0 (no cropping). +## When using the COM interface, the output array is always cropped. +## @end table +## +## If only the first argument @var{xls} is specified, xls2oct will try +## to read all contents from the first = leftmost (or the only) +## worksheet (as if a range of @'' (empty string) was specified). ## ## If only two arguments are specified, xls2oct assumes the second ## argument to be @var{wsh}. In that case xls2oct will try to read ## all data contained in that worksheet. ## ## Return argument @var{rawarr} contains the raw spreadsheet cell data. -## Optional return argument @var{xls} contains the pointer struct, -## @var{rstatus} will be set to 1 if the requested data have been read -## successfully, 0 otherwise. ## Use parsecell() to separate numeric and text values from @var{rawarr}. ## -## @var{xls} is supposed to have been created earlier by xlsopen in the -## same octave session. It is only referred to, not changed. +## Optional return argument @var{xls} contains the pointer struct, +## If any data have been read, field @var{xls}.limits contains the +## outermost column and row numbers of the actually returned cell range. ## -## If one of the Java interfaces is used, field @var{xls}.limits contains -## the outermost column and row numbers of the actually read cell range. +## Optional return argument @var{rstatus} will be set to 1 if the +## requested data have been read successfully, 0 otherwise. ## ## Erroneous data and empty cells turn up empty in @var{rawarr}. ## Date/time values in Excel are returned as numerical values. @@ -71,11 +84,10 @@ ## 1/1/0000, resp.) ## Be aware that Excel trims @var{rawarr} from empty outer rows & columns, ## so any returned cell array may turn out to be smaller than requested -## in @var{range}. +## in @var{range}, independent of field 'formulas_as_text' in @var{options}. ## When using COM, POI, or UNO interface, formulas in cells are evaluated; if -## that fails cached values are retrieved. These may be outdated -## depending on Excel's "Automatic calculation" settings when the -## spreadsheet was saved. +## that fails cached values are retrieved. These may be outdated depending +## on Excel's "Automatic calculation" settings when the spreadsheet was saved. ## ## When reading from merged cells, all array elements NOT corresponding ## to the leftmost or upper Excel cell will be treated as if the @@ -120,6 +132,7 @@ ## 2011-09-08 Minor code layout ## 2012-01-26 Fixed "seealso" help string ## 2012-02-25 Fixed missing quotes in struct check L.149-153 +## 2012-02-26 Updated texinfo header help text ## ## Latest subfunc update: 2012-02-25 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-02-26 23:49:29
|
Revision: 9707 http://octave.svn.sourceforge.net/octave/?rev=9707&view=rev Author: prnienhuis Date: 2012-02-26 23:49:23 +0000 (Sun, 26 Feb 2012) Log Message: ----------- Test scripts to check proper operation of spreadsheet I/O functions Added Paths: ----------- trunk/octave-forge/main/io/inst/io_ods_testscript.m trunk/octave-forge/main/io/inst/io_xls_testscript.m Added: trunk/octave-forge/main/io/inst/io_ods_testscript.m =================================================================== --- trunk/octave-forge/main/io/inst/io_ods_testscript.m (rev 0) +++ trunk/octave-forge/main/io/inst/io_ods_testscript.m 2012-02-26 23:49:23 UTC (rev 9707) @@ -0,0 +1,122 @@ +## Copyright (C) 2012 Philip Nienhuis <pr.nienhuis at users.sf.net> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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/>. + +## Check proper operation of ODS spreadsheet scripts +## Before running, a character variable 'intf' should be initialized with +## a value of 'otk', 'jod', or 'uno'. + +## Author: Philip Nienhuis +## Created: 2012-02-25 +## Updates: + + +printf ("\nTesting .ods interface %s ...\n", intf); + +## 1. Initialize test arrays +printf ("\n 1. Initialize arrays.\n"); +arr1 = [ 1 2; 3 4.5]; +arr2 = {'r1c1', '=c2+d2'; '', 'r2c2'; true, -83.4}; +opts = struct ("formulas_as_text", 0); + +## 2. Insert empty sheet +printf ("\n 2. Insert first empty sheet.\n"); +odswrite ('io-test.ods', {''}, 'EmptySheet', 'b4', intf); + +## 3. Add data to test sheet +printf ("\n 3. Add data to test sheet.\n"); +odswrite ('io-test.ods', arr1, 'Testsheet', 'c2:d3', intf); +odswrite ('io-test.ods', arr2, 'Testsheet', 'd4:z20', intf); + +## 4. Insert another sheet +printf ("\n 4. Add another sheet with just one number in A1.\n"); +odswrite ('io-test.ods', [1], 'JustOne', 'A1', intf); + +## 5. Get sheet info & find sheet with data and data range +printf ("\n 5. Explore sheet info.\n"); +[~, shts] = odsfinfo ('io-test.ods', intf); +shnr = strmatch ('Testsheet', shts(:, 1)); # Note case! +crange = shts{shnr, 2}; + +## 6. Read data back +printf ("\n 6. Read data back.\n"); +[num, txt, raw, lims] = odsread ('io-test.ods', shnr, crange, intf); + +## 7. Here come the tests, part 1 +printf ("\n 7. Tests part 1 (basic I/O):\n"); +try + printf (" ...Numeric array... "); + assert (num(1:2, 1:3), [1, 2, NaN; 3, 4.5, NaN], 1e-10); + assert (num(4:5, 1:3), [NaN, NaN, NaN; NaN, 1, -83.4], 1e-10); + assert (num(3, 1:2), [NaN, NaN], 1e-10); + # Just check if it's numeric, the value depends too much on cached results + assert (isnumeric (num(3,3)), true); + printf ("matches.\n"); +catch + printf ("Hmmm.... error, see 'num'\n"); + keyboard +end_try_catch +try + printf (" ...Cellstr array... "); + assert (txt{1, 1}, 'r1c1'); + assert (txt{2, 2}, 'r2c2'); + printf ("matches.\n"); +catch + printf ("Hmmm.... error, see 'txt'\n"); + keyboard +end_try_catch +try + printf (" ...Boolean... "); + assert (islogical (raw{5, 2}), true); # Fails on JOD + printf ("recovered.\n"); +catch + if (isnumeric (raw{5, 2})) + printf ("recovered as numeric '1' rather than logical TRUE\n"); + else + printf ("Hmmm.... error, see 'raw'\n"); + keyboard + endif +end_try_catch + +## Check if formulas_as_text works: +printf ("\n 8. Repeat reading, now return formulas as text\n"); +opts.formulas_as_text = 1; +ods = odsopen ('io-test.ods', 0, intf); +raw = ods2oct (ods, shnr, crange, opts); +ods = odsclose (ods); +clear ods; + +## 9. Here come the tests, part 2. Fails on COM +printf ("\n 9. Tests part 2 (read back formula):\n"); + +try + # Just check if it contains any string + assert ( (ischar (raw{3, 3}) && ~isempty (raw(3, 3))), true); + printf (" ...OK, formula recovered ('%s').\n", raw{3, 3}); +catch + printf ("Hmmm.... error, see 'raw(3, 3)'"); + if (isnumeric (raw{3, 3})) + printf (" (equals %f, should be a string like '=c2+d2')\n", raw{3, 3}); + else + printf ("\n"); + keyboard + endif +end_try_catch + +## 10. Clean up +printf ("\n10. Cleaning up....."); +delete 'io-test.ods'; +clear arr1 arr2 ods num txt raw lims opts shnr shts crange; +printf (" OK\n"); Added: trunk/octave-forge/main/io/inst/io_xls_testscript.m =================================================================== --- trunk/octave-forge/main/io/inst/io_xls_testscript.m (rev 0) +++ trunk/octave-forge/main/io/inst/io_xls_testscript.m 2012-02-26 23:49:23 UTC (rev 9707) @@ -0,0 +1,124 @@ +## Copyright (C) 2012 Philip Nienhuis <pr.nienhuis at users.sf.net> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## 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/>. + +## Check proper operation of XLS spreadsheet scripts. +## Before running, a character variable 'intf' should be initialized with +## a value of 'com', 'poi', 'jxl', 'oxs', or 'uno'. + +## Author: Philip Nienhuis +## Created: 2012-02-25 +## Updates: + + +printf ("\nTesting .xls interface %s ...\n", intf); + +if (strcmp (lower (intf), 'oxs')); + printf ("OXS interface has no write support enabled - writing is done with POI.\n"); + intf2 = 'com'; +else; + intf2 = intf; +endif + +## 1. Initialize test arrays +printf ("\n 1. Initialize arrays.\n"); +arr1 = [ 1 2; 3 4.5]; +arr2 = {'r1c1', '=c2+d2'; '', 'r2c2'; true, -83.4}; +opts = struct ("formulas_as_text", 0); + +## 2. Insert empty sheet +printf ("\n 2. Insert first empty sheet.\n"); +xlswrite ('io-test.xls', {''}, 'EmptySheet', 'b4', intf2); + +## 3. Add data to test sheet +printf ("\n 3. Add data to test sheet.\n"); +xlswrite ('io-test.xls', arr1, 'Testsheet', 'c2:d3', intf2); +xlswrite ('io-test.xls', arr2, 'Testsheet', 'd4:z20', intf2); + +## 4. Insert another sheet +printf ("\n 4. Add another sheet with just one number in A1.\n"); +xlswrite ('io-test.xls', [1], 'JustOne', 'A1', intf2); + +## 5. Get sheet info & find sheet with data and data range +printf ("\n 5. Explore sheet info.\n"); +[~, shts] = xlsfinfo ('io-test.xls', intf); +shnr = strmatch ('Testsheet', shts(:, 1)); # Note case! +crange = shts{shnr, 2}; + +## 6. Read data back +printf ("\n 6. Read data back.\n"); +[num, txt, raw, lims] = xlsread ('io-test.xls', shnr, crange, intf); + +## 7. Here come the tests, part 1 +printf ("\n 7. Tests part 1 (basic I/O):\n"); +try + printf (" ...Numeric array... "); + assert (num(1:2, 1:3), [1, 2, NaN; 3, 4.5, NaN], 1e-10); + assert (num(4:5, 1:3), [NaN, NaN, NaN; NaN, 1, -83.4], 1e-10); + assert (num(3, 1:2), [NaN, NaN], 1e-10); + # Just check if it's numeric, the value depends too much on cached results + assert (isnumeric (num(3,3)), true); + printf ("matches...\n"); +catch + printf ("Hmmm.... error, see 'num'\n"); keyboard +end_try_catch +try + printf (" ...Cellstr array... "); + assert (txt{1, 1}, 'r1c1'); + assert (txt{2, 2}, 'r2c2'); + printf ("matches...\n"); +catch + printf ("Hmmm.... error, see 'txt'\n"); keyboard +end_try_catch +try + printf (" ...Boolean... "); + assert (islogical (raw{5, 2}), true); # Fails on COM + printf ("recovered...\n"); +catch + if (isnumeric (raw{5, 2})) + printf ("returned as numeric '1' rather than logical TRUE.\n"); + else + printf ("Hmmm.... error, see 'raw{5, 2}'\n"); keyboard + endif +end_try_catch + +## Check if formulas_as_text works (doesn't with COM): +printf ("\n 8. Repeat reading, now return formulas as text\n"); +opts.formulas_as_text = 1; +xls = xlsopen ('io-test.xls', 0, intf); +raw = xls2oct (xls, shnr, crange, opts); +xls = xlsclose (xls); + +## 9. Here come the tests, part 2. Fails on COM +printf ("\n 9. Tests part 2 (read back formula):\n"); + +try + # Just check if it contains any string + assert ( (ischar (raw{3, 3}) && ~isempty (raw(3, 3))), true); + printf (" ...OK, formula recovered ('%s').\n", raw{3, 3}); +catch + printf ("Hmmm.... error, see 'raw(3, 3)'"); + if (isnumeric (raw{3, 3})) + printf (" (equals %f, should be a string like '=c2+d2')\n", raw{3, 3}); + else + printf ("\n"); keyboard + endif +end_try_catch + +## 10. Clean up +printf ("\n10. Cleaning up....."); +delete 'io-test.xls'; +clear arr1 arr2 xls num txt raw lims opts shnr shts crange intf2; +printf (" OK\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-02-27 19:28:49
|
Revision: 9711 http://octave.svn.sourceforge.net/octave/?rev=9711&view=rev Author: prnienhuis Date: 2012-02-27 19:28:40 +0000 (Mon, 27 Feb 2012) Log Message: ----------- More range check fixes; layout; copyright statements updated Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2012-02-27 11:09:00 UTC (rev 9710) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2012-02-27 19:28:40 UTC (rev 9711) @@ -113,12 +113,14 @@ ## 2011-11-18 Fixed bug in test for range parameter being character string ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral +## 2012-02-27 More range arg fixes ## ## Last update of subfunctions below: 2012-02-26 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 if (isempty (c_arr)) warning ("Request to write empty matrix - ignored."); @@ -133,7 +135,8 @@ 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 - # Check ods file pointer struct + + # Check ods file pointer struct test1 = ~isfield (ods, "xtype"); test1 = test1 || ~isfield (ods, "workbook"); test1 = test1 || isempty (ods.workbook); @@ -141,10 +144,17 @@ if test1 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 range - if (~isempty (crange) && ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif + if (~isempty (crange) && ~ischar (crange)) + error ("Character string (range) expected for arg # 4"); + elseif (isempty (crange)) + crange = ''; + endif + # Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2012-02-27 11:09:00 UTC (rev 9710) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2012-02-27 19:28:40 UTC (rev 9711) @@ -109,6 +109,7 @@ ## 2011-11-18 Fixed another bug in test for range parameter being character string ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral +## 2012-02-27 More range param fixes ## Last script file update (incl. subfunctions): 2012-02-26 @@ -139,10 +140,17 @@ 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 range - if (~isempty (crange) && ~ischar (crange)), error ("Character string (range) expected for arg # 4"); endif + if (~isempty (crange) && ~ischar (crange)) + error ("Character string (range) expected for arg # 4"); + elseif (isempty (crange)) + crange = ''; + endif + # Various options if (isempty (spsh_opts)) spsh_opts.formulas_as_text = 0; @@ -157,23 +165,23 @@ if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified.\n"); endif # Select interface to be used - if (strcmp (xls.xtype, 'COM')) + if (strcmpi (xls.xtype, 'COM')) # Call oct2com2xls to do the work [xls, rstatus] = oct2com2xls (obj, xls, wsh, crange, spsh_opts); - elseif (strcmp (xls.xtype, 'POI')) + elseif (strcmpi (xls.xtype, 'POI')) # Invoke Java and Apache POI [xls, rstatus] = oct2jpoi2xls (obj, xls, wsh, crange, spsh_opts); - elseif (strcmp (xls.xtype, 'JXL')) + elseif (strcmpi (xls.xtype, 'JXL')) # Invoke Java and JExcelAPI [xls, rstatus] = oct2jxla2xls (obj, xls, wsh, crange, spsh_opts); - elseif (strcmp (xls.xtype, 'OXS')) -# # Invoke Java and OpenXLS ##### Not complete, saving file doesn't work yet! + 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] = oct2oxs2xls (obj, xls, wsh, crange, spsh_opts); - elseif (strcmp (xls.xtype, 'UNO')) + elseif (strcmpi (xls.xtype, 'UNO')) # Invoke Java and UNO bridge (OpenOffice.org) [xls, rstatus] = oct2uno2xls (obj, xls, wsh, crange, spsh_opts); -# elseif (strcmp'xls.xtype, '<whatever>')) +# elseif (strcmpi (xls.xtype, '<whatever>')) # <Other Excel interfaces> else error (sprintf ("oct2xls: unknown Excel .xls interface - %s.", xls.xtype)); @@ -183,7 +191,7 @@ #=================================================================================== -## Copyright (C) 2009,2010 by Philip Nienhuis <prn...@us...> +## Copyright (C) 2009,2010,2011,2012 by Philip Nienhuis <prn...@us...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -236,7 +244,7 @@ ## 2010-08-01 Added range vs. array size vs. capacity checks ## 2010-08-03 Moved range checks and type array parsing to separate functions ## 2010-10-20 Bug fix removing new empty sheets in new workbook that haven't been -## created in the first place duetoExcelsetting (thanks Ian Journeaux) +## created in the first place due to Excel setting (thanks Ian Journeaux) ## " Changed range use in COM transfer call ## 2010-10-21 Improved file change tracking (var xls.changed) ## 2010-10-24 Fixed bug introduced in above fix: for loops have no stride param, @@ -244,6 +252,7 @@ ## " Added check for "live" ActiveX server ## 2010-11-12 Moved ptr struct check into main func ## 2012-01-26 Fixed "seealso" help string +## 2012-02-27 Copyright strings updated function [ xls, status ] = oct2com2xls (obj, xls, wsh, crange, spsh_opts) @@ -415,7 +424,7 @@ #==================================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -472,6 +481,7 @@ ## 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 +## 2012-02-27 Copyright strings updated function [ xls, rstatus ] = oct2jpoi2xls (obj, xls, wsh, crange, spsh_opts) @@ -578,7 +588,7 @@ #==================================================================================== -## Copyright (C) 2009,2010 Philip Nienhuis <prnienhuis at users.sf.net> +## Copyright (C) 2009,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 @@ -633,10 +643,11 @@ ## 2010-08-03 Moved range checks and cell type parsing to separate routines ## 2010-08-11 Moved addcell() into try-catch as it is addCell which throws fatal errors ## 2010-10-20 Improved logic for tracking file changes (xls.changed 2 or 3); dropped -## " internal variable 'changed' +## '' internal variable 'changed' ## 2010-10-27 File change tracking again refined ## 2010-11-12 Moved ptr struct check into main func ## 2012-01-26 Fixed "seealso" help string +## 2012-02-27 Copyright strings updated function [ xls, rstatus ] = oct2jxla2xls (obj, xls, wsh, crange, spsh_opts) @@ -794,7 +805,7 @@ ## Author: Philip Nienhuis <prn...@us...> ## Created: 2011-03-29 ## Updates: -##oct2oxs2xls +## function [ xls, rstatus ] = oct2oxs2xls (obj, xls, wsh, crange, spsh_opts) @@ -889,7 +900,7 @@ endfunction -## Copyright (C) 2011 Philip Nienhuis <prn...@us...> +## Copyright (C) 2011,2012 Philip Nienhuis <prn...@us...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -914,6 +925,7 @@ ## 2012-02-25 Fixed wrong var name in L.933 ## 2012-02-25 Catch stray Java RuntimeException when deleting sheets ## 2012-02-26 Bug fix when adding sheets near L.994 (wrong if-else-end construct). +## 2012-02-27 Copyright strings updated function [ xls, rstatus ] = oct2uno2xls (c_arr, xls, wsh, crange, spsh_opts) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-03-01 22:22:30
|
Revision: 9737 http://octave.svn.sourceforge.net/octave/?rev=9737&view=rev Author: prnienhuis Date: 2012-03-01 22:22:23 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Changed UNO warning so that it is suppressed when UNO is not yet chosen Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2012-03-01 17:45:35 UTC (rev 9736) +++ trunk/octave-forge/main/io/inst/odsopen.m 2012-03-01 22:22:23 UTC (rev 9737) @@ -92,7 +92,7 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-02-26 Added ";" to suppress echo of filename f UNO ## -## Latest change on subfunctions below: 2011-09-18 +## Latest change on subfunctions below: 2012-02-01 function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) @@ -375,26 +375,26 @@ ## 2010-06-## dropped 0.8.5, too buggy ## 2010-08-22 Experimental odfdom 0.8.6 support ## 2010-08-23 Added odfvsn (odfdom version string) to output struct argument -## " Bugfix: moved JOD version check to main function (it can't work here) -## " Finalized odfdom 0.8.6 support (even prefered version now) +## '' Bugfix: moved JOD version check to main function (it can't work here) +## '' Finalized odfdom 0.8.6 support (even prefered version now) ## 2010-09-11 Somewhat clarified messages about missing java classes -## " Rearranged code a bit; fixed typos in OTK detection code (odfdvsn -> odfvsn) +## '' Rearranged code a bit; fixed typos in OTK detection code (odfdvsn -> odfvsn) ## 2010-09-27 More code cleanup ## 2010-11-12 Warning added about waning support for odfdom v. 0.7.5 ## 2011-05-06 Fixed wrong strfind tests -## " Experimental UNO support added +## '' Experimental UNO support added ## 2011-05-18 Forgot to initialize odsinterfaces.UNO ## 2011-06-06 Fix for javaclasspath format in *nix w. java-1.2.8 pkg -## " Implemented more rigid Java check -## " Tamed down verbosity +## '' Implemented more rigid Java check +## '' Tamed down verbosity ## 2011-09-03 Fixed order of odsinterfaces.<member> statement in Java detection try-catch -## " Reset tmp1 (always allow interface rediscovery) for empty odsinterfaces arg +## '' Reset tmp1 (always allow interface rediscovery) for empty odsinterfaces arg ## 2011-09-18 Added temporary warning about UNO interface function [odsinterfaces] = getodsinterfaces (odsinterfaces) persistent tmp1 = []; persistent jcp; - persistent uno_1st_time = []; + persistent uno_1st_time = 0; if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) # Assume no interface detection has happened yet @@ -513,7 +513,7 @@ if (jpchk >= numel (entries)) odsinterfaces.UNO = 1; printf ("UNO"); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; 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 @@ -525,8 +525,8 @@ ## FIXME the below stanza should be dropped once UNO is stable. # Echo a suitable warning about experimental status: - if (isempty (uno_1st_time) && odsinterfaces.UNO); - uno_1st_time = 1; + if (uno_1st_time == 1) + ++uno_1st_time; printf ("\nPLEASE NOTE: UNO (=OpenOffice.org-behind-the-scenes) is EXPERIMENTAL\n"); printf ("After you've opened a spreadsheet file using the UNO interface,\n"); printf ("odsclose on that file will kill ALL OpenOffice.org invocations,\n"); Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2012-03-01 17:45:35 UTC (rev 9736) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2012-03-01 22:22:23 UTC (rev 9737) @@ -104,9 +104,9 @@ ## 2011-09-03 Reset chkintf to [] if no xls support was discovered (to allow ## rediscovery of interfaces between xlsopen calls, e.g. javaclasspath changes) ## 2011-09-08 Minor code cleanup +## 2012-01-26 Fixed "seealso" help string ## -## 2011-09-18 Latest subfunction update -## 2012-01-26 Fixed "seealso" help string +## Latest subfunction update: 2012-02-01 function [ xls ] = xlsopen (filename, xwrite=0, reqinterface=[]) @@ -450,12 +450,13 @@ ## '' Reset tmp1 (always allow interface rediscovery) for empty xlsinterfaces arg ## 2011-09-08 Minor code cleanup ## 2011-09-18 Added temporary warning about UNO interface +## 2012-03-01 Changed UNO warning so that it is suppressed when UNO is not yet chosen function [xlsinterfaces] = getxlsinterfaces (xlsinterfaces) # tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) persistent tmp1 = []; persistent jcp; # Java class path - persistent uno_1st_time; + persistent uno_1st_time = 0; if (isempty (xlsinterfaces.COM) && isempty (xlsinterfaces.POI) && isempty (xlsinterfaces.JXL) && isempty (xlsinterfaces.OXS)) printf ("Detected interfaces: "); @@ -598,7 +599,7 @@ if (jpchk >= numel (entries)) xlsinterfaces.UNO = 1; printf ('UNO'); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif + if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; uno_1st_time = min (++uno_1st_time, 2); endif endif endif @@ -608,8 +609,8 @@ ## FIXME the below stanza should be dropped once UNO is stable. # Echo a suitable warning about experimental status: - if (isempty (uno_1st_time) && xlsinterfaces.UNO); - uno_1st_time = 1; + if (uno_1st_time == 1) + ++uno_1st_time; printf ("\nPLEASE NOTE: UNO (=OpenOffice.org-behind-the-scenes) is EXPERIMENTAL\n"); printf ("After you've opened a spreadsheet file using the UNO interface,\n"); printf ("xlsclose on that file will kill ALL OpenOffice.org invocations,\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-03-07 19:35:20
|
Revision: 9775 http://octave.svn.sourceforge.net/octave/?rev=9775&view=rev Author: prnienhuis Date: 2012-03-07 19:35:08 +0000 (Wed, 07 Mar 2012) Log Message: ----------- Updated texinfo help text Modified Paths: -------------- trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/oct2xls.m trunk/octave-forge/main/io/inst/odsread.m trunk/octave-forge/main/io/inst/odswrite.m trunk/octave-forge/main/io/inst/xlsread.m trunk/octave-forge/main/io/inst/xlswrite.m Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2012-03-07 19:09:25 UTC (rev 9774) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2012-03-07 19:35:08 UTC (rev 9775) @@ -30,8 +30,9 @@ ## odsclose is needed to write the updated spreadsheet to disk (and ## -if needed- close the Java invocation holding the file pointer). ## -## @var{arr} can be any array type save complex. Mixed numeric/text arrays -## can only be cell arrays. +## @var{arr} can be any 1D or 2D array containing numerical or character +## data (cellstr) except complex. Mixed numeric/text arrays can only be +## cell arrays. ## ## @var{ods} must be a valid pointer struct created earlier by odsopen. ## @@ -114,6 +115,7 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral ## 2012-02-27 More range arg fixes +## 2012-03-07 Updated texinfo help text ## ## Last update of subfunctions below: 2012-02-26 @@ -237,11 +239,11 @@ ## 2010-03-08 Some comment lines adapted ## 2010-03-25 Try-catch added f. unpatched-for-booleans java-1.2.6 / 1.2.7 package ## 2010-04-11 Changed all references to "cell" to "scell" to avoid reserved keyword -## " Small bugfix for cases with empty left columns (wrong cell reference) +## '' Small bugfix for cases with empty left columns (wrong cell reference) ## 2010-04-13 Fixed bug with stray cell copies beyond added data rectangle ## 2010-07-29 Added formula input support (based on xls patch by Benjamin Lindner) ## 2010-08-01 Added try-catch around formula input -## " Changed range arg to also allow just topleft cell +## '' Changed range arg to also allow just topleft cell ## 2010-08-03 Moved range checks and type array parsing to separate functions ## 2010-08-13 Fixed empty Sheet1 in case of new spreadsheets, fix input text sheet name ## 2010-10-27 Improved file change tracking tru ods.changed @@ -872,11 +874,11 @@ ## 2010-06-01 Checked logic. AFAICS all should work with upcoming jOpenDocument 1.2b4; ## in 1.2b3 adding a newsheet always leaves an incomplete upper row; ## supposedly (hopefully) that will be fixed in 1.2b4. -## " Added check for jOpenDocument version. Adding sheets only works for +## '' Added check for jOpenDocument version. Adding sheets only works for ## 1.2b3+ (barring bug above) ## 2010-06-02 Fixed first sheet remaining in new spreadsheets ## 2010-08-01 Added option for crange to be only topleft cell address -## " Code cleanup +## '' Code cleanup ## 2010-08-13 Fixed bug of ignoring text sheet name in case of new spreadsheet ## 2010-08-15 Fixed bug with invalid first sheet in new spreadsheets ## 2010-10-27 Improved file change tracking tru ods.changed Modified: trunk/octave-forge/main/io/inst/oct2xls.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2xls.m 2012-03-07 19:09:25 UTC (rev 9774) +++ trunk/octave-forge/main/io/inst/oct2xls.m 2012-03-07 19:35:08 UTC (rev 9775) @@ -29,8 +29,9 @@ ## A subsequent call to xlsclose is needed to write the updated spreadsheet ## to disk (and -if needed- close the Excel or Java invocation). ## -## @var{arr} can be any array type save complex. Mixed numeric/text arrays -## can only be cell arrays. +## @var{arr} can be any 1D or 2D array containing numerical or character +## data (cellstr) except complex. Mixed numeric/text arrays can only be +## cell arrays. ## ## @var{xls} must be a valid pointer struct created earlier by xlsopen. ## @@ -93,8 +94,8 @@ ## 2010-03-14 Updated help text section on java memory usage ## 2010-07-27 Added formula writing support (based on patch by Benjamin Lindner) ## 2010-08-01 Added check on input array size vs. spreadsheet capacity -## " Changed argument topleft into range (now compatible with ML); the -## " old argument version (just topleft cell) is still recognized, though +## '' Changed argument topleft into range (now compatible with ML); the +## '' old argument version (just topleft cell) is still recognized, though ## 2010-08014 Added char array conversion to 1x1 cell for character input arrays ## 2010-08-16 Added check on presence of output argument. Made wsh = 1 default ## 2010-08-17 Corrected texinfo ("topleft" => "range") @@ -110,6 +111,7 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral ## 2012-02-27 More range param fixes +## 2012-03-07 Updated texinfo help text ## Last script file update (incl. subfunctions): 2012-02-26 @@ -238,18 +240,18 @@ ## 2010-01-13 Removed an extraneous statement used for debugging ## I plan look at it when octave v.3.4 is about to arrive. ## 2010-08-01 Added checks for input array size vs check on capacity -## " Changed topleft arg into range arg (just topleft still recognized) -## " Some code cleanup -## " Added option for formula input as text string +## '' Changed topleft arg into range arg (just topleft still recognized) +## '' Some code cleanup +## '' Added option for formula input as text string ## 2010-08-01 Added range vs. array size vs. capacity checks ## 2010-08-03 Moved range checks and type array parsing to separate functions ## 2010-10-20 Bug fix removing new empty sheets in new workbook that haven't been ## created in the first place due to Excel setting (thanks Ian Journeaux) -## " Changed range use in COM transfer call +## '' Changed range use in COM transfer call ## 2010-10-21 Improved file change tracking (var xls.changed) ## 2010-10-24 Fixed bug introduced in above fix: for loops have no stride param, -## " replaced by while loop -## " Added check for "live" ActiveX server +## '' replaced by while loop +## '' Added check for "live" ActiveX server ## 2010-11-12 Moved ptr struct check into main func ## 2012-01-26 Fixed "seealso" help string ## 2012-02-27 Copyright strings updated @@ -638,8 +640,8 @@ ## Added check for valid file pointer struct ## 2010-08-01 Improved try-catch for formulas to enter wrong formulas as text strings ## 2010-08-01 Added range vs. array size vs. capacity checks -## " Code cleanup -## " Changed topleft arg into range arg (topleft version still recognized) +## '' Code cleanup +## '' Changed topleft arg into range arg (topleft version still recognized) ## 2010-08-03 Moved range checks and cell type parsing to separate routines ## 2010-08-11 Moved addcell() into try-catch as it is addCell which throws fatal errors ## 2010-10-20 Improved logic for tracking file changes (xls.changed 2 or 3); dropped Modified: trunk/octave-forge/main/io/inst/odsread.m =================================================================== --- trunk/octave-forge/main/io/inst/odsread.m 2012-03-07 19:09:25 UTC (rev 9774) +++ trunk/octave-forge/main/io/inst/odsread.m 2012-03-07 19:35:08 UTC (rev 9775) @@ -24,8 +24,10 @@ ## in OpenOffice_org Calc spreadsheet file @var{filename}. ## ## You need the octave-forge java package (> 1.2.6) and one or both of -## jopendocument-<version>.jar or preferrably: (odfdom.jar (version 0.7.5 -#3 or 0.8.6) & xercesImpl.jar) in your javaclasspath. +## jopendocument-<version>.jar or preferrably: (odfdom.jar (versions +## 0.7.5, 0.8.6 or 0.8.7) & xercesImpl.jar v. 2.9.1) in your javaclasspath. +## There is also experimental support invoking OpenOffice.org or clones +## through Java/UNO bridge. ## ## Return argument @var{numarr} contains the numeric data, optional ## return arguments @var{txtarr} and @var{rawarr} contain text strings @@ -59,8 +61,8 @@ ## ## The optional last argument @var{reqintf} can be used to override ## the automatic selection by odsread of one interface out of the -## supported ones: Java/ODFtoolkit ('OTK') or Java/jOpenDocument -## ('JOD'). +## supported ones: Java/ODFtoolkit ('OTK'), Java/jOpenDocument +## ('JOD') or Java/UNO bridge ('UNO'). ## ## Erroneous data and empty cells are set to NaN in @var{numarr} and ## turn up empty in @var{txtarr} and @var{rawarr}. Date/time values @@ -116,6 +118,7 @@ ## 2011-09-08 Catch empty ods structs after failed odsopen attempts ## 2011-09-18 Return empty output arg in case of empty rawarr ## 2012-01-26 Fixed "seealso" help string +## 2012-03-07 Updated texinfo help text function [ numarr, txtarr, rawarr, lim ] = odsread (filename, wsh=1, datrange=[], reqintf=[]) Modified: trunk/octave-forge/main/io/inst/odswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/odswrite.m 2012-03-07 19:09:25 UTC (rev 9774) +++ trunk/octave-forge/main/io/inst/odswrite.m 2012-03-07 19:35:08 UTC (rev 9775) @@ -28,8 +28,9 @@ ## file name extension). If @var{filename} does not contain any directory ## path, the file is saved in the current directory. ## -## @var{arr} can be any array type save complex. Mixed numeric/text arrays -## can only be cell arrays. +## @var{arr} can be any 1D or 2D array containing numerical or character +## data (cellstr) except complex. Mixed numeric/text arrays can only be +## cell arrays. ## ## @var{wsh} can be a number or string. In case of a not yet existing ## OpenOffice.org spreadsheet, the first sheet will be used & named @@ -48,7 +49,8 @@ ## Array @var{arr} will be clipped at the right and/or bottom if its size ## is bigger than can be accommodated in @var{range}. ## If @var{arr} is smaller than the @var{range} allows, it is placed -## in the top left of @var{range}. +## in the top left rectangle of @var{range} and cell values outside that +## rectangle will be untouched. ## ## If @var{range} contains merged cells, only the elements of @var{arr} ## corresponding to the top or left Calc cells of those merged cells @@ -92,6 +94,7 @@ ## 2011-09-08 Minor filename error text adaptation ## 2012-01-26 Fixed "seealso" help string ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral +## 2010-03-07 Updated texinfo help text function [ rstatus ] = odswrite (filename, data, wsh=1, crange='', reqintf=[]) Modified: trunk/octave-forge/main/io/inst/xlsread.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsread.m 2012-03-07 19:09:25 UTC (rev 9774) +++ trunk/octave-forge/main/io/inst/xlsread.m 2012-03-07 19:35:08 UTC (rev 9775) @@ -25,11 +25,7 @@ ## in Excel spreadsheet file @var{filename}. ## Return argument @var{numarr} contains the numeric data, optional ## return arguments @var{txtarr} and @var{rawarr} contain text strings -## and the raw spreadsheet cell data, respectively. -## -## If neither Excel, Java/Apache POI or Java/JExcelAPI are installed, -## xlsread will fail and suggest .csv file reading. -## +## and the raw spreadsheet cell data, respectively. Return argument ## @var{limits} contains the outer column/row numbers of the read ## spreadsheet range where @var{numarr}, @var{txtarr} and @var{rawarr} ## have come from (remember, xlsread trims outer rows and columns). @@ -37,16 +33,15 @@ ## If @var{filename} does not contain any directory, the file is ## assumed to be in the current directory. The filename extension ## (.xls or .xlsx) must be included in the file name; when using the -## COM interface any file format can be read from that can be read -## and written by the locally installed MS-Excel version (e.g., wk1, -## csv, dbf, ...). +## COM interface all file formats can be read that are supported by the +## locally installed MS-Excel version (e.g., wk1, csv, dbf, etc.). ## ## @var{range} is expected to be a regular spreadsheet range format, ## or "" (empty string, indicating all data in a worksheet). ## If no range is specified the occupied cell range will have to be ## determined behind the scenes first; this can take some time for the -## Java-based interfaces (but the results are more reliable than that -## of ActiveX/COM). +## Java-based interfaces (but the results may be more reliable than +## that of ActiveX/COM). ## ## @var{wsh} is either numerical or text; in the latter case it is ## case-sensitive and it may be max. 31 characters long. @@ -56,12 +51,12 @@ ## in the Excel file. ## ## If only the first argument is specified, xlsread will try to read -## all contents from the first = leftmost (or the only) worksheet (as -## if a range of @'' (empty string) was specified). +## all contents (as if a range of @'' (empty string) was specified) +## from the first = leftmost (or the only) worksheet ## ## If only two arguments are specified, xlsread assumes the second ## argument to be @var{range} if it is a string argument and contains -## a ":" or if it is @'' (empty string) and in those cases assumes +## a ":" or if it is @'' (empty string), and in those cases assumes ## the data must be read from the first worksheet (not necessarily ## Sheet1! but the leftmost sheet). ## @@ -71,13 +66,13 @@ ## xlsread tries to read all data contained in that worksheet. ## ## The optional last argument @var{reqintf} can be used to override -## the automatic selection by xlsread of one interface out of the -## supported ones: COM/Excel, Java/Apache POI, or Java/JExcelAPI -## (in that built-in order of preference). -## For reading from OOXML files a value of 'poi' or 'uno' must be specified -## for @var{reqintf} (see help for xlsopen); for Excel'95 files use -## 'com', or if Excel is not installed use 'jxl', 'basic', or 'uno' (POI -## can't read Excel 95 but will try to fall back to JXL). +## the automatic interface selection by xlsread out of the supported +## ones: COM/Excel, Java/Apache POI, Java/JExcelAPI, Java/OpenXLS, or +## Java/UNO (OpenOffice.org) (in that -built in- order of preference). +## For reading from OOXML files a value of 'com', 'poi' or 'uno' must +## be specified for @var{reqintf} (see help for xlsopen); for Excel'95 +## files use 'com', or if Excel is not installed use 'jxl', 'basic' +## or 'uno' (POI can't read Excel 95 but will try to fall back to JXL). ## As @var{reqintf} can also be a cell array of strings, one can ## select or exclude one or more interfaces. ## @@ -85,7 +80,8 @@ ## turn up empty in @var{txtarr} and @var{rawarr}. Date/time values in ## Excel are returned as numerical values in @var{numarr}. Note that ## Excel and Octave have different date base values (1/1/1900 & -## 1/1/0000, resp.) +## 1/1/0000, resp.). Spreadsheet date values lying before 1/1/1900 are +## returned as strings, formatted as they appear in the spreadsheet. ## @var{numarr} and @var{txtarr} are trimmed from empty outer rows ## and columns. Be aware that Excel does the same for @var{rawarr}, ## so any returned array may turn out to be smaller than requested in @@ -96,11 +92,11 @@ ## "corresponding" Excel cells are empty. ## ## xlsread is just a wrapper for a collection of scripts that find out -## the interface to be used (COM, Java/POI, Java/JXL) and do the actual -## reading. For each call to xlsread the interface must be started and -## the Excel file read into memory. When reading multiple ranges (in -## optionally multiple worksheets) a significant speed boost can be -## obtained by invoking those scripts directly as in: +## the interface to be used (COM, Java/POI, Java/JXL Java/OXS, Java/UNO) +## and do the actual reading. For each call to xlsread the interface must +## be started and the Excel file read into memory. When reading multiple +## ranges (in optionally multiple worksheets) a significant speed boost +## can be obtained by invoking those scripts directly as in: ## xlsopen / xls2oct [/ parsecell] / ... / xlsclose ## ## Beware: when using the COM interface, hidden Excel invocations may be @@ -138,7 +134,7 @@ ## 2010-01-12 added unwind_protect to get rid of stray Excel invocations i.c.o. COM errors ## 2010-05-31 Updated help text (delays i.c.o. empty range due to getusedrange call) ## 2010-08-18 Added check for existence of xls after call to xlsopen to -## " avoid unneeded error message clutter +## '' avoid unneeded error message clutter ## 2010-08-25 Improved help text, esp. sections Excel file types and interfaces ## 2010-10-20 Dropped wiping xls.limits for COM (nowadays COM can return those) ## 2010-10-21 Formally added 'BASIC' option as synonym for 'JXL' @@ -148,6 +144,7 @@ ## 2011-04-17 Suppress xlsopen messages (";" was missing) ## 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 function [ numarr, txtarr, rawarr, lims ] = xlsread (fn, wsh, datrange, reqintf=[]) Modified: trunk/octave-forge/main/io/inst/xlswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/xlswrite.m 2012-03-07 19:09:25 UTC (rev 9774) +++ trunk/octave-forge/main/io/inst/xlswrite.m 2012-03-07 19:35:08 UTC (rev 9775) @@ -28,18 +28,20 @@ ## name extension). If @var{filename} does not contain any directory path, ## the file is saved in the current directory. ## -## @var{arr} can be any array type save complex. Mixed numeric/text arrays -## can only be cell arrays. +## @var{arr} can be any 1D or 2D array containing numerical or character +## data (cellstr) except complex. Mixed numeric/text arrays can only be +## cell arrays. ## ## If only 3 arguments are given, the 3rd is assumed to be a spreadsheet ## range if it contains a ":" or is a completely empty string (corresponding -## to A1:IV65336). The 3rd argument is assumed to refer to a worksheet if -## it is a numeric value or a non-empty text string not containing ":" +## to A1:IV65336 for regular .xls or A1:XFD1048576 for OOXML .xlsx). The +## 3rd argument is assumed to refer to a worksheet if it is a numeric value +## or a non-empty text string not containing ":" ## ## @var{wsh} can be a number or string (max. 31 chars). ## In case of a not yet existing Excel file, the first worksheet will be ## used & named according to @var{wsh} - the extra worksheets that Excel -## creates by default are deleted. +## normally creates by default are deleted. ## In case of existing files, some checks are made for existing worksheet ## names or numbers, or whether @var{wsh} refers to an existing sheet with ## a type other than worksheet (e.g., chart). @@ -53,7 +55,8 @@ ## Array @var{arr} will be clipped at the right and/or bottom if its size ## is bigger than can be accommodated in @var{range}. ## If @var{arr} is smaller than the @var{range} allows, it is placed -## in the top left of @var{range}. +## in the top left rectangle of @var{range} and remaining cell values +## outside the rectangle will be retained. ## ## If @var{range} contains merged cells, only the elements of @var{arr} ## corresponding to the top or left Excel cells of those merged cells @@ -64,18 +67,21 @@ ## the automatic selection by xlswrite of one interface out of the ## supported ones: 'com' (ActiveX/Excel), 'poi' (Java/Apache POI), 'jxl' ## (Java/JExcelAPI), or 'uno' (Java/OpenOffice.org). 'oxs' (Java/OpenXLS) -## is implemented but disabled for writing. For writing to OOXML files -## (.xlsx) a value of 'poi' or 'uno' must be specified for @var{reqintf}. -## The value of @var{reqintf} is case-insensitive. Multiple interfaces -## can be selected if entered as a cell array of strings. +## is implemented but disabled for writing as it is too buggy. For +## writing to OOXML files (.xlsx) a value of 'com', 'poi' or 'uno' must +## be specified for @var{reqintf}. The value of @var{reqintf} is +## case-insensitive. Multiple interfaces can be selected if entered as +## a cell array of strings. ## ## xlswrite is a mere wrapper for various scripts which find out what -## Excel interface to use (COM, Java/POI) plus code to mimic the other +## Excel interface to use (COM, POI, etc) plus code to mimic the other ## brand's syntax. For each call to xlswrite such an interface must be ## started and possibly an Excel file loaded. When writing to multiple ## ranges and/or worksheets in the same Excel file, a speed bonus can be -## obtained by invoking those scripts (xlsopen / octxls / .... / xlsclose) -## directly. +## obtained by invoking those scripts directly with multiple calls to +## oct2xls (one for each sheet or range) surrounded by one call to +## xlsopen and xlsclose: +## (xlsopen / octxls / oct2xls / .... / xlsclose) ## ## Examples: ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |