Commit 96694f33 authored by yinxiaoling's avatar yinxiaoling

excel换库

parent dcb13c63
......@@ -7,11 +7,11 @@ APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=pgsql
DB_HOST=120.77.61.117
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=strategy
DB_USERNAME=postgres
DB_PASSWORD=yhhl123
DB_PASSWORD=46H6lRFLulDJyNa8
BROADCAST_DRIVER=log
CACHE_DRIVER=array
......@@ -21,7 +21,7 @@ QUEUE_DRIVER=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=120.77.61.117
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=5gwW1hWM7xAtFdKxxbeAhzDpW50MOdimAMMw
REDIS_PORT=8293
......
*.env
/node_modules
/public/hot
/public/storage
......@@ -10,7 +11,6 @@ Homestead.yaml
npm-debug.log
yarn-error.log
.env.development
.env
.buildpath
.project
.settings/*
......
......@@ -13,12 +13,13 @@ trait Tool
}
/*
$loginUserInfo = [
['user_name'=>'ljss','user_sn'=>'SYSUSER|61f8d0f38ce9b0af1d0a405a2586c6cb','parent_sn'=>'ljs'],
['user_name'=>'yxl001','user_sn'=>'SYSUSER|9da548a2e392a679eb274a0b2abeb627','parent_sn'=>'ljs'],
['user_name'=>'yxl002','user_sn'=>'SYSUSER|a15f5d51a8b0156d14f2d8ad2d39e111','parent_sn'=>'ljs'],
['user_name'=>'yxl003','user_sn'=>'SYSUSER|bb25ff86b38bdac649494b690a655ed6','parent_sn'=>'ljs'],
['user_name'=>'yxl004','user_sn'=>'SYSUSER|da1452dd4bfa9371372b1f665f267540','parent_sn'=>'ljs'],
];
*/
*/
$loginUserInfo = [
['user_name'=>'hz900718001','user_sn'=>'SYSUSER|b6f3e7dfeccb7c455d28674943d42b90','parent_sn'=>'hz900718']
];
......
......@@ -152,7 +152,8 @@ class StrategySetController extends Controller
$datas[0][2]= "值班日期";
$datas[1] = ['小a',13112345678,'2020/5/20'];
$CommonService->exportPHPExcel($excelName, $datas);
//$CommonService->exportPHPExcel($excelName, $datas);
$CommonService->exportXlswriter($excelName, $datas);
}
public function downloadFailExcel(Request $request){
......
......@@ -125,5 +125,81 @@ class CommonService
}
//保存内容到excel文件,针对手机号码科学计数法特殊处理,$scientificCounting=1则处理第二列为string类型
public function storeXlswriter($excelName,$datas,$path='',$scientificCounting=0){
try{
if ($scientificCounting == 1){
foreach ($datas as $k=>$v){
if (strlen($v[1]) > 11 && is_numeric($v[1])){
$v[1] = (string)$v[1];
$datas[$k] = $v;
}
}
}
if (empty($path)){
$path = 'exports';
}
$pathDir = storage_path($path);
$config = ['path' => $pathDir];
$excel = new \Vtiful\Kernel\Excel($config);
$headers = $datas[0];
unset($datas[0]);
// fileName 会自动创建一个工作表,你可以自定义该工作表名称,工作表名称为可选参数
$filePath = $excel->fileName($excelName.'.xlsx', 'sheet1')
->header($headers)
->data($datas)
->output();
if ($filePath == 'FilePath'){
Log::info('保存文件失败'.$excelName);
return false;
}
return true;
}catch(\Exception $e){
return response()->json(['rst' => 200,'msg'=>"异常".$e->getMessage()]);
}
}
public function exportXlswriter($filename,$excel_data,$path=''){
$config = ['path' => storage_path($path)];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName($filename.'.xlsx', 'sheet1')
//->header(['Item', 'Cost'])
->data($excel_data)
->output();
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Disposition: attachment;filename="'.$filename.'.xlsx"');
header('Content-Length: ' . filesize($filePath));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Cache-Control: max-age=0');
header('Pragma: public');
ob_clean();
flush();
if (copy($filePath, 'php://output') === false) {
// Throw exception
}
// Delete temporary file
@unlink($filePath);
}
public function readXlswriter($path,$filename){
$config = ['path' => $path];
$excel = new \Vtiful\Kernel\Excel($config);
$datas = [];
$datas = $excel->openFile($filename)
->openSheet()
->getSheetData();
return array_merge(array_filter($datas));
}
}
......@@ -123,7 +123,8 @@ class StrategyService
array_unshift($failData, $failDataTitle);
$failExcelName = "importfaildata_".date('YmdHis');
$CommonService = new CommonService();
$failFile = $CommonService->storeExcelStyle($failExcelName, $failData,'','import');
//$failFile = $CommonService->storeExcelStyle($failExcelName, $failData,'','import');
$failFile = $CommonService->storeXlswriter($failExcelName, $failData,'','import');
//$failDataFile = $failExcelName.'.xlsx';
if ($failFile){
$failDataFile = $failExcelName;
......
This diff is collapsed.
......@@ -279,7 +279,7 @@ class ClassLoader
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}
/**
......@@ -377,7 +377,7 @@ class ClassLoader
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
$search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
......
This diff is collapsed.
......@@ -13,6 +13,7 @@ return array(
'XdgBaseDir\\' => array($vendorDir . '/dnoegel/php-xdg-base-dir/src'),
'Whoops\\' => array($vendorDir . '/filp/whoops/src/Whoops'),
'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'),
'Vtiful\\Kernel\\' => array($vendorDir . '/viest/php-ext-xlswriter-ide-helper/src'),
'VladimirYuldashev\\LaravelQueueRabbitMQ\\' => array($vendorDir . '/vladimir-yuldashev/laravel-queue-rabbitmq/src'),
'TijsVerkoyen\\CssToInlineStyles\\' => array($vendorDir . '/tijsverkoyen/css-to-inline-styles/src'),
'Tests\\' => array($baseDir . '/tests'),
......
This diff is collapsed.
This diff is collapsed.
Subproject commit 0d9c2d39802e6c1ebbad7d515d860a50c131f12e
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment