forked from Wavyzz/dolibarr
Qual: Removed php_writexcel lib. Replaced with phpexcell.
Fix: Make script export-contaxts-xls-example.php working. Qual: removed not used code.
This commit is contained in:
@@ -20,13 +20,10 @@
|
||||
* \ingroup export
|
||||
* \brief File of class to generate export file with Excel format
|
||||
* \author Laurent Destailleur
|
||||
* \version $Id: export_excel.modules.php,v 1.28 2011/08/03 01:38:53 eldy Exp $
|
||||
* \version $Id: export_excel.modules.php,v 1.29 2011/08/11 19:13:04 eldy Exp $
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/includes/modules/export/modules_export.php");
|
||||
require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_workbookbig.inc.php");
|
||||
require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_worksheet.inc.php");
|
||||
require_once(PHP_WRITEEXCEL_PATH."/functions.writeexcel_utility.inc.php");
|
||||
|
||||
|
||||
/**
|
||||
@@ -47,11 +44,13 @@ class ExportExcel extends ModeleExports
|
||||
var $worksheet; // Handle onglet
|
||||
var $row;
|
||||
var $col;
|
||||
var $file; // To save filename
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructor
|
||||
* \param db databse handler
|
||||
* Constructor
|
||||
*
|
||||
* @param db databse handler
|
||||
*/
|
||||
function ExportExcel($db)
|
||||
{
|
||||
@@ -63,12 +62,12 @@ class ExportExcel extends ModeleExports
|
||||
$this->desc='<b>Excel</b> file format (.xls)<br>This is native Excel 95 format.';
|
||||
$this->extension='xls'; // Extension for generated file by this driver
|
||||
$this->picto='mime/xls'; // Picto
|
||||
$ver=explode(' ','$Revision: 1.28 $');
|
||||
$ver=explode(' ','$Revision: 1.29 $');
|
||||
$this->version=$ver[2]; // Driver version
|
||||
|
||||
// If driver use an external library, put its name here
|
||||
$this->label_lib='Php_WriteExcel';
|
||||
$this->version_lib='0.3.0';
|
||||
$this->label_lib='PhpExcel';
|
||||
$this->version_lib='1.7.2';
|
||||
|
||||
$this->row=0;
|
||||
}
|
||||
@@ -110,37 +109,62 @@ class ExportExcel extends ModeleExports
|
||||
|
||||
|
||||
/**
|
||||
* \brief Open output file
|
||||
* \param file Path of filename
|
||||
* \return int <0 if KO, >=0 if OK
|
||||
* Open output file
|
||||
*
|
||||
* @param file Path of filename
|
||||
* @return int <0 if KO, >=0 if OK
|
||||
*/
|
||||
function open_file($file,$outputlangs)
|
||||
{
|
||||
global $conf,$langs;
|
||||
global $user,$conf,$langs;
|
||||
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
}
|
||||
|
||||
dol_syslog("ExportExcel::open_file file=".$file);
|
||||
$this->file=$file;
|
||||
|
||||
$ret=1;
|
||||
|
||||
$outputlangs->load("exports");
|
||||
$this->workbook = new writeexcel_workbookbig($file);
|
||||
$this->workbook->set_tempdir($conf->export->dir_temp); // Set temporary directory
|
||||
$this->workbook->set_sheetname($outputlangs->trans("Sheet"));
|
||||
$this->worksheet = &$this->workbook->addworksheet();
|
||||
|
||||
// $this->worksheet->set_column(0, 50, 18);
|
||||
$outputlangs->load("exports");
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
require_once(PHP_WRITEEXCEL_PATH."class.writeexcel_workbookbig.inc.php");
|
||||
require_once(PHP_WRITEEXCEL_PATH."class.writeexcel_worksheet.inc.php");
|
||||
require_once(PHP_WRITEEXCEL_PATH."functions.writeexcel_utility.inc.php");
|
||||
$this->workbook = new writeexcel_workbookbig($file);
|
||||
$this->workbook->set_tempdir($conf->export->dir_temp); // Set temporary directory
|
||||
$this->workbook->set_sheetname($outputlangs->trans("Sheet"));
|
||||
$this->worksheet = &$this->workbook->addworksheet();
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once(PHPEXCEL_PATH."PHPExcel.php");
|
||||
require_once(PHPEXCEL_PATH."PHPExcel/Style/Alignment.php");
|
||||
$this->workbook = new PHPExcel();
|
||||
$this->workbook->getProperties()->setCreator($user->getFullName($outputlangs).' - Dolibarr '.DOL_VERSION);
|
||||
//$this->workbook->getProperties()->setLastModifiedBy('Dolibarr '.DOL_VERSION);
|
||||
$this->workbook->getProperties()->setTitle($outputlangs->trans("Export").' - '.$file);
|
||||
$this->workbook->getProperties()->setSubject($outputlangs->trans("Export").' - '.$file);
|
||||
$this->workbook->getProperties()->setDescription($outputlangs->trans("Export").' - '.$file);
|
||||
|
||||
$this->workbook->setActiveSheetIndex(0);
|
||||
$this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet"));
|
||||
$this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(15);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write header
|
||||
*
|
||||
* @param outputlangs Object lang to translate values
|
||||
*/
|
||||
function write_header($outputlangs)
|
||||
{
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
//$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -148,23 +172,30 @@ class ExportExcel extends ModeleExports
|
||||
|
||||
/**
|
||||
* Output title line into file
|
||||
*
|
||||
* @param array_export_fields_label Array with list of label of fields
|
||||
* @param array_selected_sorted Array with list of field to export
|
||||
* @param outputlangs Object lang to translate values
|
||||
*/
|
||||
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
|
||||
{
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
|
||||
// Create a format for the column headings
|
||||
$formatheader =$this->workbook->addformat();
|
||||
$formatheader->set_bold();
|
||||
$formatheader->set_color('blue');
|
||||
//$formatheader->set_size(12);
|
||||
//$formatheader->set_font("Courier New");
|
||||
//$formatheader->set_align('center');
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
|
||||
//$this->worksheet->insert_bitmap('A1', 'php.bmp', 16, 8);
|
||||
$formatheader =$this->workbook->addformat();
|
||||
$formatheader->set_bold();
|
||||
$formatheader->set_color('blue');
|
||||
//$formatheader->set_size(12);
|
||||
//$formatheader->set_font("Courier New");
|
||||
//$formatheader->set_align('center');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true);
|
||||
$this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
}
|
||||
|
||||
$this->col=0;
|
||||
foreach($array_selected_sorted as $code => $value)
|
||||
@@ -172,7 +203,14 @@ class ExportExcel extends ModeleExports
|
||||
$alias=$array_export_fields_label[$code];
|
||||
//print "dd".$alias;
|
||||
if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.');
|
||||
$this->worksheet->write($this->row, $this->col, $outputlangs->transnoentities($alias), $formatheader);
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$this->worksheet->write($this->row, $this->col, $outputlangs->transnoentities($alias), $formatheader);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $outputlangs->transnoentities($alias));
|
||||
}
|
||||
$this->col++;
|
||||
}
|
||||
$this->row++;
|
||||
@@ -181,24 +219,22 @@ class ExportExcel extends ModeleExports
|
||||
|
||||
/**
|
||||
* Output record line into file
|
||||
*
|
||||
* @param array_selected_sorted Array with list of field to export
|
||||
* @param objp A record from a fetch with all fields from select
|
||||
* @param outputlangs Object lang to translate values
|
||||
*/
|
||||
function write_record($array_selected_sorted,$objp,$outputlangs)
|
||||
{
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
|
||||
$formatdate=$this->workbook->addformat();
|
||||
$formatdate->set_num_format('yyyy-mm-dd');
|
||||
//$formatdate->set_num_format(0x0f);
|
||||
|
||||
$formatdatehour=$this->workbook->addformat();
|
||||
$formatdatehour->set_num_format('yyyy-mm-dd hh:mm:ss');
|
||||
//$formatdatehour->set_num_format(0x0f);
|
||||
|
||||
// Create a format for the column headings
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO
|
||||
}
|
||||
|
||||
// Define first row
|
||||
$this->col=0;
|
||||
|
||||
foreach($array_selected_sorted as $code => $value)
|
||||
{
|
||||
$alias=str_replace(array('.','-'),'_',$code);
|
||||
@@ -219,21 +255,54 @@ class ExportExcel extends ModeleExports
|
||||
|
||||
if (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i',$newvalue))
|
||||
{
|
||||
$arrayvalue=preg_split('/[.,]/',xl_parse_date($newvalue));
|
||||
//print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
|
||||
$newvalue=strval($arrayvalue[0]).'.'.strval($arrayvalue[1]); // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
|
||||
$this->worksheet->write($this->row, $this->col, $newvalue, $formatdate);
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$formatdate=$this->workbook->addformat();
|
||||
$formatdate->set_num_format('yyyy-mm-dd');
|
||||
//$formatdate->set_num_format(0x0f);
|
||||
$arrayvalue=preg_split('/[.,]/',xl_parse_date($newvalue));
|
||||
//print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
|
||||
$newvalue=strval($arrayvalue[0]).'.'.strval($arrayvalue[1]); // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
|
||||
$this->worksheet->write($this->row, $this->col, $newvalue, PHPExcel_Shared_Date::PHPToExcel($formatdate));
|
||||
}
|
||||
else
|
||||
{
|
||||
$newvalue=dol_stringtotime($newvalue);
|
||||
$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, PHPExcel_Shared_Date::PHPToExcel($newvalue));
|
||||
$coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate();
|
||||
$this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd');
|
||||
}
|
||||
}
|
||||
elseif (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/i',$newvalue))
|
||||
{
|
||||
$arrayvalue=preg_split('/[.,]/',xl_parse_date($newvalue));
|
||||
//print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
|
||||
$newvalue=strval($arrayvalue[0]).'.'.strval($arrayvalue[1]); // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
|
||||
$this->worksheet->write($this->row, $this->col, $newvalue, $formatdatehour);
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$formatdatehour=$this->workbook->addformat();
|
||||
$formatdatehour->set_num_format('yyyy-mm-dd hh:mm:ss');
|
||||
//$formatdatehour->set_num_format(0x0f);
|
||||
$arrayvalue=preg_split('/[.,]/',xl_parse_date($newvalue));
|
||||
//print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
|
||||
$newvalue=strval($arrayvalue[0]).'.'.strval($arrayvalue[1]); // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
|
||||
$this->worksheet->write($this->row, $this->col, $newvalue, $formatdatehour);
|
||||
}
|
||||
else
|
||||
{
|
||||
$newvalue=dol_stringtotime($newvalue);
|
||||
$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, PHPExcel_Shared_Date::PHPToExcel($newvalue));
|
||||
$coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate();
|
||||
$this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd h:mm:ss');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->worksheet->write($this->row, $this->col, $newvalue);
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$this->worksheet->write($this->row, $this->col, $newvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $newvalue);
|
||||
}
|
||||
}
|
||||
$this->col++;
|
||||
}
|
||||
@@ -242,21 +311,41 @@ class ExportExcel extends ModeleExports
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write footer
|
||||
*
|
||||
* @param outputlangs Object lang to translate values
|
||||
*/
|
||||
function write_footer($outputlangs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close Excel file
|
||||
*/
|
||||
function close_file()
|
||||
{
|
||||
$this->workbook->close();
|
||||
if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL))
|
||||
{
|
||||
$this->workbook->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once(PHPEXCEL_PATH."PHPExcel/Writer/Excel5.php");
|
||||
$objWriter = new PHPExcel_Writer_Excel5($this->workbook);
|
||||
$objWriter->save($this->file);
|
||||
$this->workbook->disconnectWorksheets();
|
||||
unset($this->workbook);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean a cell to respect rules of Excel file cells
|
||||
*
|
||||
* @param newvalue String to clean
|
||||
* @return string Value cleaned
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user