Welcome, Guest
Username: Password: Remember me

TOPIC: export to csv / excel

export to csv / excel 03 Dec 2013 12:15 #11727

  • albert
  • albert's Avatar
  • Offline
  • Senior Member
  • Posts: 70
  • Thank you received: 2
  • Karma: 2
Hi, normally in my old components I used the file view.raw.php to export to csv
so i did a link like this one on the default.php:
<a href="index.php?option=com_component&view=viewname&format=raw" target="_blank"><img src="components/com_component/assets/spreadsheet.png" align="right" alt="CSV" title="Export to CSV"></a>

and then on the view.raw.php
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

// PEAR include for generating Excel files
require_once( 'Spreadsheet/Excel/Writer.php' );

class ComponentNameViewViewName extends View
{
	var $_name = null;
	
	function __construct()
	{
		parent::__construct();
		$this->_name = 'view_report';
	}
	
	function display($tpl = null)
	{	
		$user =& JFactory::getUser();

		// report rows
		$items = array();
		
		// create excel file		
		$workbook = new Spreadsheet_Excel_Writer();
		$workbook->send("reports_" . date("Ymd") . ".xls");

		$items =& $this->get('data'); 

		if (count($items)) {
			$worksheet =& $wor
.
.
.
		$workbook->close();
		die;
	}
}
?>

Now, by using your component in 3.2 i try to put the link and the raw file and doesn't connect, could you help me please ?
The administrator has disabled public write access.
The following user(s) said Thank You: admin

export to csv / excel 06 Dec 2013 16:57 #11754

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Thanks !! really usefull !!
K++;
Coding is now a piece of cake
The administrator has disabled public write access.

export to csv / excel 06 Dec 2013 19:37 #11760

  • albert
  • albert's Avatar
  • Offline
  • Senior Member
  • Posts: 70
  • Thank you received: 2
  • Karma: 2
It WAS useful,
Can you help me in the link part?
I do not know why it does not reach the raw view.
Thanks
The administrator has disabled public write access.
Time to create page: 0.060 seconds

Get Started