Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Excel-Writer-XLSX : Excel file with warning messages

by rajan (Acolyte)
on Oct 07, 2019 at 08:50 UTC ( [id://11107121]=perlquestion: print w/replies, xml ) Need Help??

rajan has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks: (1) I am creating a excel file and save it in a location. (2) I am sending an email with a link that points to this location. (3) While clicking the link - the file gets downloaded. (4) While opening the file - the excel file opens up with the warning message as "we found a problem with some content in do you want to recover as much as we can. If you trust the source of this workbook then click yes" (5) If we click "Yes" - the file is intact and the data is not lost at all. Question: How to suppress this warning message. Every time it forces the user to choose this option. Alternatively if I attach the file directly to the email - this warning message does not appear. It appears only when it is downloaded through a link.

Replies are listed 'Best First'.
Re: Excel-Writer-XLSX : Excel file with warning messages
by marto (Cardinal) on Oct 07, 2019 at 09:05 UTC

    If you can email the file and it opens without this warning then the file at that point is sound. Perhaps the code you're using to present this via a URL/link is causing an issue, or it could be totally unrelated to perl. How do I post a question effectively?, provide a short example which can replicate the problem.

      Thanks for your patience. I have resolved the issue and pasted under user "swl" comment.

Re: Excel-Writer-XLSX : Excel file with warning messages
by swl (Parson) on Oct 07, 2019 at 21:54 UTC

      Here is some code to get to the same error message.

      Run the code to the point it pauses, then try to open the perl.xlsx file using Excel.

      It uses an undocumented internal method, so hopefully is not what is actually being done. I tried a few variants of deferred close etc. but without success as all files were zero sized until the close method is called (or objects destroyed). Perhaps there is a point where Excel::Writer::XLSX reaches a memory or size threshold and writes the data to file, and this is being hit by the OP.

      # adapted from the Excel::Writer::XLSX synopsis use 5.010; use warnings; use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX->new( 'perl.xlsx' ); # Add a worksheet $worksheet = $workbook->add_worksheet(); # some data for my $row (0..5) { for my $col (0..2) { $worksheet->write( $row, $col, $row ); } } # internal method used in ->close() $workbook->_store_workbook(); $workbook->close(); { # defer garbage collection to test file local $| = 1; say 'Pausing, press any key to continue'; my $pause = <>; }

        Dear Friends: Thanks for taking patience in answering the question. I have the issue resolved like this but I am not sure how it works. Here is the code

        my $subject="Monthly Report"; my $file_link="\n Dear Customer: Please click on the link below to dow +nload the Monthly Report for the month of 2019-05. <br><br> <a href=\ +"https://$hostname/ui_report/download_report?file=$fileloc\">Download + Report</a></center> \n\n"; # $fileloc contains the path of the store +d file in our server. &SendEmail($from,$toAddress,$cc,$bcc,$subject,'text/html',$file_link,$ +from); # This module sends an email with link - by clicking will down +load the excel report. In the "download_report" script: if ($file =~ /\.xlsx$/) { print "Content-type: application/vnd.openxmlformats-officedocument.spr +eadsheetml.sheet\n"; # The Content-Disposition will generate a prompt to save the file. print "Content-Disposition: attachment; filename=$file\n"; print "\n"; &download ($fileloc); exit 0; # NEWLY ADDED DUE TO ISSUE IN EXCEL REPORT OPENING } print "Content-Type: text/html\r\n\r\n"; my $cgi = new CGI; print $cgi->redirect("tent"); print "The redirect seems to have failed."; die;

        By simply adding "exit 0; " statement I am able to download and view the report without any warnings. I believe previously after the execution of if block, it continued the execution and it might have created the problem. Please let me know if my explanation is not sufficient.

        Above

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11107121]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found