FileWrite CSV File opens in READ ONLY in Excel...why?

Started by mark_in_atx, January 26, 2016, 11:22:46 AM

Previous topic - Next topic

mark_in_atx

I have a program that uses ArrayFilePutCSV.  When I open the file in Excel all is fine.

Later the program writes a separate file using FileOpen(,,'WRITE') and later FileClose().  It is written and saved in a CSV format.  When I open it in Excel, however, it is labeled as "READ ONLY".  The file attributes do not mark it as read only, and I have made certain the file is not open somewhere else by a backup program, etc.  I have rebooted my computer, etc.

Why (or how?) is FileWrite making a CSV file read only in Excel, but ArrayFilePutCSV is not?  I need to have FileWrite not create a ReadOnly file.

To further debug, I have created a new program that writes a file using FileWrite to the same folder.  This file is fine - not read only.  However even if I delete the first file, etc., the original program still creates a CSV file that opens in Read Only in Excel.  FileAttrGet shows the file as ARCHIVE, Properties on the file via Windows Explorer does not show the file as read only, etc.  It makes no sense to me why Excel is showing this file as read only.

I can open the file in Notepad, make changes, and save with no problem, which implies that it is only Excel seeing the file this way (???)

mark_in_atx

Okay, WEIRD:

NOT READ ONLY:
a = FileOpen('c:\test\a.csv')
FileWrite(a, 'NWsymbol,abc')
FileClose(a)

READ ONLY:
a = FileOpen('c:\test\a.csv')
FileWrite(a, 'NEWsymbol,abc')
FileClose(a)

Upon further debugging, it appears that if the line written begins in "NE", not matter what follows it, it opens as read only.  Is Excel seeing this first line as some kind of read-only meta data?  I can make my own file outside of winbatch and simply have NE in the file.  Excel will open it as Read Only.  Obviously this is an Excel issue, not Winbatch.  But if anyone can help my out as to why I would greatly appreciate it!

Thanks!



td

An Excel file can certainly store information internally that indicates to an opening process that it is read only.   This is apparently done independently of any FAT32 and NTFS security settings.  I imagine the exact nature of the stored read only indicator may vary with the Excel version and save format of the Excel file.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Haven't tried it but you may be able to resolve your 'NE' problem by simply quoting the first field of the first record of your CSV file.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Maybe off-topic, but I know that with Excel 2013, files I have created are often opened with the 'enable editing' banner (essentially read only). I think it is part of security. 

mark_in_atx

Yes, easy work around by simply not having start of first line be NE...

I know (now) this post was off topic, thanks for the replies.  It definitely only occurs if start of text file begins with NE.  I can't find any reference anywhere online on how/why this would occur, but no worries.  Definitely NOT a Winbatch issue.

td

Did a quick search and found one oblique reference to something called the 'NE' problem on a discussion board topic about a CSV file with a first field containing an 'ID'.

https://social.msdn.microsoft.com/Forums/office/en-US/74689fdf-22cb-4493-9619-2a759cda38d4/excel-csv-readonly-problem?forum=exceldev
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade