使用phpofficephpspreadsheet,导入、导出数据

更新时间:2023-07-20 19:49:28 阅读: 评论:0

使⽤phpofficephpspreadsheet,导⼊、导出数据安装
compor require phpoffice/phpspreadsheet
//u \PhpOffice\PhpSpreadsheet\Spreadsheet;
//u \PhpOffice\PhpSpreadsheet\IOFactory;
//u \PHPExcel_Style_NumberFormat;    //设置列的格式==>>设置⽂本格式
//导⼊数据
发红包的吉利数字public function export()如何将应用隐藏起来
{
//上传excel⽂件
$file = request()->file('myfile');
  //获取表格的⼤⼩,限制上传表格的⼤⼩5M
$file_size = $_FILES['myfile']['size'];
if ($file_size > 50 * 1024 * 1024) {
$this->error('⽂件⼤⼩不能超过5M');
exit();
}
//限制上传表格类型
$fileExtendName = substr(strrchr($_FILES['myfile']["name"], '.'), 1);
//application/vnd.ms-excel  为xls⽂件类型
if ($fileExtendName != 'xls') {
$this->error('必须为excel表格,且必须为xls格式!');
exit();
}
header("content-type:text/html;chart=utf-8");
//将⽂件保存到public/uploads⽬录下⾯
$info = $file->validate(['size' => 5 * 1024 * 1024, 'ext' => 'xls,xlsx'])->move('uploads');
if ($info) {
小火龙果
//获取上传到后台的⽂件名
$fileName = $info->getSaveName();
//获取⽂件路径
$filePath =  '/www/wwwroot/obd-api/'. 'public' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $fileName;
} el {
return json(['status' => '1', 'message' => '⽂件过⼤或格式不正确导致上传失败-_-!']);
}
require dirname(dirname(dirname(__DIR__))).'/vendor/autoload.php';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$reader->tReadDataOnly(TRUE);
奇货可居是什么意思$spreadsheet = $reader->load($filePath); //载⼊excel表格
推荐意见$worksheet = $spreadsheet->getActiveSheet();
$highestRow = $worksheet->getHighestRow(); // 总⾏数
$highestColumn = $worksheet->getHighestColumn(); // 总列数
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn); // e.g. 5
龙江公园$lines = $highestRow - 2;
if ($lines <= 0) {
exit('Excel表格中没有数据');
}
蒸八宝饭的做法for ($row = 3; $row <= $highestRow; ++$row) {
$temp = array(
'code' => $worksheet->getCellByColumnAndRow('1', $row)->getValue(),
'name' => $worksheet->getCellByColumnAndRow('2', $row)->getValue(),
'class' => $worksheet->getCellByColumnAndRow('3', $row)->getValue(),
叉烧鸡腿'describe' => $worksheet->getCellByColumnAndRow('4', $row)->getValue(),
'symptom' => $worksheet->getCellByColumnAndRow('5', $row)->getValue(),
'cau' => $worksheet->getCellByColumnAndRow('6', $row)->getValue(),
'scheme' => $worksheet->getCellByColumnAndRow('7', $row)->getValue(),
)
;
$list[] = $temp;
}
}

本文发布于:2023-07-20 19:49:28,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1107515.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:表格   上传   获取   数据   限制
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图