function ExportExcelRecord($arrdata, $datatype, $numberRow, $objPHPExcel, $pageObj)
{
    global $cCharset, $locale_info;
    $col = -1;
    $objASIndex = $objPHPExcel->setActiveSheetIndex(0);
    $objASheet = $objPHPExcel->getActiveSheet();
    $rowDim = $objASIndex->getRowDimension($numberRow + 1);
    foreach ($arrdata as $field => $data) {
        $col++;
        $colLetter = PHPExcel_Cell::stringFromColumnIndex($col);
        $colDim = $objASIndex->getColumnDimension($colLetter);
        if ($datatype[$field] == "binary") {
            if (!$data) {
                continue;
            }
            if (!function_exists("imagecreatefromstring")) {
                $objASIndex->setCellValueByColumnAndRow($col, $numberRow + 1, "LONG BINARY DATA - CANNOT BE DISPLAYED");
                continue;
            }
            $error_handler = set_error_handler("empty_error_handler");
            $gdImage = imagecreatefromstring($data);
            if ($error_handler) {
                set_error_handler($error_handler);
            }
            if ($gdImage) {
                $objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
                $objDrawing->setImageResource($gdImage);
                $objDrawing->setCoordinates($colLetter . ($row + 1));
                $objDrawing->setWorksheet($objASheet);
                $width = $objDrawing->getWidth() * 0.143;
                $height = $objDrawing->getHeight() * 0.75;
                if ($rowDim->getRowHeight() < $height) {
                    $rowDim->setRowHeight($height);
                }
                $colDimSh = $objASheet->getColumnDimension($colLetter);
                $colDimSh->setAutoSize(false);
                if ($colDim->getWidth() < $width) {
                    $colDim->setWidth($width);
                }
            }
        } elseif ($datatype[$field] == "file") {
            $arr = my_json_decode($row[$field]);
            if (count($arr) == 0) {
                $data = PHPExcel_Shared_String::ConvertEncoding($data, 'UTF-8', $cCharset);
                if ($data == "<img src=\"images/no_image.gif\" />") {
                    $arr[] = array("name" => "images/no_image.gif");
                } else {
                    if (substr($data, 0, 1) == '=') {
                        $data = '="' . str_replace('"', '""', $data) . '"';
                    }
                    $objASIndex->setCellValueByColumnAndRow($col, $numberRow + 1, $data);
                    continue;
                }
            }
            $offsetY = 0;
            $height = 0;
            foreach ($arr as $img) {
                if (!file_exists($img["name"]) || !$img["name"]) {
                    $data = PHPExcel_Shared_String::ConvertEncoding($data, 'UTF-8', $cCharset);
                    if (substr($data, 0, 1) == '=') {
                        $data = '="' . str_replace('"', '""', $data) . '"';
                    }
                    $objASIndex->setCellValueByColumnAndRow($col, $numberRow + 1, $data);
                    continue;
                }
                $objDrawing = new PHPExcel_Worksheet_Drawing();
                $objDrawing->setPath($img["name"]);
                $objDrawing->setCoordinates($colLetter . ($numberRow + 1));
                $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
                $objDrawing->setOffsetY($offsetY);
                $width = $objDrawing->getWidth() * 0.143;
                $height = $height + $objDrawing->getHeight() * 0.75;
                $offsetY = $offsetY + $objDrawing->getHeight();
                if ($rowDim->getRowHeight() < $height) {
                    $rowDim->setRowHeight($height);
                }
                $colDimSh = $objASheet->getColumnDimension($colLetter);
                $colDimSh->setAutoSize(false);
                if ($colDim->getWidth() < $width) {
                    $colDim->setWidth($width);
                }
            }
        } else {
            $data = PHPExcel_Shared_String::ConvertEncoding($data, 'UTF-8', $cCharset);
            if (substr($data, 0, 1) == '=') {
                $data = '="' . str_replace('"', '""', $data) . '"';
            }
            $objASIndex->setCellValueByColumnAndRow($col, $numberRow + 1, $data);
            if ($datatype[$field] == "date") {
                $objStyle = $objASIndex->getStyle($colLetter . ($numberRow + 1));
                $objNumFrm = $objStyle->getNumberFormat();
                $objNumFrm->setFormatCode($locale_info["LOCALE_SSHORTDATE"] . " hh:mm:ss");
            }
        }
    }
}
Beispiel #2
0
function ExportExcelRecord($arrdata, $datatype, $row, $objPHPExcel, $pageObj)
{
    global $cCharset, $locale_info;
    $col = -1;
    $objASIndex = $objPHPExcel->setActiveSheetIndex(0);
    $objASheet = $objPHPExcel->getActiveSheet();
    $rowDim = $objASIndex->getRowDimension($row + 1);
    foreach ($arrdata as $field => $data) {
        $col++;
        $colLetter = PHPExcel_Cell::stringFromColumnIndex($col);
        $colDim = $objASIndex->getColumnDimension($colLetter);
        if ($datatype[$field] == "binary") {
            if (!$data) {
                continue;
            }
            if (!function_exists("imagecreatefromstring")) {
                $objASIndex->setCellValueByColumnAndRow($col, $row + 1, "LONG BINARY DATA - CANNOT BE DISPLAYED");
                continue;
            }
            $error_handler = set_error_handler("empty_error_handler");
            $gdImage = imagecreatefromstring($data);
            if ($error_handler) {
                set_error_handler($error_handler);
            }
            if ($gdImage) {
                $objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
                $objDrawing->setImageResource($gdImage);
                $objDrawing->setCoordinates($colLetter . ($row + 1));
                $objDrawing->setWorksheet($objASheet);
                $width = $objDrawing->getWidth() * 0.143;
                $height = $objDrawing->getHeight() * 0.75;
                if ($rowDim->getRowHeight() < $height) {
                    $rowDim->setRowHeight($height);
                }
                $colDimSh = $objASheet->getColumnDimension($colLetter);
                $colDimSh->setAutoSize(false);
                if ($colDim->getWidth() < $width) {
                    $colDim->setWidth($width);
                }
            }
        } elseif ($datatype[$field] == "file") {
            if (!file_exists($pageObj->pSet->getUploadFolder($field) . $data) || !$data) {
                continue;
            }
            $objDrawing = new PHPExcel_Worksheet_Drawing();
            $objDrawing->setPath($pageObj->pSet->getUploadFolder($field) . $data);
            $objDrawing->setCoordinates($colLetter . ($row + 1));
            $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
            $width = $objDrawing->getWidth() * 0.143;
            $height = $objDrawing->getHeight() * 0.75;
            if ($rowDim->getRowHeight() < $height) {
                $rowDim->setRowHeight($height);
            }
            $colDimSh = $objASheet->getColumnDimension($colLetter);
            $colDimSh->setAutoSize(false);
            if ($colDim->getWidth() < $width) {
                $colDim->setWidth($width);
            }
        } else {
            $data = PHPExcel_Shared_String::ConvertEncoding($data, 'UTF-8', $cCharset);
            $objASIndex->setCellValueByColumnAndRow($col, $row + 1, $data);
            if ($datatype[$field] == "date") {
                $objStyle = $objASIndex->getStyle($colLetter . ($row + 1));
                $objNumFrm = $objStyle->getNumberFormat();
                $objNumFrm->setFormatCode($locale_info["LOCALE_SSHORTDATE"] . " hh:mm:ss");
            }
        }
    }
}