Hi,
Is is possible to access some of the other PHPExcel functions/attributes with this module?
For example, how do you call setLoadSheetsOnly($sheetnames)?
or
getTitle() to get worksheet titles?
or
getHighestColumn()?
Is there a way to access these functions using the module API?
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | COBie-UK-2012-example1.xls | 65 bytes | gmak |
| #6 | Screenshot_31_05_2013_22_43.png | 89.42 KB | gmak |
Comments
Comment #1
wadmiraal commentedHi,
The module hooks provide access to pretty much all the export/import functionality you need. It depends at what stage of the export/import you "hook" in.
You can find more info on the hooks here: https://drupal.org/node/1415076
Let me know if you need more help.
Comment #2
gmak commentedwadmiraal,
could you give me an example of how to access the sheetname on an import?
I am trying to import an excel file with multiple worksheets (each with unique columns). What I'd like to be able to do is step through the worksheets, and create a node for each of the rows in a sheet where each worksheet writing to a different node type. (hope that makes sense)
Ideally, I'd like to be able to grab the column name (from the header row) and cell value for each row.
Many thanks
Comment #3
wadmiraal commentedIf you import a file, the worksheet names will be the first keys on the data array. The data array has three levels:
Worksheet (string key)
Row (numerical key)
Column (string key if $keyed_by_header parameter is TRUE)
Isn't that what you want ?
Comment #4
wadmiraal commentedOh no, wait. That's not the case... But it soon will be ;-). Wait a few minutes.
Comment #5
wadmiraal commentedIt's on 3.6.
Comment #6
gmak commentedI must be missing something...
I've got the following:
This is clearly loading my test file (see attached), which has 20+ worksheets.
Shouldn't my
dpm($val[0]);be spitting out the names of the worksheets, if they are the first keys in the data array?Also, if I simply call
dpm($result)I don't see worksheet names appearing at all. What I get is a series of arrays that are all numbered, but no names (see screenshot).Do I need something more to get the names to be returned in the data array?
Thanks,
Comment #7
wadmiraal commentedSorry, should have mentioned I also updated the documntation.
phpexcel_import takes 3 params (now). The first is the file path. The second is optional and defaults to true. It keys the cell values with the column header. The third defaults to false (as not to break existing sites). If you set the third one to true, it will key by worksheet name, which is what you want.
Comment #8
gmak commentedThis is great! I've managed to get pretty much what I need. Two more questions:
1. What is the second parameter (that defaults to TRUE)?
2. Is is possible to access the
PHPExcel_IOFactory::identify()function in the module API? I note that the PHPExcel library carries this function which allows you to get the file type from the file and set the Reader appropriately. It would be good to be able to access this so that you can allow users to upload different filetypes (xls, xlsx, csv, etc).Many, many thanks!
Comment #9
wadmiraal commentedThe second parameter (if TRUE) makes the import ignore the first row (the "header") and uses these cell values as keys for corresponding cells in the next rows.
So if you have a CSV like:
With the second parameter TRUE, it will be imported like this:
If the second parameter is FALSE, it will look like this:
As for the
PHPExcel_IOFactory, it is already used internally for importing files. So you can import all files that PHPExcel supports (xls, xlsx, csv, xml, etc).Comment #10
gmak commentedwadmiral,
First, I want to thank you for your help with my questions. I'm learning a great deal about both PHPExcel and Drupal.
Second, I'm still trying to understand how to access some of the functions of PHPExcel through the module.
In PHPExcel, it is possible to load specific worksheets via something like:
I'm afraid I don't understand the hook system for the module that would allow me to pass an array of Worksheet Names to the
phpexcel_import()function.Is this possible? Could you provide a quick example of how to access some of these type of functions?
I think if you can give me a basic example, then I can probably figure out the rest (he says, with some possibly false optimism).
Many thanks
Comment #12
wadmiraal commentedFor future reference: #10 was answered here: #2024309: Importing a specific worksheet.
Comment #13
jincy_k commentedHi,
I am using this module to import data and create nodes. I could not read headers from an .xlsx file with leading space in the value.
I tried to trim space using php trim function,but no luck.
The second issue I got now is with reading data from another .xlsx file which is also having the same format as the previous one used for importing (some headers and corresponding column values). The data could not be read like this
array(
'Sheet name' => array(
array(
'Header 1' => 'Col 1',
'Header 2' => 'Col 2',
'Header 3' => 'Col 3',
)
)
);
I wanted the result as a key-value pair array (column header as keys and cell values as values).
Actually it was reading in my desired way (as a key value pair) when I exported one .xlsx file.
When I tried testing with another file with same format using same code, result is not in the expected way.
I used the function
phpexcel_import($path);
and tried by giving the other parameters also
phpexcel_import($path,TRUE,TRUE);
phpexcel_import($path,TRUE,FALSE);
Please help me to fix both these issues. I am using Drupal 7.59
Regards
Jincy
Comment #14
jincy_k commentedPlease give me a solution for this issue.