Mercurial > forge
changeset 8369:ce402c3d3454 octave-forge
Adapted sh_names variable handling to support class changes in LibreOffice 3.4.+
author | prnienhuis |
---|---|
date | Sun, 18 Sep 2011 16:25:50 +0000 |
parents | 9f4c76ad0f42 |
children | e888eb214cf2 |
files | main/io/inst/oct2ods.m main/io/inst/oct2xls.m main/io/inst/ods2oct.m main/io/inst/xls2oct.m |
diffstat | 4 files changed, 41 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/main/io/inst/oct2ods.m Sun Sep 18 16:24:15 2011 +0000 +++ b/main/io/inst/oct2ods.m Sun Sep 18 16:25:50 2011 +0000 @@ -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');
--- a/main/io/inst/oct2xls.m Sun Sep 18 16:24:15 2011 +0000 +++ b/main/io/inst/oct2xls.m Sun Sep 18 16:25:50 2011 +0000 @@ -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 <prnienhuis@users.sf.net> ## 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');
--- a/main/io/inst/ods2oct.m Sun Sep 18 16:24:15 2011 +0000 +++ b/main/io/inst/ods2oct.m Sun Sep 18 16:25:50 2011 +0000 @@ -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 <prnienhuis@users.sf.net> ## 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
--- a/main/io/inst/xls2oct.m Sun Sep 18 16:24:15 2011 +0000 +++ b/main/io/inst/xls2oct.m Sun Sep 18 16:25:50 2011 +0000 @@ -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 <prnienhuis@users.sf.net> ## 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