Mercurial > forge
changeset 12256:c226af31d4ad octave-forge
Implemented OOXML support for OpenXLS v.10; fixed file open support, no more lingering file locks
author | prnienhuis |
---|---|
date | Sun, 29 Dec 2013 22:38:19 +0000 |
parents | 351dac0d87de |
children | eb03c40ba74e |
files | main/io/inst/private/__OXS_spsh_open__.m |
diffstat | 1 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/main/io/inst/private/__OXS_spsh_open__.m Sun Dec 29 22:36:28 2013 +0000 +++ b/main/io/inst/private/__OXS_spsh_open__.m Sun Dec 29 22:38:19 2013 +0000 @@ -14,21 +14,43 @@ ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. -## __OXS_xlsopen__ - inernal function for opening an xls file using Java / OpenXLS +## __OXS_xlsopen__ - internal function for opening an xls file using Java / OpenXLS ## Author: Philip Nienhuis <prnienhuis at users.sf.net> ## Created: 2012-10-07 ## Updates: ## 2012-10-24 Style fixes -## 2013-12-06 Updated copyright string; style fixes +## 2013-12-06 Updated copyright string; style fixes +## 2013-12-28 Fix creating new files +## '' Implemented OOXML support for OpenXLS v.10 function [ xls, xlssupport, lastintf ] = __OXS_spsh_open__ (xls, xwrite, filename, xlssupport, ftype) - if (ftype != 1) - error ("OXS can only read from .xls (BIFF8; Excel'97-2003) files") + if (ftype != 1 && ftype != 2) + error ("OXS can only read from .xls (Excel'97-2003) or .xlsx (Excel 2007+) files") endif - try - wb = javaObject ("com.extentech.ExtenXLS.WorkBookHandle", filename); + try + if (xwrite > 2) + if (ftype == 1) + ## Create BIFF 8 file (.xls) + wb = javaObject ("com.extentech.ExtenXLS.WorkBookHandle", false); + else + ## Create OOXML file (.xlsx) + wb = javaObject ("com.extentech.ExtenXLS.WorkBookHandle", true); + endif + ## This new workbook has 3 empty sheets - get rid of the last two. + ## Renaming, if needed, of Sheet1 is handled in __OXS_oct2spsh__.m + for ii=2:wb.getNumWorkSheets + ## Remarkable = sheet index = 0-based! + wb.getWorkSheet (1).remove; + endfor + ## Workbook now has only one sheet ("Sheet1"). Rename it + wb.getWorkSheet(0).setSheetName (")_]_}_ Dummy sheet made by Octave_{_[_("); + else + xlsin = javaObject ("java.io.FileInputStream", filename); + wb = javaObject ("com.extentech.ExtenXLS.WorkBookHandle", xlsin); + xlsin.close (); + endif xls.xtype = "OXS"; xls.app = "void - OpenXLS"; xls.workbook = wb;