FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Storing strings and numbers properly in CSV files
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Storing strings and numbers properly in CSV files [message #185623 is a reply to message #185620] Tue, 22 April 2014 19:07 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/22/2014 2:43 PM, sonnichjensen(at)gmail(dot)com wrote:
> Hi
>
> I am saving CSV files from a PHP app, but I face 2 problems:
> 1. stock numbers are sometimes just numbers, but I'd like to keep them as strings
> 2. prices are e.g. 5.2 which Excel translates as a date.
>
> Say:
>
> Item;Name;Price;Amount;Total
> 123;Test;5.2;1;5.2
> 124;Test2;1.2;2;2.4
> Total;;;;=sum(e2:e3)
>
> Just copy this into notepad and save with csv extension and you will see.
>
> I'd like to have 123 and 124 as strings, and eg 5.2 as a float.
> Can I format it better than this?
>
> WBR
> Sonnich
>

Unfortunately, while there are some guidelines on how .CSV files should
be written, there are few "hard and fast" rules. About the only ones
are that if a field contains the field and/or row separator character
(by default comma and newline, respectively), that field must be
enclosed in double quotes. Also, if a field contains double quotes,
("), the quotes must be doubled ("").

Because there are so few rules, the program that imports the file is
pretty much free to do what it wants with the file. You might try
enclosing the numbers you want as strings in quotes (i.e. "123"); I
don't know if this will work or not (I don't use Excel).

Other than that, you could try an Excel newsgroup or forum to see if
they have any suggestions on how to format your file so that Excel will
interpret it as you wish.

Wish I could be of more help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Mock HTTP servers for unit tests.
Next Topic: scandir problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 19 16:56:29 GMT 2024

Total time taken to generate the page: 0.03841 seconds