function ExportToExcel($rs, $nPageSize, $eventObj, $cipherer, $pageObj) { if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs, $pageObj); } else { $row = $cipherer->DecryptFetchedArray($pageObj->connection->fetch_array($rs)); } $tmpArr = array(); $totals = array(); $arrLabel = array(); $arrTotal = array(); $arrFields = array(); $arrTmpTotal = array(); $arrColumnWidth = array(); $arrTotalMessage = array(); $tmpArr = $pageObj->pSet->getExportFields(); foreach ($tmpArr as $value) { if ($pageObj->pSet->appearOnExportPage($value)) { $arrFields[] = $value; } } $arrTmpTotal = $pageObj->pSet->getTotalsFields(); $pageObj->viewControls->forExport = "excel"; foreach ($arrFields as $value) { $arrLabel[$value] = GetFieldLabel(GoodFieldName($pageObj->tName), GoodFieldName($value)); $arrColumnWidth[$value] = 10; $totals[$value] = array("value" => 0, "numRows" => 0); $totalsType = ""; foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $value) { $totalsType = $tvalue["totalsType"]; $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => $pageObj->pSet->getViewFormat($value)); } } } // write data rows $iNumberOfRows = 0; $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth); while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) { countTotals($totals, $totalsFields, $row); $values = array(); $arrData = array(); $arrDataType = array(); foreach ($arrFields as $field) { if (IsBinaryType($pageObj->pSet->getFieldType($field))) { $values[$field] = $row[$field]; } else { $values[$field] = $pageObj->getExportValue($field, $row); } } $eventRes = true; if ($eventObj->exists('BeforeOut')) { $eventRes = $eventObj->BeforeOut($row, $values, $pageObj); } if ($eventRes) { $iNumberOfRows++; $i = 0; foreach ($arrFields as $field) { if (IsBinaryType($pageObj->pSet->getFieldType($field))) { $arrDataType[$field] = "binary"; } elseif ($pageObj->pSet->getViewFormat($field) == FORMAT_DATE_SHORT || $pageObj->pSet->getViewFormat($field) == FORMAT_DATE_LONG || $pageObj->pSet->getViewFormat($field) == FORMAT_DATE_TIME) { $arrDataType[$field] = "date"; } elseif ($pageObj->pSet->getViewFormat($field) == FORMAT_FILE_IMAGE) { $arrDataType[$field] = "file"; } else { $arrDataType[$field] = ""; } $arrData[$field] = $values[$field]; } ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel, $pageObj); } if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs, $pageObj); } else { $row = $cipherer->DecryptFetchedArray($pageObj->connection->fetch_array($rs)); } } if (count($arrTmpTotal)) { foreach ($arrFields as $fName) { $value = array(); foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $fName) { $value = $tvalue; } } $total = ""; $totalMess = ""; if ($value["totalsType"]) { if ($value["totalsType"] == "COUNT") { $totalMess = "Count" . ": "; } elseif ($value["totalsType"] == "TOTAL") { $totalMess = "Total" . ": "; } elseif ($value["totalsType"] == "AVERAGE") { $totalMess = "Average" . ": "; } $total = GetTotals($fName, $totals[$fName]["value"], $value["totalsType"], $totals[$fName]["numRows"], $value["viewFormat"], "export"); } $arrTotal[$fName] = $total; $arrTotalMessage[$fName] = $totalMess; } } ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel); $extExcel = ".xlsx"; $formatExcel = "Excel2007"; if (@$_REQUEST["type"] == "excel5") { $formatExcel = "Excel5"; $extExcel = ".xls"; } ExportExcelSave(GoodFieldName($pageObj->tName) . $extExcel, $formatExcel, $objPHPExcel); }
function ExportToExcel() { global $rs, $nPageSize, $strTableName, $conn, $eventObj; if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs); } else { $row = db_fetch_array($rs); } // if(!$row) // return; $arrLabel = array(); $arrColumnWidth = array(); $arrTotal = array(); $arrTotalMessage = array(); $totals = array(); $arrFields = array(); $arrTmpTotal = array(); $arrFields = GetFieldsList($strTableName); $arrTmpTotal = GetTableData($strTableName, ".totalsFields", array()); foreach ($arrFields as $value) { $arrLabel[$value] = label($value, $strTableName); $arrColumnWidth[$value] = 10; $totals[$value] = 0; $totalsType = ""; foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $value) { $totalsType = $tvalue["totalsType"]; } } $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => ViewFormat($value, $strTableName)); } // write data rows $iNumberOfRows = 0; $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth); while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) { countTotals($totals, $totalsFields, $row); $values = array(); $arrData = array(); $arrDataType = array(); foreach ($arrFields as $value) { if (GetEditFormat($value, $strTableName) == EDIT_FORMAT_LOOKUP_WIZARD || GetEditFormat($value, $strTableName) == EDIT_FORMAT_RADIO) { $values[$value] = ""; if (strlen($row[$value])) { $values[$value] = DisplayLookupWizard($value, $row[$value], $row, "", MODE_EXPORT); } } elseif (IsBinaryType(GetFieldType($value, $strTableName))) { $values[$value] = $row[$value]; } else { if (ViewFormat($value, $strTableName) != FORMAT_FILE_IMAGE && ViewFormat($value, $strTableName) != FORMAT_FILE && ViewFormat($value, $strTableName) != FORMAT_HYPERLINK && ViewFormat($value, $strTableName) != FORMAT_EMAILHYPERLINK && ViewFormat($value, $strTableName) != FORMAT_CHECKBOX) { $format = ViewFormat($value, $strTableName); } else { $format = FORMAT_NONE; } $values[$value] = GetData($row, $value, $format); } } $eventRes = true; if ($eventObj->exists('BeforeOut')) { $eventRes = $eventObj->BeforeOut($row, $values, $arrColumnWidth, $iNumberOfRows + 1, $objPHPExcel); } if ($eventRes) { $iNumberOfRows++; $i = 0; foreach ($arrFields as $value) { if (IsBinaryType(GetFieldType($value, $strTableName))) { $arrDataType[$value] = "binary"; } elseif (ViewFormat($value, $strTableName) == FORMAT_FILE_IMAGE) { $arrDataType[$value] = "file"; } elseif (ViewFormat($value, $strTableName) == FORMAT_DATE_SHORT || ViewFormat($value, $strTableName) == FORMAT_DATE_LONG || ViewFormat($value, $strTableName) == FORMAT_DATE_TIME) { $arrDataType[$value] = "date"; } else { $arrDataType[$value] = ""; } $arrData[$value] = $values[$value]; } ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel); } if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs); } else { $row = db_fetch_array($rs); } } if (count($arrTmpTotal)) { foreach ($arrFields as $fName) { $value = array(); foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $fName) { $value = $tvalue; } } $total = ""; $totalMess = ""; if ($value["totalsType"]) { if ($value["totalsType"] == "COUNT") { $totalMess = "Count" . ": "; } elseif ($value["totalsType"] == "TOTAL") { $totalMess = "Total" . ": "; } elseif ($value["totalsType"] == "AVERAGE") { $totalMess = "Average" . ": "; } $total = GetTotals($fName, $totals[$fName], $value["totalsType"], $iNumberOfRows, $value["viewFormat"]); } $arrTotal[$fName] = $total; $arrTotalMessage[$fName] = $totalMess; } } ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel); $formatExcel = "Excel2007"; $extExcel = ".xlsx"; if (@$_REQUEST["type"] == "excel5") { $formatExcel = "Excel5"; $extExcel = ".xls"; } ExportExcelSave(GoodFieldName($strTableName) . $extExcel, $formatExcel, $objPHPExcel); }