>-----Original Message----- >From: John Delacour [mailto:johndelac...@gmail.com] >Sent: Thursday, January 06, 2011 11:33 >To: beginners@perl.org >Subject: RE: Getting LineFeed for Excel within q quoted field > >At 11:55 -0600 06/01/2011, David Waner wrote: > >> >From: John Delacour [mailto:johndelac...@gmail.com] >> >#!/usr/bin/perl >>>use strict; >>>my $csv="temp.csv"; >>>open CSV, ">$csv"; >> >print CSV qq~1,2,"3\n4\n5"\n6,7,8~; > > >>For something that should have been relatively easy, this has been a >>real pain in getting to work as I would have expected it to. >>...So to get things in what I believe was a correct setup and using >>the binmode which was giving me what I thought Excel wanted, I >>replaced my \n with \r\n and did the \x0a for the soft returns. Now >>when it is opened in Excel, there are no question marks in either of >>the two columns that I am doing soft returns.. > >You are still making a mountain out of a molehill. The first point >is that there is no such character as a 'soft return'. The term is >used loosely in wordprocessor-speak etc. to refer to an apparent new >line that is due to word wrapping. If you think you see returns in >this paragraph then you are mistaken. Make the window wider and, >unless you're using a very inadequate mailer, you will discover it is >one line without returns that stretches to fill the width of the >window. > >You day you used "\x0A" for your imaginary 'soft returns' when all >you're doing is respecting Excel's convention of using "\n" for the >in-cell hard return in a Windows document. Why not just use "\n", >which is precisely the same thing? > Ok, I did exactly as stated and only used \n for all the processing within my script for writing out the csv that I am after. Excel does NOT do the right thing in a text wrapped column with \n. What I now get is two question marks and no wrap at all. When you say there are no 'soft returns', I accept that, but when I use \x0a and open the column to the widest elemnt I have in that column, they all line up as I expect.
I may be making a mountain out of a molehill, but everything that I am seeing says, to get it correctly displayed in Excel, only the \x0a should be used in column which has double quotes around it. I even tried your simple script and with that, the question marks are part of the output. >I really don't know what 'binmode' has to do with anything either. >You're dealing in this case with plain text and you're working only >in Windows so all that's needed is to discover what rules Excel goes >by and respect them. > That is what I have been doing. Crlf is what I see in the text file for end of lines and lf is what I see for keeping my columns in a correctly setup display of data. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us >JD > > > >-- >To unsubscribe, e-mail: beginners-unsubscr...@perl.org >For additional commands, e-mail: beginners-h...@perl.org >http://learn.perl.org/ > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/