[development] Import data from excel into drupal

Neil Hastings neil.hastings at gmail.com
Thu Jul 30 17:27:21 UTC 2009


That's easier then what I did.  Using
http://code.google.com/p/parsecsv-for-php/

Example code:
function opcerts_import_person() {
  //add person
  $csv = new parseCSV;
  $csv->auto('/var/www/import.csv');

  foreach ($csv->data as $key => $row) {
    //get the nid if the person already exists
    $nid = opcerts_person_check_emp_id($row['emp_id']);
    if (!$nid) {
      $person = new stdClass;

      //add person
      $person->uid = 1;
      $person->type = 'person';
      $person->field_last_name[0]['value'] = $row['l_name'];
      $person->field_first_name[0]['value'] = $row['f_name'];
      $person->field_emp_id[0]['value'] = $row['emp_id'];
      $person->field_position[0]['value'] = $row['title_tid'];
      $person->field_unit[0]['value'] = $row['unit_tid'];
      $person->field_middle[0]['value'] = $row['m_name'];
      $person->field_other_name[0]['value'] = $row['o_name'];
    }
    else {
      //add the unit to the person
      $person = node_load($nid);
      array_unshift($person->field_unit, array('value' =>
$row['unit_tid']));
    }
    node_object_prepare($person);
    node_save($person);
    unset($person);
  }
}

Cheers,
Neil
http://code-dreamers.com

On Thu, Jul 30, 2009 at 1:19 PM, Kyle Mathews <mathews.kyle at gmail.com>wrote:

> Feedapi + parser_csv + feed element mapper + cck
>
> http://drupal.org/project/feedapi
> http://drupal.org/project/parser_csv
> http://drupal.org/project/feedapi_mapper
>
> Kyle
>
> Research Assistant
> Entrepreneurship and Technology Center @ BYU
> kyle.mathews2000.com/blog
>
>
> 2009/7/30 Gastón Pablo Pérez <gpperez at gmail.com>
>
> Hi!
>>
>> I would like implement a functionality in a web site for able to upload an
>> excel file, with a determined format, and then, I want to generate nodes
>> with this information.
>> Exists a module or a medium to do that? or how can i insert data into
>> drupal database from an excel file?
>>
>> thanks a lot
>>
>> --
>> "La perseverancia es un árbol de raíces amargas, pero de frutos muy
>> dulces."
>>
>> Gastón Pablo Perez
>> Email:gpperez at gmail.com <Email%3Agpperez at gmail.com>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.drupal.org/pipermail/development/attachments/20090730/875a1e53/attachment-0001.htm>


More information about the development mailing list