Extracting contents from excel in Drupal
I want to extract the contents of a excel file and populate them in a new post( page) . I'd like to maintain the row-column relationship.
Ex:
sample.xls
Name | Age | Sex
A | 20 | M
B | 30 | F
C | 40 | M
In Drupal (the one which i want)
Name | Age | Sex
A | 20 | M
B | 30 | F
C | 40 | M
Is there any module in Drupal to do that or should I create a 开发者_运维问答new one for it? I wish some drupaler came across this situation :)
There's no module for what you want to do based on your comment below the question that I'm aware of. Unfortunately when you export an Excel spreadsheet to HTML Excel will attach all kinds of formatting to the result and you probably don't want that. One trick would be to save the spreadsheet as a .csv file (comma-separated values) and then use a utility to convert the CSV file into an HTML table that you can paste into your node content. I haven't used any of the utilities in this set of Google search results but there's no shortage of ones you can try, anyway.
Try the FeedAPI module, it is able to parse CSV files, and you can assign data to specific fields, should do exactly what you need.
I think this old discussion contains the resource you need.
I'm sure there's a better way to use this library, but in a pinch I downloaded http://code.google.com/p/php-excel-reader
and then used the php filter in a regular drupal node and wrote
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'path/to/excel/library/excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("path/to/uploaded/spreadsheet/myexcelsheet.xls");
echo $data->dump($row_numbers=false,$col_letters=false,$sheet=0,$table_class='excel');
?>
There are other options at http://code.google.com/p/php-excel-reader/wiki/Documentation
I'm using Importer for uploads... The Importer module provides this tip:
*To enable the support for .xls files download the "excel_reader2.inc" file from here and place in the module directory.*
The "here" in the above points to: http://code.google.com/p/php-excel-reader/
Rename the file from excel_reader2.php to excel_reader2.inc and drag it into the modules/importer folder. That's it.. it'll let you upload xls files directly and convert them to cvs for you. The rest of the formula is just CSS or whatever you're using to display it like you require.
精彩评论