|
@@ -113,22 +113,30 @@ function export($columns, $rows, $filename = "jjrcw", $settings = [], $sheetname
|
|
|
for ($i = 0; $i < $colCount; $i++) {
|
|
|
$objPHPExcel->setCellValue(getExcelColumnByIndex($i) . $titleStartLine, $columns[$i]);
|
|
|
}
|
|
|
+ $formatString = []; //需要文本处理的列
|
|
|
//设置正文内容
|
|
|
for ($i = 0; $i < $rowCount; $i++) {
|
|
|
for ($n = 0; $n < $colCount; $n++) {
|
|
|
if (is_numeric($rows[$i][$n]) && strlen($rows[$i][$n]) > 11) {
|
|
|
//超过11位的数字转成文本方以免被转化为科学数
|
|
|
$objPHPExcel->setCellValueExplicit(getExcelColumnByIndex($n) . ($rowStartLine + $i), $rows[$i][$n], $datatype::TYPE_STRING);
|
|
|
+ $formatString[] = $n;
|
|
|
} else {
|
|
|
$objPHPExcel->setCellValue(getExcelColumnByIndex($n) . ($rowStartLine + $i), $rows[$i][$n]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ $formatString = array_unique($formatString); //去掉重复项
|
|
|
+
|
|
|
$objPHPExcel->getDefaultColumnDimension()->setWidth(16); //默认列宽
|
|
|
$objPHPExcel->getDefaultRowDimension()->setRowHeight(30); //默认列高
|
|
|
//样式设置
|
|
|
$defaultSetting = getCommonExcelSetting($colCount, $rowCount);
|
|
|
- $mergeSettings = [];
|
|
|
+ foreach ($formatString as $fs) {
|
|
|
+ $columnName = getExcelColumnByIndex($fs);
|
|
|
+ $defaultSetting["format"][] = ["string", sprintf("%s%d:%s%d", $columnName, 2, $columnName, count($rows) + 1)];
|
|
|
+ }
|
|
|
+ $mergeSettings = []; //合并默认设置与个性设置的集合
|
|
|
foreach ($defaultSetting as $key => $set) {
|
|
|
$mergeSettings[$key] = is_array($set) ? array_merge((array) $set, (array) $settings[$key]) : ($settings[$key] ?: $set);
|
|
|
unset($settings[$key]);
|