如何通过电子邮件发送oracle查询结果。我更喜欢将电子邮件附加为excel文件。 [英] How can I send oracle query results by email. I would prefer attaching to email as excel file.
本文介绍了如何通过电子邮件发送oracle查询结果。我更喜欢将电子邮件附加为excel文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用PhpExcel和PhpMailer作为excel附件的电子邮件发送此表。此表是查询我的oracle数据库的结果。我需要知道如何使用PhpExcel将此表写入excel,然后将其附加到phpMailer的电子邮件地址,最后发送。
提前感谢
I need to send this table by email as an excel attachment using PhpExcel and PhpMailer. This table is a result of querying my oracle DB. I need to know how I can use PhpExcel to write this table to excel and then attach it to an email address with phpMailer and finally send it. Thanks in advance.
<?php
$username = "xxx";
$passwd = "yyy";
$db="(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.43.56.789)(PORT = 1234))
)
(CONNECT_DATA =
(SERVICE_NAME = xxx)
)
)";
$c = OCILogon($username,$passwd,$db);
if (!$c)
{
echo "Connection failed";
}
else
{
echo "We are connected to KYC.Querying DB now...Please wait... ";
}
$s = oci_parse($c, "
select MSISDN SUBSCRIBER_NUMBER, OUTLET_NUMBER,time_stamp, Company,NAMES SUBSCRIBER_NAME,GENDER, DOB DATE_OF_BIRTH,Dealer_name Dealer_name, Agent_name
from subscribers where time_stamp between trunc(sysdate)-1 And trunc(sysdate)-1/86400 order by time_stamp");
if (!$s) {
$e = oci_error($c);
trigger_error('Could not parse statement: '. $e['message'], E_USER_ERROR);
}
$r = oci_execute($s);
if (!$r) {
$e = oci_error($s);
trigger_error('Could not execute statement: '. $e['message'], E_USER_ERROR);
}
$html .= '<table width="720" border="0" cellspacing="0" cellpadding="0">
<tr>
<th class="header" colspan="7"> KYC Details</th>
<tr>
<tr>
<th>SUBSCRIBER_NUMBER</th>
<th>OUTLET_NUMBER</th>
<th>TIME_STAMP</th>
<th>COMPANY</th>
<th>SUBSCRIBER_NAME</th>
<th>GENDER</th>
<th>DATE_OF_BIRTH</th>
<tr>';
while($rows=oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)){
$sub = $rows['SUBSCRIBER_NUMBER'];
$agt = $rows['OUTLET_NUMBER'];
$tim = $rows['TIME_STAMP'];
$com = $rows['COMPANY'];
$nam = $rows['SUBSCRIBER_NAME'];
$sex = $rows['GENDER'];
$dob = $rows['DATE_OF_BIRTH'];
$html .= '<tr>
<td>'.$sub.'</td>
<td>'.$agt.'</td>
<td>'.$tim.'</td>
<td>'.$com.'</td>
<td>'.$nam.'</td>
<td>'.$sex.'</td>
<td>'.$dob.'</td>';
$html .= '<tr>';
}
$html .='</table><hr>';
echo $html;
?>
推荐答案
我会忽略HTML的东西,只是写出来作为逗号分隔的值文件,在每个记录之后有一行新行,然后在Excel中打开它,并将其保存为XLSX。
I would ignore the HTML stuff and simply write it out as a comma-separated values file with a new-line after each record, then open that in Excel and save it as XLSX.
这篇关于如何通过电子邮件发送oracle查询结果。我更喜欢将电子邮件附加为excel文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文