tags:

views:

227

answers:

2

I have been trying to import this excel file my mysql database, and it has been rough. There are around 7,000 rows in the .xls file, but when I export it to .csv and parse it with PHP I get one of two issues:

  • Excel does not escape anything, ie. the commas in each row split the data
  • When I change all commas to * then export for some reason excel changes a whole bunch of lines to a bunch of pound signs #####.

(Is there a reason it does this?)

I can upload the .xls somewhere if need be.

A: 

As a suggestion, if you are dealing with cells that do contain commas which are widespread, an easy solution would be to export from Excel in a Tab-Delimited format (TXT), or yet alone any format that contains a character you would not normally encounter.

I've found it to be a pretty simple way to take care of many of the troubles associated with exporting from Excel and importing into a database medium.

George
There's nothing wrong with CSV, and PHP (and MySQL, too) parses CSV with built-in functions.
ceejayoz
I never said there was anything wrong with CSV -- do you see where I said something was wrong with CSV?
George
I am aware of these options, but csv just makes things more simple (and php has everything built in for it).
Tom
A delimiter is a delimiter.
George
A: 

Figured it out!

Turns out it was Excel's fault. I checked the .xls before opening it in Excel, not ###. But after saving it in Excel they appeared.

So I opened it in Numbers (part of iWork), changed all , to *, and all quotes to % (these never appeared in any line. Exported it to .csv, then changed them back when importing with PHP.

Worked great. :-)

Tom