A place to log my programming solutions.
14
Aug 09

Solution to Excel’s CSV Output Formats

Recently I’ve had to import a client’s catalog data from Excel 2007 to the Magento eCommerce Platform. The data in Excel was unsurprisingly in a format that was unsupported by Magento’s import methods. Using code, I needed to parse Excel data into the format Magento required. In PHP, I wasn’t aware of any way to interface with .xls or .xlsx files, so I tried exporting the data to flat-file CSV, where it could be easily manipulated using PHP’s native CSV functions.

Unfortunately, none of the three CSV formats that Excel outputs could be properly parsed as CSV. For example, accepted CSV standards state that values should be:

"value1","value2","escaped "" double quote", "value 3", "", "", "7th column"

But in Excel’s version of CSV, that would look like:

value1,value2,"escaped "" double quote",value 3,,,7th column

It’s terribly inconsistent in its use of double quotes, confusing the hell out of many CSV parsers.

The Solution:

CSV to XML Converter by Creativyst(R). It takes in CSV garbage and returns immaculate and clean XML. Then use your language-of-choice’s XML functions to work with the data.

  • StumbleUpon
  • Digg

Leave a Response

About NVNCBL and Myself

Contact Me