Hi Ian,
Ian Journeaux wrote:
> I am trying to use XLSWrite with the Windows version of Octave. I have the
> Java and Windows packages loaded. I started this discussion on the Octave
> Help list but it was recommended that I post to the OctDev list instead.
(... because the Excel I/O is not in "core Octave" (and as such doesn't
"belong" on the mailing lists for core Octave) but in Octave-Forge
(meant for extra Octave toolboxes not supported by the core-Octave
developers team).
Not my choice, it's just the way it is)
Read on....
> Everything seems to initiate correctly but I get a COM error
>
> Excel/COM interface requested... Excel (COM) OK.
> Creating file Job006-10345-vp3.xls
> error: com_invoke: property/method invocation on the COM object failed with
> error `0x80020009'
> error: called from:
> error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\packages\io-1.0.11\oct2xls.m
> at line 290, column 3
> error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\packages\io-1.0.11\oct2xls.m
> at line 86, column 17
> error: C:/HelioDotSkip/Scripts\helio2.m at line 524, column 10
> octave-3.2.4.exe:2>
> Here is the sequence of calls I am making to output to the XLS file.
>
> xlh=xlsopen(Tout,'1','COM');
> [xlh rs]=oct2xls(str1,xlh,SampleID,'A1');
> xlh=xlsclose(xlh);
> xlh=xlsopen(Tout,'1','COM');
> [xlh rs]=oct2xls(str2,xlh,SampleID,'A20');
> xlh=xlsclose(xlh);
> xlh=xlsopen(Tout,'1','COM');
> [xlh rs]=oct2xls(str3,xlh,SampleID,'E1');
> xlh=xlsclose(xlh);
> xlh=xlsopen(Tout,'1','COM');
> [xlh rs]=oct2xls(str3,xlh,SampleID,'E20');
> xlh=xlsclose(xlh);
> xlh=xlsopen(Tout,'1','COM');
> [xlh rs]=oct2xls(str4,xlh,SampleID,'B2');
> xlh=xlsclose(xlh);
> xlh=xlsopen(Tout,'1','COM');
> [xlh rs]=oct2xls(str4,xlh,SampleID,'B21');
> xlh=xlsclose(xlh);
>
> How can I get past this error?
I think I finally can make more sense of these; and I have a question
for you (far below, under Question:).
Let's see:
1. You only need to open the .xls file once for all subsequent calls to
oct2xls.m
2. You MUST specify the extension in the file name.
Is Tout a string variable with a complete filename like
'blahblahblah.xls'?
If not, please tell us the value of Tout (and for that matter, str1,
str2, str3 and str4)
3.The second argument to xlsopen must be an integer value, not a string
value. See second example when you do (in Octave)
"help xlsopen" (w/o quotes)
4. In the *output* argument list arguments should be separated with a
comma as well. See example when you do
"help oct2xls" (w/o quotes)
(5. A personal preference: I'd like to make things more readable by
adding spaces here and there. Up to you to follow or not, your choice.)
So the sequence should rather look like this:
Tout = 'somefilename.xls';
xlh = xlsopen (Tout, 1, 'COM');
[xlh, rs] = oct2xls (str1, xlh, SampleID, 'A1');
[xlh, rs] = oct2xls (str2, xlh, SampleID, 'A20');
[xlh, rs] = oct2xls (str3, xlh, SampleID, 'E1');
[xlh, rs] = oct2xls (str3, xlh, SampleID, 'E20');
[xlh, rs] = oct2xls (str4, xlh, SampleID, 'B2');
[xlh, rs] = oct2xls (str4, xlh, SampleID, 'B21');
xlh = xlsclose (xlh);
You see, the whole xlsopen - oct2xls - xlsclose fandango was invented to
avoid a repeated sequence of:
- starting up Excel
- reading the complete .xls file (these 2 happen in xlsopen.m)
- saving the complete .xls file
- closing Excel. (these 2 happen in xlsclose.m)
for every read/write action to the same Excel file.
In fact, xlswrite (and for that matter, xlsread) are simple wrappers
around xlsopen - oct2xls / [xls2oct-parsecell] - xlsclose sequences for
just one worksheet. Matlab works exactly like that; for repeated actions
like you want, Matlab users must dive in the ActiveX/COM programming
language themselves.
For Octave I chose to make this sort of thing a bit easier and much
faster for users; I often use this myself. And (for me as author /
maintainer) this makes the code much cleaner.
BTW as written in earlier reply postings on the help-octave ML, this is
all outlined in the README-XLS.html file in the IO package's ./doc
directory.
Question:
=========
What I do not understand is why you need repeated calls to oct2xls.m for
writing each and every single string to one and the same worksheet
('SampleID'). It's faster to first assign them to a cell array in the
proper position (i.e., build a cell array from those strings) and then
write the whole cell array to the Excel file.
Assuming str1 - str4 are just character strings:
carr = cell (21, 5); # 21 rows, 5 columns A-E of empty cells
carr { 1, 1} = str1; # Note brackets rather than parens
carr {20, 1} = str2; # (20, 1) corresponds to A20
carr { 1, 5} = str3; # ( 1, 5) " E1
carr { 2, 2} = str4; # ( 2, 2) " B2
carr {21, 2} = str4; # (21, 2) " B21
Please let me know if you can get it to work using these suggestions.
Regards,
Philip
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev