Info

This question is closed. Reopen it to edit or answer.

sheetnames() leaves Excel file locked?

39 views (last 30 days)
dpb
dpb on 27 Nov 2024 at 18:47
Closed: dpb on 3 Dec 2024 at 12:53
In a debugging session, something seemingly bizarre occurred -- function is to create an Excel sheet for import into another product; the file is given by the variable FTemplate and has been previously read from by readtable() and confirmed the file can at this point be opened in Excel as writeable.
There are a whole bunch of sheets in the file and they're not named in a really convenient way, so while stopped in the debugger I executed sheetnames(FTemplate) in order to get the desired sheet name to use to write a test section of data and
K>> shts=sheetnames(FTemplate);
K>> sht=shts(contains(shts,'6.30.24'))
sht =
"Journal Entries -BegBal 6.30.24"
K>> writetable(tJE,FTemplate,'Sheet',sht,'Range','A10','PreserveFormat',1,'WriteVariableNames',0)
Unable to write to file 'C:\SCCC Foundation\Financial\FinancialEdge\ImplementationDocuments\FENXT Import Templates 2024 - SCCCF.xlsm'. You may not have write permissions
or the file may be open by another application.
K>>
BOOM! the file is now locked. Looking with Task Manager, indeed there is a new Excel process in the background and it has the file locked...if one ends that task, then
K>> writetable(tJE,FTemplate,'Sheet',sht,'Range','A10','PreserveFormat',1,'WriteVariableNames',0)
K>>
lets one write to the file.
This is apparently a bug; I found in Task Manager earlier some 30 or more Excel processes hanging around that had apparently been created over the last week by this; I had no idea what had caused that to have happen until now. I had just rebooted to get rid of all those zombie processes when ran the above.
Has anybody else observed this and does it still occur in later releases before submitting a bug report?
  3 Comments
Stephen23
Stephen23 on 27 Nov 2024 at 22:07
Even if this only occurs when debugging it would still deserve a bug report.
dpb
dpb on 28 Nov 2024 at 15:33
@Stephen23, thanks; I think so as well...

Answers (2)

埃博拉酱
埃博拉酱 on 28 Nov 2024 at 0:42
I can't reproduce your bug in R2024b, even in a debug session. Maybe you should try to upgrade your MATLAB version.
  1 Comment
dpb
dpb on 28 Nov 2024 at 15:37
Thanks for trying and responding with your experience...it just happened here again, so it is reproducible with R2022b, anyway.
Unfortunately, I have some other constraints that make upgrading an unpalatable option for the time being at least...having to do with needing to support a compiled app on an IT-controlled machine that is using prior runtime version...not a Mathworks' problem.

dpb
dpb on 28 Nov 2024 at 17:44
Edited: dpb on 29 Nov 2024 at 14:16
Well, it turned out to be pilot error, after all!
I need to also pick a formula from the template file so the sheet would remain dynamic and forgot that initially while debugging I had commented out the line that closed the file in the ActiveX session that extracted that formula so I could see the sheet while getting that code right...then, forgot to go back and uncomment the line that closed the file after doing so...and then, completely forgot about having read the formula after moving on...
Sorry for the bum steer; I'll come back and delete the thread after the holiday weekend is over so it isn't cluttering up the forum needlessly.

This question is closed.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!