I have the excel document. First row is the field (tag) name. The rows after are the data.

I would like to transfer it to xml.

1) Is there a way using built in Microsoft Excel tools to convert the excel to xml? (I haven't used Microsoft Office for a while now. And usually I didn't like the xml/html/sql script etc. Microsoft auto created before. Too many microsoft tags, but is the new version of the office doing better now?)

2) How about Open Office, is there a built in tool to convert Excel to xml in Open Office that is good?)

3) Third approach, I can use php script to transfer excel to xml. Any good resources (scripts, urls, sampls etc.) you could recommend?

Thanks!

    I don't know off-hand how the various spreadsheet programs convert to XML, but if you save the file as CSV, it should be pretty easy to convert to XML with PHP. You could use the SimpleXML or DOM extensions, or for that matter just output it yourself:

    <?php
    $file = "test.csv";
    $fh = fopen($file, 'r') or die("fopen error");
    header('Content-Type: text/xml');
    echo "<?xml version='1.0' encoding='utf-8'?>\n";
    echo "<data>\n";
    $cols = fgetcsv($fh);
    while(($row = fgetcsv($fh)) != false)
    {
       echo "<row>\n";
       foreach($cols as $col)
       {
          echo "<$col><![CDATA[".current($row)."]]></$col>\n";
          if(next($row) === false)
          {
             break;
          }
       }
       echo "</row>\n";
    }
    echo "</data>";
    

      Thanks, Nogdog. I used the same approach.

      1) save the excel as csv.
      2) use texpad to save the csv as utf8 csv.
      3) covert csv to the array of associative array (use the first row of the csv, field or tag name, as the key)
      4) covert array of associative array to xml.

        Write a Reply...