Welcome to PerlMonks!

It's customary when asking a question here to post the snippet of code with enough context to describe the problem.

In this case, it seems as though this is more a Windows problem, as when you try to overwrite a read-only file in Windows without using Perl, you'll get the same prompt.

EDIT: Thanks Athanasius for pointing out that chmod() doesn't do what I thought it did on Windows (although it did reset the ro bit on a shared drive I was testing on). I then tried with Win32::File::SetAttributes() to no avail. However, I did finally come across a way.

# unset the RO bit on a file system("attrib -r filename.csv"); #... do writing to file # change file back to RO system("attrib +r filename.csv");

I have serious doubts if that will have any effect if it's NTFS permissions preventing writing though...

If Win32::OLE doesn't have the capability to change a file from read-only, you can use the built-in chmod() function:

chmod 0777, $file; # do stuff that writes to file

The 0777 mask will make the file read, write and executable (r, w, x) by anyone who has access to the system. 0755 will make it r/w/x the owner (which might not be you), and only readable for everyone else.

-stevieb


In reply to Re: save read-only Excel by stevieb
in thread save read-only Excel by ShashankSC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.