1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
<?php
require_once $Ini->path_third . '/phpexcel/PHPExcel.php';
require_once $Ini->path_third . '/phpexcel/PHPExcel/Writer/Excel2007.php';
private $oWorkbook;
private $oWorksheet;
private $oCell;
private $oRs;
/* This structure encodes the difference between ISO-8859-1 and Windows-1252,
as a map from the UTF-8 encoding of some ISO-8859-1 control characters to
the UTF-8 encoding of the non-control characters that Windows-1252 places
at the equivalent code points. */
function cp1252_to_utf8($str) {
var_dump($str);
var_dump(iconv_get_encoding('all'));
return $str;
}
//------------------------------------------------------------------
// @function ax_GetDbRs
// @purpose Get the SQL recordset according to the input request
//------------------------------------------------------------------
function ax_OpenWkb($filename) {
$oReader = PHPExcel_IOFactory::createReader('Excel2007');
$this->oWorkbook = $oReader->load($filename);
}
function ax_CloseWkb($filename) {
$objWriter = PHPExcel_IOFactory::createWriter($this->oWorkbook, 'Excel2007');
$objWriter->save($filename);
}
function ax_UploadWkb($filename,$forcetext=false) {
$objWriter = PHPExcel_IOFactory::createWriter($this->oWorkbook, 'Excel5');
ob_end_clean();
if(!$forcetext) {
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'.xls"');
} else {
header('Content-type: plain/text');
header('Content-Disposition: attachment;filename="'.$filename.'.txt"');
}
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
ob_end_flush();
ob_start();
}
function ax_SetRecordset($request) {
sc_select(dataset, $request);
$this->oRs = $dataset;
}
function ax_SyncNamedRange() {
if (false == $this->oRs) {
ax_DebugPush('Error while accessing dataset.');
} else {
foreach ($this->oWorkbook->getNamedRanges() as $oNames => $oNamedRange) {
$sName = $oNamedRange->getName();
$this->oWorksheet = $oNamedRange->getWorksheet();
$this->oCell = $this->oWorksheet->GetCell($oNamedRange->GetRange());
for ($i = 0; $i < $this->oRs->FieldCount(); $i++) {
$fld = $this->oRs->FetchField($i);
if (strtolower($fld->name) == strtolower($sName)) {
$this->oCell->setValue($this->oRs->fields[$i]);
ax_DebugVar($sName,$this->oCell->getValue());
}
}
}
}
}
function ax_SyncWorksheet($sheetname) {
if (false == $this->oRs) {
ax_DebugPush('Error while accessing dataset.');
} else {
$rows = $this->oRs->rowCount();
$rows = 2;
$columns = $this->oRs->fieldCount();
$columns = 10;
$this->oWorksheet = $this->oWorkbook->getActiveSheet();
$rowOffset = 1;
$colOffset = 1;
$this->oWorksheet->setCellValueByColumnAndRow(0, 1, $rows);
$this->oWorksheet->setCellValueByColumnAndRow(0, 2, $columns);
for ($colIndex=0;$colIndex<$columns;$colIndex++)
{
$fieldInfo = $this->oRs->fetchField($colIndex);
$this->oWorksheet->setCellValueByColumnAndRow($colIndex +$colOffset, $rowOffset, $fieldInfo->name);
}
$this->oRs->MoveFirst();
$arr = $this->oRs->FetchRow();
$this->oWorksheet->setCellValueByColumnAndRow(0, 3, count($arr));
$rowOffset = 3;
for ($rowIndex=0;$rowIndex<$rows;$rowIndex++) {
$this->oWorksheet->fromArray($this->oRs->FetchRow(), NULL, 'B'.($rowIndex+$rowOffset));
for ($colIndex=0;$colIndex<$columns;$colIndex++)
{
$this->oWorksheet->setCellValueByColumnAndRow($colIndex +$colOffset, $rowIndex+$rowOffset, $this->oRs->fields[$colIndex]);
}
$this->oRs->MoveNext();
}
}
}
?> |
Partager