Info

此问题已关闭。 请重新打开它进行编辑或回答。

sheetnames() leaves Excel file locked?

39 次查看(过去 30 天)
dpb
dpb 2024-11-27,18:47
关闭: dpb 2024-12-3,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 个评论
Stephen23
Stephen23 2024-11-27,22:07
Even if this only occurs when debugging it would still deserve a bug report.
dpb
dpb 2024-11-28,15:33
@Stephen23, thanks; I think so as well...

回答(2 个)

埃博拉酱
埃博拉酱 2024-11-28,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 个评论
dpb
dpb 2024-11-28,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 2024-11-28,17:44
编辑:dpb 2024-11-29,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.

此问题已关闭。

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by