|
@@ -36,20 +36,21 @@ function array_get($array, $key, $default = null)
|
|
* @param array $expTableData [['a'=>1]]
|
|
* @param array $expTableData [['a'=>1]]
|
|
* @param array $textValue ['a']
|
|
* @param array $textValue ['a']
|
|
*/
|
|
*/
|
|
-function export_exl($expTitle, $expCellName, $expTableData, $textValue=[]) {
|
|
|
|
|
|
+function export_exl($expTitle, $expCellName, $expTableData, $textValue = [])
|
|
|
|
+{
|
|
$fileName = $expTitle . date('_YmdHis'); //or $xlsTitle 文件名称可根据自己情况设定
|
|
$fileName = $expTitle . date('_YmdHis'); //or $xlsTitle 文件名称可根据自己情况设定
|
|
$cellNum = count($expCellName);
|
|
$cellNum = count($expCellName);
|
|
$dataNum = count($expTableData);
|
|
$dataNum = count($expTableData);
|
|
$objPHPExcel = new \PHPExcel();
|
|
$objPHPExcel = new \PHPExcel();
|
|
- $cellName = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'];
|
|
|
|
|
|
+ $cellName = get_exl_column_letter(count($expCellName));
|
|
for ($i = 0; $i < $cellNum; $i++) {
|
|
for ($i = 0; $i < $cellNum; $i++) {
|
|
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $expCellName[$i][1]);
|
|
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $expCellName[$i][1]);
|
|
}
|
|
}
|
|
// Miscellaneous glyphs, UTF-8
|
|
// Miscellaneous glyphs, UTF-8
|
|
for ($i = 0; $i < $dataNum; $i++) {
|
|
for ($i = 0; $i < $dataNum; $i++) {
|
|
for ($j = 0; $j < $cellNum; $j++) {
|
|
for ($j = 0; $j < $cellNum; $j++) {
|
|
- if (in_array($expCellName[$j][0],$textValue)) {
|
|
|
|
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]],\PHPExcel_Cell_DataType::TYPE_STRING);
|
|
|
|
|
|
+ if (in_array($expCellName[$j][0], $textValue)) {
|
|
|
|
+ $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]], \PHPExcel_Cell_DataType::TYPE_STRING);
|
|
} else {
|
|
} else {
|
|
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]]);
|
|
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]]);
|
|
}
|
|
}
|
|
@@ -65,6 +66,21 @@ function export_exl($expTitle, $expCellName, $expTableData, $textValue=[]) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+function get_exl_column_letter($num = 1)
|
|
|
|
+{
|
|
|
|
+ $res = [];
|
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
|
+ $y = ($i / 26);
|
|
|
|
+ if ($y >= 1) {
|
|
|
|
+ $y = intval($y);
|
|
|
|
+ $res[] = chr($y + 64) . chr($i - $y * 26 + 65);
|
|
|
|
+ } else {
|
|
|
|
+ $res[] = chr($i + 65);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $res;
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param string $file
|
|
* @param string $file
|
|
@@ -76,7 +92,7 @@ function export_exl($expTitle, $expCellName, $expTableData, $textValue=[]) {
|
|
function import_exl($file = '', $cell = [], $crop = 0, $sheet = 0)
|
|
function import_exl($file = '', $cell = [], $crop = 0, $sheet = 0)
|
|
{
|
|
{
|
|
$file = iconv("utf-8", "gb2312", $file); //转码
|
|
$file = iconv("utf-8", "gb2312", $file); //转码
|
|
- if (empty($file) OR !file_exists($file)) {
|
|
|
|
|
|
+ if (empty($file) or !file_exists($file)) {
|
|
die('file not exists!');
|
|
die('file not exists!');
|
|
}
|
|
}
|
|
|
|
|