Dear all,
I need to add some text to my exported data in CSV. In order to do that, I found the following link:
http://fabrikar.com/forums/index.php?wiki/export-to-csv-customizing/
With this method I can do any needed customization and save the file in a .xlsx format.
My problem is that I can't see anything despite I followed right the instructions.
Here my code:
list_11_csv_export.php (saved in \plugins\fabrik_list\listcsv\scripts):
csv_export_mylist.php (saved in \plugins\fabrik_list\listcsv\scripts):
Since I'm testing the export custozimazion in my csv_export_mylist.php I will only test the transformation to .xlsx and after that the editing of a specific cell in every row.
Anyone have an idea about what is wrong?
Thanks in advance and kind regards
eulanaZ
I need to add some text to my exported data in CSV. In order to do that, I found the following link:
http://fabrikar.com/forums/index.php?wiki/export-to-csv-customizing/
With this method I can do any needed customization and save the file in a .xlsx format.
My problem is that I can't see anything despite I followed right the instructions.
Here my code:
list_11_csv_export.php (saved in \plugins\fabrik_list\listcsv\scripts):
PHP:
<?php $user = JFactory::getUser();
$incfile = JPATH_ROOT.'/plugins/fabrik_list/listcsv/scripts/csv_export_mylist.php';
$filename = 'mylist'.$user->id;
$filetype = 'mylist';
/* Check that 2nd include file exists */
if(file_exists(JPATH_ROOT.$incfile)){
require JPATH_ROOT.$incfile;
}
/* If JPATH_ROOT.$incfile does not exist, the normal download will proceed */
?>
csv_export_mylist.php (saved in \plugins\fabrik_list\listcsv\scripts):
PHP:
<?php
// Get upload temp path (containing the CSV export file)
// Needed when writing the saved file with a different filename
$config = JFactory::getConfig();
$tmp_path = $config->get( 'tmp_path' );
// Import PHPExcel library
jimport('phpexcel.library.PHPExcel');
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('CSV');
// Load the CSV export file into the phpExcel Reader
$objPHPExcel = $objReader->load($filePath);
// assign the active sheet to var $sheet
$sheet = $objPHPExcel->getActiveSheet();
/* Set Excel document properties
* This section is optional. The values can either be hard-coded
* or insert php code here to query tables and pass the retrieved
* values to these phpExcel functions.
*/
$objPHPExcel->getProperties()->setCreator("mylist")
->setLastModifiedBy($user->name." [".$user->username."]")
->setTitle("mylist Export")
->setSubject("mylist - Type:".$filetype)
->setDescription("mylist Export")
->setKeywords("mylist PHPExcel php")
->setCategory("Export");
// sheet title
// shown in navigation tab at bottom of workbook - limit 31 characters
$sheet->setTitle(substr($filetype,0,31));
// save row and column count to variables
$highestRowCount = $sheet->getHighestRow();
$highestColumnCount = $sheet->getHighestColumn();
/* Initialize the PHPExcel Writer */
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$fullFilename = $filename.'.xlsx';
$fullPathFile = $tmp_path.'/'.$fullFilename;
/* Write the formatted sheet to an Excel file */
$objWriter->save($fullPathFile);
/* disconnect worksheet and unload PHPExcel */
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
/* Delete original csv export file */
unlink($filePath);
/* flush output before reading file */
while(ob_get_level()) ob_end_clean();
flush();
/* readfile (and force the download) */
readfile($fullPathFile);
/* This is where you could include some php to also optionally save
* the file to a special user folder or 'store' for future use or purchase.
*/
/* delete file then kill the php process to prevent 'normal' csv file from being downloaded */
unlink($fullPathFile);
die;
?>
Since I'm testing the export custozimazion in my csv_export_mylist.php I will only test the transformation to .xlsx and after that the editing of a specific cell in every row.
Anyone have an idea about what is wrong?
Thanks in advance and kind regards
eulanaZ