我正与swift mail
中的yii2
合作。我发送了一封包含csv
附件的电子邮件。该文件包含一个工作表。现在我想在一个文件中添加两张纸。
public function actionEmail()
{
$sql = "SELECT COUNT(DISTINCT od.`meter_serial`) AS OGP_Created,
COUNT(DISTINCT mp.`meter_id`) AS Un_Verified_Meters,
COUNT(DISTINCT ins.`meter_msn`) AS Verified_Meters,
sd.`sub_div_code` AS SD_Code,sd.`name` AS SD_Name
FROM `ogp_detail` od
INNER JOIN `survey_hesco_subdivision` sd ON od.`sub_div` = sd.`sub_div_code`
LEFT JOIN `meter_ping` mp ON od.`meter_id` = mp.`meter_id`
LEFT JOIN `installations` ins ON od.`meter_serial` = ins.`meter_msn`
WHERE od.`meter_type` = '3-Phase'
GROUP BY sd.`name`";
$query= "SELECT COUNT(DISTINCT od.`meter_serial`) AS OGP_Created,
COUNT(DISTINCT mp.`meter_id`) AS Un_Verified_Meters,
COUNT(DISTINCT ins.`meter_msn`) AS Verified_Meters,
sd.`sub_div_code` AS SD_Code,sd.`name` AS SD_Name
FROM `ogp_detail` od
INNER JOIN `survey_hesco_subdivision` sd ON od.`sub_div` =
sd.`sub_div_code`
LEFT JOIN `meter_ping` mp ON od.`meter_id` = mp.`meter_id`
LEFT JOIN `installations` ins ON od.`meter_serial` =
ins.`meter_msn`
WHERE od.`meter_type` = 'L.T.TOU'
GROUP BY sd.`name`";
$result = Yii::$app->db->createCommand($sql)->queryAll();
$result_set = Yii::$app->db->createCommand($query)->queryAll();
//create a csv file
$filename = $this->getAttachment($result,$result_set);
//send email
$this->sendEmail($filename);
return $this->redirect(['index']);
}
以下是我的getAttachment
功能
public function getAttachment($results,$result_set) {
$sum_OGP = 0;
$sum_UnVerified = 0;
$sum_Verified = 0;
$filename = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . '3-Phase Breakdown List ' . date('d-m-y') . '.csv';
//open a csv file
$file = fopen($filename, "w");
$headerInjected = false;
$header = ['OGP Created', '3-Phase Un Verified Meters', '3-Phase Verified Meters', 'Sub Div Code', 'Sub Div Name'];
//write lines to the csv file
foreach ($results as $result) {
if (!$headerInjected) {
$headerInjected = true;
fputcsv($file, $header);
}
fputcsv($file, $result);
$sum_OGP +=$result['OGP_Created'];
$sum_UnVerified +=$result['Un_Verified_Meters'];
$sum_Verified +=$result['Verified_Meters'];
}
//add the sum in the last row
fputcsv($file,["Total OGP","Total Unverified Meters","Total Verified Meters"]);
fputcsv($file,[$sum_OGP,$sum_UnVerified,$sum_Verified]);
//close the file handle
fclose($file);
return $filename;
}
我想添加$result_set
header
的内容fputcsv
两者的内容将相同,model.add(Dense(3, activation='softmax')) # Number of classes 3
内容会有所不同。
如何在一张excel文件中添加两张图片?
任何帮助都将受到高度赞赏。