+ Reply to Thread
Results 1 to 6 of 6

 

Thread: Excel to XML converter

  1. #1
    more focused this year...

    Status
    Offline
    Join Date
    Nov 2005
    Location
    India
    Posts
    640
    Thanks
    42
    Thanked 15 Times in 15 Posts


    Hiya,

    I am looking for the script or a program that i can run on local to convert the excel spreadsheet to xml sheet. Tried googling too but couldn't find the right one available. There are few offering the demo version too but that generates the xml sheet with the "Please buy licence" code.

    Does anyone here got a script or program for the same?

    P.S - I am looking for the "FREE" script as of now

    Thanks,
    Mike...
    "Falling down is not Defeat....Defeat is when you refuse to get up."

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Nov 2003
    Location
    London
    Posts
    680
    Thanks
    3
    Thanked 19 Times in 19 Posts
    The free script

    1/ convert excel to csv format

    2/ use php (or other) script to parse the csv file to xml format

    If it is a big set of data, the quicker option is to parse to an sql database.

  3. #3
    more focused this year...

    Status
    Offline
    Join Date
    Nov 2005
    Location
    India
    Posts
    640
    Thanks
    42
    Thanked 15 Times in 15 Posts
    Thanks for the pointers moredial, just wanted to ask if you or someone else here have the php script to parse the same ? I have found another way using the XML parsing through the MS excel 2003 but thats a real lengthly and manual process. Anyone care to share..

    Thanks again.
    "Falling down is not Defeat....Defeat is when you refuse to get up."

  4. #4
    Registered User

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Gillingham
    Posts
    510
    Thanks
    0
    Thanked 4 Times in 1 Post
    If you have a csv file with headings in the first line try this:

    PHP Code:
    <?php
    header
    ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    header('Content-type: text/xml');
    $global_tag="product_list";
    $outer_tag="product";
    $tags=array();
    $xml="<?xml version=\"1.0\" ?>\r\n";
    $xml.="<".$global_tag.">";
    $fp=fopen("filename.csv","r");
    $data fgetcsv ($fp,8192);
    $tags=$data;
    while (
    $data=fgetcsv ($fp,8192)){
    $xml.="<".$outer_tag.">";
    foreach (
    $tags as $key=>$value){
    $xml.="<".$value.">";
    $xml.="<![CDATA[".$data[$key]."]]>";
    $xml.="</".$value.">\r\n";
    }
    $xml.="</".$outer_tag.">\r\n";
    }
    $xml.="</".$global_tag.">";
    echo 
    $xml;
    ?>
    If you don't have the headings in the first row change $tags=array() to $tags=array("col1","col2"); and leave out the first fgetcsv.

    If your data is well formed for xml you don't need to have the cdata round the data. Change the line to $xml.=$data[$key]; and don't forget to change filename.csv to your own file name.

    Regards Bob
    They came for my 404 and I said nothing

  5. #5
    more focused this year...

    Status
    Offline
    Join Date
    Nov 2005
    Location
    India
    Posts
    640
    Thanks
    42
    Thanked 15 Times in 15 Posts
    Thanks for the script mate.. Will surely give it a try.

    Thanks again,

    Quote Originally Posted by Donk View Post
    If you have a csv file with headings in the first line try this:

    PHP Code:
    <?php
    header
    ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    header('Content-type: text/xml');
    $global_tag="product_list";
    $outer_tag="product";
    $tags=array();
    $xml="<?xml version=\"1.0\" ?>\r\n";
    $xml.="<".$global_tag.">";
    $fp=fopen("filename.csv","r");
    $data fgetcsv ($fp,8192);
    $tags=$data;
    while (
    $data=fgetcsv ($fp,8192)){
    $xml.="<".$outer_tag.">";
    foreach (
    $tags as $key=>$value){
    $xml.="<".$value.">";
    $xml.="<![CDATA[".$data[$key]."]]>";
    $xml.="</".$value.">\r\n";
    }
    $xml.="</".$outer_tag.">\r\n";
    }
    $xml.="</".$global_tag.">";
    echo 
    $xml;
    ?>
    If you don't have the headings in the first row change $tags=array() to $tags=array("col1","col2"); and leave out the first fgetcsv.

    If your data is well formed for xml you don't need to have the cdata round the data. Change the line to $xml.=$data[$key]; and don't forget to change filename.csv to your own file name.

    Regards Bob
    "Falling down is not Defeat....Defeat is when you refuse to get up."

  6. #6
    Registered User

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Gillingham
    Posts
    510
    Thanks
    0
    Thanked 4 Times in 1 Post
    As an afterthought.

    If you want stick to excel:
    Insert a column in front of the data and also insert a new column after each of your current columns.

    Delete the heading row
    insert 2 rows at the top
    cell A1 enter <?xml version="1.0" ?>
    in cell A2 enter <product_list>
    in A3 enter<product> and the start tag for the first column of you data. eg <product_id>
    in C3 close the first tag and open the next eg </product_Id><product_name>
    continue this in E3 G3 etc

    After your last column you will need to close the preceding column tag and also the product tag eg </last_data></product>

    Copy and paste these cell into every row
    and finally after the final row close the </product_list> tag.

    Save this as a text file and rename it with an xml extension.
    They came for my 404 and I said nothing

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. bit of a pickle, php xml parser
    By morleymouse in forum Programming
    Replies: 5
    Last Post: 20-01-06, 02:52 PM
  2. Excel Airways XML feed down
    By drivetowin in forum DGM Affiliates
    Replies: 2
    Last Post: 15-08-05, 11:31 AM
  3. Excel Airways Doubles Commission
    By rich2nd in forum DGM Affiliates
    Replies: 0
    Last Post: 06-10-04, 04:35 PM
  4. Anyone anygood with xml, php, mysql and Affiliate Window
    By AnnonnyMouse in forum Affiliate Marketing Lounge
    Replies: 1
    Last Post: 23-09-04, 12:00 PM
  5. datafeed help? xml - csv (excel)
    By plesecontact in forum Affiliate Marketing Lounge
    Replies: 0
    Last Post: 03-02-04, 10:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2