forked from TechToThePeople/eu.tttp.excel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportexcel.php
78 lines (68 loc) · 2.25 KB
/
exportexcel.php
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
<?php
function writeHTMLFile($fileName, &$header, &$rows, $titleHeader = NULL, $outputHeader = TRUE) {
if ($outputHeader) {
CRM_Utils_System::download(CRM_Utils_String::munge($fileName),
'application/vnd.ms-excel; charset=utf-8',
CRM_Core_DAO::$_nullObject,
'xls',
FALSE
);
// a bit of magic copy paste. Something in the html header helps excel understanding unicode
echo <<<EOD
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8" />
<meta name=ProgId content=Excel.Sheet><html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40" />
<meta http-equiv="Content-Language" Content="en" />
EOD;
echo "<table><thead><tr class='xlGeneralBold'>";
foreach ($header as $field) {
echo "<th>$field</th>";
}
echo "</tr></thead><tbody>";
}
$i = 0;
$fields_cnt = count($header);
foreach ($rows as $row) {
$schema_insert = '';
$colNo = 0;
echo "\n<tr>";
foreach ($row as $j => $value) {
echo "<td>" . htmlentities($value, ENT_COMPAT, 'UTF-8') . "</td>";
}
echo "</tr>";
}
// echo "</tbody></table>";
}
function exportexcel_civicrm_export( $exportTempTable, $headerRows, $sqlColumns, $exportMode ) {
$writeHeader = true;
$offset = 0;
$limit = 10;
$query = "SELECT * FROM $exportTempTable";
require_once 'CRM/Core/Report/Excel.php';
while ( 1 ) {
$limitQuery = $query . " LIMIT $offset, $limit;";
$dao = CRM_Core_DAO::executeQuery( $limitQuery );
if ( $dao->N <= 0 ) {
break;
}
$componentDetails = array( );
while ( $dao->fetch( ) ) {
$row = array( );
foreach ( $sqlColumns as $column => $dontCare ) {
$row[$column] = $dao->$column;
}
$componentDetails[] = $row;
}
//CRM_Core_Report_Excel::
writeHTMLFile( CRM_Export_BAO_Export::getExportFileName('xls', $exportMode)." ".date("Y-m-d_H-i"), $headerRows,$componentDetails, null, $writeHeader );
$writeHeader = false;
$offset += $limit;
}
echo "</tbody></table>";
CRM_Utils_System::civiExit( );
}