Page 1 of 1

Exclusive lock on excel file

Posted: Wed Jul 24, 2019 10:17 am
by d3nton
Hi!

Is there a way (option or property or s.th.) to exclusively lock an excel file when beginning to read the file via TXLSReadWriteII5.Read until it is written again?
I currently run into a problem where two program instances try to write into the same excel file. First both instances have read the file (into memory) and did some modifications
but then override each other when writing into the same file. Is there a way to lock the excel file before the first instance starts reading until it has written its modifications into the file?

best regards

Re: Exclusive lock on excel file

Posted: Wed Aug 07, 2019 11:28 am
by larsa
Hello

You have to modify the source for this. Open file XLSReadWriteII5 and go to line #827 (Stream := TFileStream.Create(FManager.Filename,fmOpenRead or fmShareDenyNone);)
Change the share options to what you want.

Re: Exclusive lock on excel file

Posted: Mon Aug 10, 2020 10:41 am
by d3nton
Hi again.

I came across this problem again. The described approach does not work because 'Stream' is a local variable that is released at the end of the function. I would need a way to lock the file from the outside, so that it is only released after the file has been written. Is that possible?