[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [10129] property: excel related changes
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [10129] property: excel related changes |
Date: |
Sun, 07 Oct 2012 21:56:31 +0000 |
Revision: 10129
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10129
Author: sigurdne
Date: 2012-10-07 21:56:30 +0000 (Sun, 07 Oct 2012)
Log Message:
-----------
property: excel related changes
Modified Paths:
--------------
trunk/property/inc/class.bocommon.inc.php
trunk/property/inc/class.import.inc.php
trunk/property/inc/class.uiimport.inc.php
trunk/property/inc/class.uis_agreement.inc.php
trunk/property/inc/cron/default/import_files.php
Modified: trunk/property/inc/class.bocommon.inc.php
===================================================================
--- trunk/property/inc/class.bocommon.inc.php 2012-10-07 17:08:00 UTC (rev
10128)
+++ trunk/property/inc/class.bocommon.inc.php 2012-10-07 21:56:30 UTC (rev
10129)
@@ -1591,6 +1591,85 @@
* @param array $descr array containing Names for the heading
of the output for the coresponding keys in $list
* @param array $input_type array containing information
whether fields are to be suppressed from the output
*/
+ function excel_out_ny($list,$name,$descr,$input_type=array())
+ {
+ phpgw::import_class('phpgwapi.phpexcel');
+
+
+ $filename= str_replace('
','_',$GLOBALS['phpgw_info']['user']['account_lid']).'.xls';
+
+ $browser = CreateObject('phpgwapi.browser');
+
$browser->content_header($filename,'application/vnd.ms-excel');
+
+ $cacheMethod = PHPExcel_CachedObjectStorageFactory::
cache_to_phpTemp;
+ $cacheSettings = array( 'memoryCacheSize' => '8MB');
+ PHPExcel_Settings::setCacheStorageMethod($cacheMethod,
$cacheSettings);
+
+ $objPHPExcel = new PHPExcel();
+
+
$objPHPExcel->getProperties()->setCreator($GLOBALS['phpgw_info']['user']['fullname'])
+
->setLastModifiedBy($GLOBALS['phpgw_info']['user']['fullname'])
+ ->setTitle("Download
from {$GLOBALS['phpgw_info']['server']['system_name']}")
+ ->setSubject("Office
2007 XLSX Document")
+
->setDescription("document for Office 2007 XLSX, generated using PHP classes.")
+ ->setKeywords("office
2007 openxml php")
+
->setCategory("downloaded file");
+
+ $count_uicols_name=count($name);
+
+ $m=0;
+ for ($k=0;$k<$count_uicols_name;$k++)
+ {
+ if(!isset($input_type[$k]) ||
$input_type[$k]!='hidden')
+ {
+
+ $objPHPExcel->setActiveSheetIndex(0)
+ ->setCellValueByColumnAndRow($m, 1, $descr[$k]);
+ $m++;
+ }
+ }
+
+ $j=0;
+ if (isset($list) && is_array($list))
+ {
+ foreach($list as $entry)
+ {
+ $m=0;
+ for ($k=0;$k<$count_uicols_name;$k++)
+ {
+ if(!isset($input_type[$k]) ||
$input_type[$k]!='hidden')
+ {
+ $content[$j][$m]
= str_replace("\r\n"," ",$entry[$name[$k]]);
+ $m++;
+ }
+ }
+ $j++;
+ }
+
+ $line = 1;
+
+ foreach($content as $row)
+ {
+ $line++;
+ $rows = count($row);
+ for ($i=0; $i < $rows; $i++)
+ {
+
$objPHPExcel->setActiveSheetIndex(0)
+ ->setCellValueByColumnAndRow($i, $line,
$row[$i]);
+ }
+ }
+ }
+
+ // Set active sheet index to the first sheet, so Excel
opens this as the first sheet
+ $objPHPExcel->setActiveSheetIndex(0);
+
+ // Save Excel 2007 file
+ $objWriter =
PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+// $objWriter =
PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
+ $objWriter->save('php://output');
+
+ }
+
function excel_out($list,$name,$descr,$input_type=array())
{
$filename= str_replace('
','_',$GLOBALS['phpgw_info']['user']['account_lid']).'.xls';
Modified: trunk/property/inc/class.import.inc.php
===================================================================
--- trunk/property/inc/class.import.inc.php 2012-10-07 17:08:00 UTC (rev
10128)
+++ trunk/property/inc/class.import.inc.php 2012-10-07 21:56:30 UTC (rev
10129)
@@ -108,6 +108,7 @@
return $importfile;
}
+
function prepare_data($importfile = '', $list='',$uicols='')
{
$fields = array();
@@ -128,34 +129,26 @@
$this->uicols2 = $uicols2;
- $data = CreateObject('phpgwapi.excelreader');
+ phpgw::import_class('phpgwapi.phpexcel');
- $data->setOutputEncoding('CP1251');
- $data->read($importfile);
+ $objPHPExcel = PHPExcel_IOFactory::load($importfile);
+ $sheetData =
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
foreach($fields as &$entry)
{
- $entry['id'] = array_search($entry['descr'],
$data->sheets[0]['cells'][1]);
+ $entry['id'] = array_search($entry['descr'],
$sheetData[1]);
}
$valueset = array();
- $rows = $data->sheets[0]['numRows']+1;
+ $rows = count($sheetData) +1;
for ($i=2; $i<$rows; $i++ ) //First data entry on row 2
{
- if ($data->sheets[0]['cells'][$i][2] != '')
+ foreach ($fields as $entry)
{
-
- foreach ($fields as &$entry)
- {
- $valueset[$i-2][$entry['name']]
= $this->bocommon->ascii2utf($data->sheets[0]['cells'][$i][$entry['id']]);
- }
+ $valueset[$i-2][$entry['name']] =
$sheetData[$i][$entry['id']];
}
- else
- {
- break;
- }
}
return $valueset;
}
Modified: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php 2012-10-07 17:08:00 UTC (rev
10128)
+++ trunk/property/inc/class.uiimport.inc.php 2012-10-07 21:56:30 UTC (rev
10129)
@@ -373,29 +373,33 @@
return $result;
}
+
protected function getexceldata($path, $skipfirstline = true)
{
- $data = CreateObject('phpgwapi.excelreader');
- $data->setOutputEncoding('CP1251');
- $data->read($path);
+ phpgw::import_class('phpgwapi.phpexcel');
+
+ $objPHPExcel = PHPExcel_IOFactory::load($path);
+ $data =
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
+
$result = array();
$start = $skipfirstline ? 2 : 1; // Read the first line
to get the headers out of the way
if ($skipfirstline)
{
- $this->fields =
array_values($data->sheets[0]['cells'][1]);
+ $this->fields = array_values($data[1]);
}
- $rows = $data->sheets[0]['numRows']+1;
+ $rows = count($data)+1;
- for ($i=$start; $i<$rows; $i++ ) //First data entry on
row 2
+ for ($i=$start; $i<$rows; $i++ )
{
$_result = array();
- foreach($data->sheets[0]['cells'][$i] as $key
=> $value)
+ $j=0;
+ foreach($data[$i] as $key => $value)
{
- $_key = $key - 1;
- $_result[$_key] =
utf8_encode(trim($value));
+ $_result[$j] = trim($value);
+ $j++;
}
$result[] = $_result;
}
Modified: trunk/property/inc/class.uis_agreement.inc.php
===================================================================
--- trunk/property/inc/class.uis_agreement.inc.php 2012-10-07 17:08:00 UTC
(rev 10128)
+++ trunk/property/inc/class.uis_agreement.inc.php 2012-10-07 21:56:30 UTC
(rev 10129)
@@ -738,7 +738,7 @@
$import = CreateObject('property.import');
$importfile = $import->importfile();
- $id = phpgw::get_var('id', 'int');
+ $id = phpgw::get_var('id');
if(isset($importfile) && is_file($importfile) &&
!phpgw::get_var('cancel'))
{
$list = $this->bo->read_details(0);
@@ -1643,14 +1643,14 @@
{
return;
}
- $id = phpgw::get_var('id', 'int');
+ $id = phpgw::get_var('id');
if($id)
{
$list = $this->bo->read_details($id);
}
else
{
- $list = $this->bo->read($id);
+ $list = $this->bo->read();
}
$uicols = $this->bo->uicols;
$this->bocommon->download($list,$uicols['name'],$uicols['descr'],$uicols['input_type']);
Modified: trunk/property/inc/cron/default/import_files.php
===================================================================
--- trunk/property/inc/cron/default/import_files.php 2012-10-07 17:08:00 UTC
(rev 10128)
+++ trunk/property/inc/cron/default/import_files.php 2012-10-07 21:56:30 UTC
(rev 10129)
@@ -152,20 +152,16 @@
function import_vaktprotokoll()
{
$filename = 'Vakthendelser.xls';
- $data = CreateObject('phpgwapi.excelreader');
- $data->setOutputEncoding('CP1251');
- $data->read(PHPGW_SERVER_ROOT .
"/property/inc/excelreader/test/{$filename}");
+ phpgw::import_class('phpgwapi.phpexcel');
- for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
+ $path = PHPGW_SERVER_ROOT .
"/property/inc/excelreader/test/{$filename}";
+ $objPHPExcel = PHPExcel_IOFactory::load($path);
+ $data =
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
+
+ for ($i = 1; $i <= count($data); $i++)
{
- for ($j = 1; $j <= $data->sheets[0]['numCols'];
$j++)
- {
- echo
"\"".$data->sheets[0]['cells'][$i][$j]."\",";
- }
- echo "\n";
+ echo "\"".print_r($data[$i]);
}
}
}
-
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [10129] property: excel related changes,
Sigurd Nes <=