当前位置:网站首页>Spreadsheet export excel table
Spreadsheet export excel table
2022-07-28 01:19:00 【qq_ twenty-seven million eight hundred and seventy-eight thousa】
One . export excel To local , Contains wechat image columns
/** * Export member data organization table */
public function exportsMem($lst)
{
// Add program execution without time limit
ini_set("memory_limit", "500M");
set_time_limit(0);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Set sheet title name
$worksheet->setTitle(' Member data export table ');
// Header
// Set cell contents
$worksheet->setCellValueByColumnAndRow(1, 1, ' APP Member data export table ');
$worksheet->setCellValueByColumnAndRow(1, 2, ' User's mobile phone number ');
$worksheet->setCellValueByColumnAndRow(2, 2, ' The avatars ');
$worksheet->setCellValueByColumnAndRow(3, 2, ' Wechat login ');
$worksheet->setCellValueByColumnAndRow(4, 2, ' Bind wechat ');
$worksheet->setCellValueByColumnAndRow(5, 2, ' Alipay user name ');
$worksheet->setCellValueByColumnAndRow(6, 2, ' Alipay account ');
$worksheet->setCellValueByColumnAndRow(7, 2, ' nickname ');
$worksheet->setCellValueByColumnAndRow(8, 2, ' The balance of gold coins ');
$worksheet->setCellValueByColumnAndRow(9, 2, ' Cash balance ');
$worksheet->setCellValueByColumnAndRow(10, 2, ' Amount withdrawn ');
$worksheet->setCellValueByColumnAndRow(11, 2, ' Registration time ');
$worksheet->setCellValueByColumnAndRow(12, 2, ' Application ');
$worksheet->setCellValueByColumnAndRow(13, 2, ' Application market ');
// Set column width
$worksheet->getColumnDimension('A')->setWidth(20);
$worksheet->getColumnDimension('B')->setWidth(20);
$worksheet->getColumnDimension('C')->setWidth(40);
$worksheet->getColumnDimension('D')->setWidth(20);
$worksheet->getColumnDimension('E')->setWidth(20);
$worksheet->getColumnDimension('F')->setWidth(20);
$worksheet->getColumnDimension('G')->setWidth(20);
$worksheet->getColumnDimension('H')->setWidth(20);
$worksheet->getColumnDimension('I')->setWidth(20);
$worksheet->getColumnDimension('J')->setWidth(20);
$worksheet->getColumnDimension('K')->setWidth(20);
$worksheet->getColumnDimension('L')->setWidth(20);
$worksheet->getColumnDimension('M')->setWidth(20);
// $spreadsheet->getDefaultStyle()->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); // Set all columns horizontally centered
// merge cell
$worksheet->mergeCells('A1:M1');
$styleArray = [
'font' => [
'bold' => true
],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
],
];
// Set cell header style
$worksheet->getStyle('A1')->applyFromArray($styleArray)->getFont()->setSize(28);
$worksheet->getStyle('A2:M2')->applyFromArray($styleArray)->getFont()->setSize(14);
// Get the data reported by all enterprises Conduct excel export
foreach ($lst as $key => $value) {
$k = $key + 3;
$worksheet->setCellValue('A' . $k, $value['phone']);
// $worksheet->setCellValue('B' . $k, $value['headimgurl']);
// $worksheet->setCellValue('B' . $k, '');
$worksheet->setCellValue('C' . $k, $value['isLoginWechat']);
$worksheet->setCellValue('D' . $k, $value['hasWechat']);
$worksheet->setCellValue('E' . $k, $value['alipay_name']);
$worksheet->setCellValue('F' . $k, $value['alipay_account']);
$worksheet->setCellValue('G' . $k, $value['nickname']);
$worksheet->setCellValue('H' . $k, $value['gold']);
$worksheet->setCellValue('I' . $k, $value['goldCash']);
$worksheet->setCellValue('J' . $k, $value['outCash']);
$worksheet->setCellValue('K' . $k, $value['addTime']);
$worksheet->setCellValue('L' . $k, $value['app_name']);
$worksheet->setCellValue('M' . $k, $value['market_name']);
if(!empty($value['headimgurl'])){
$img = self::curlGet($value['headimgurl']);
$drawing[$k] = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing[$k]->setName(' picture ');
$drawing[$k]->setDescription(' picture ');
$drawing[$k]->setPath($img);
// $drawing[$key]->setPath($dir . $basename);
$drawing[$k]->setWidth(80);
$drawing[$k]->setHeight(80);
$drawing[$k]->setCoordinates('B'.$k);
$drawing[$k]->setOffsetX(12);
$drawing[$k]->setOffsetY(12);
$drawing[$k]->setWorksheet($spreadsheet->getActiveSheet());
$spreadsheet->getActiveSheet()->getRowDimension($k)->setRowHeight(80);
} else {
$worksheet->setCellValue('B' . $k, '');
}
}
$len = count($lst);
$styleArrayBody = [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => '666666'],
],
],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
],
];
$total_jzInfo = $len + 2;
// Add all borders / In the middle
$worksheet->getStyle('A1:M'.$total_jzInfo)->applyFromArray($styleArrayBody);
$filename = ' Member data export table .xlsx';
// Clear output buffer
ob_end_clean();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
return $writer->save('php://output');
exit();
}
Two . Analyze wechat pictures
function getImage(string $url )
{
$header = array(
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding: gzip, deflate',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
$dataimg = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code == 200) {
$imgBase64Code = "data:image/jpeg;base64," . base64_encode($dataimg);
}
$img_content=$imgBase64Code;
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result)){
$type = $result[2];
$dir = "Uploads/wxpic";
is_dir($dir) OR mkdir($dir, 0777, true);
$new_file = "Uploads/wxpic/".md5(uniqid(rand())).".{
$type}";
if (file_put_contents($new_file, base64_decode(str_replace($result[1],'', $img_content))))
{
return $new_file;
}
}
return false;
}
$s = getImage("https://thirdwx.qlogo.cn/mmopen/vi_32/yLnIhxnZuXgZN2dGCibx5oZWmQnBj6PT77e7MJBLbH0q8rPLjXUpFFdSxm2Z8tB6ia5SwFicl56kxgJIa0mAbXCZA/132");
var_dump($s);
边栏推荐
- Recommended system model (III): fine scheduling model [LR, gbdt, wide & deep, DCN, DIN, Dien, MMOE, ple]
- 力挺吴雄昂!Arm中国管理层发公开信:对莫须有的指控感到震惊和愤怒!
- Huawei's Hubble investment shares in VCSEL chip manufacturer Zonghui Xinguang
- Lua进阶
- 测试人员需要了解的软件流程
- If asynchronous processing is implemented according to the framework
- 总投资近16亿元!乾照光电VCSEL、高端LED芯片项目正式开工
- Rviz uses arbotix to control robot motion
- Unknown database ‘xxxxx‘
- [game] Nintendo Nintendo switch ultra detailed purchase / use guide and precautions (continuous update according to your own use...)
猜你喜欢

Swoole定时器

Interface test practical project 02: read interface test documents and practice

The cooperation between starfish OS and metabell is just the beginning

Lua advanced

实现ABCD字母递增

The cooperation between starfish OS and metabell is just the beginning

Unknown database ‘xxxxx‘

110. In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe

氧气温湿度模组

I/O设备的基本概念及分类
随机推荐
激光器芯片厂商陕西源杰半导体获广发证券、中信证券等8家投资机构入股
If asynchronous processing is implemented according to the framework
CAP的理解
S-RPN: Sampling-balanced region proposal network for small crop pest detection
Interface test practical project 02: read interface test documents and practice
逻辑回归原理
从功能测试到自动化测试,月薪突破30K+,我的6年测开经验。
Redis缓存穿透击穿和雪崩
安全检测风险
《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
Oracle error: ora-01722 invalid number
华米科技“黄山2号”发布:AI性能提升7倍,功耗降低50%!
URDF 集成 Gazebo
如果某个表有近千万数据,CRUD比较慢,如何优化
ABAP CDs table function introduction and examples
Cross desktop web container evolution
Lua快速上手
糟糕程序员的20个坏习惯
[STM32] watchdog module