1

我已经导出了一个 Excel 表,它将从我的客户(Mysql 数据库)中收集数据,现在我想用列颜色对其进行格式化。

这是我导出excel表的代码....

<?php

ob_start();
session_start();
include("include/session.php");
include("common_function.php");
//connect the database

$customer_id=$_GET['pid'];
//Enter the headings of the excel columns
$contents="Sr.,Agent Name,Contact Person,Contact Number,Password,Deal With Customer,References,Time to reach,Package Offered,Mode of Payment,Note,NEAREST CROSS STREET,DATE OF BIRTH\n"; 

//Mysql query to get records from datanbase
//You can customize the query to filter from particular date and month etc...Which will depends your database structure.

$sql = "SELECT id,agent_id,fname1,mobile_no,password,fname,rentfrom,cheque_no,package_id,monthly_monitoring,final_comment,cross_street,dob1 FROM customer WHERE `id`='$customer_id'";

$user_query = mysql_query($sql);

//While loop to fetch the records
while($row = mysql_fetch_array($user_query))
{
$contents.=$row['id'].",";
$contents.=$row['agent_id'].",";
$contents.=$row['fname1'].",";
$contents.=$row['mobile_no'].",";
$contents.=$row['password'].",";
$contents.=$row['fname'].",";
$contents.=$row['rentfrom'].",";
$contents.=$row['cheque_no'].",";
$contents.=$row['package_id'].",";
$contents.=$row['monthly_monitoring'].",";
$contents.=$row['final_comment'].",";
$contents.=$row['cross_street'].",";
$contents.=$row['dob1']."\n";
}

// remove html and php tags etc.
$contents = strip_tags($contents); 

//header to make force download the file

header("Content-Disposition: attachment; filename=Sale_report".date('d-m-Y').".csv");
print $contents;

?>

现在我想给我的第一行上色...

4

3 回答 3

1

嘿 Cnik,Ayyappan Sekar 是对的。PHPExcel 是一个可用于生成 xls(和许多其他格式)文件的库。它的目的是生成一个文件,而不是在某个 id 上发送它。

您可以做的是,首先使用 PHPExcel 库生成一个文件并将其保存在某处。要向某个 id 发送电子邮件,您可以使用 http://php.net/manual/en/function.mail.php'>mail 功能。然而,使用 php 的邮件功能发送带有附件的电子邮件并不复杂,虽然不是很困难。

请参阅下面给出的链接:
1] http://www.shotdev.com/php/php-mail/php-send-email-upload-form-attachment-file/
2]通过 PHP 邮件附加文件(参考答案阿斯普林)
3] http://www.texelate.co.uk/blog/send-email-attachment-with-php/

于 2012-12-18T10:23:34.383 回答
0

CSV 文件是一个简单的文本文件,不能用颜色格式化它 http://en.wikipedia.org/wiki/Comma-separated_values

于 2012-12-14T09:00:47.983 回答
0

您好,您可以使用PHPExcel库,而不是使用标头导出到 excel 。它提供了更简单的内置方法来实现你想要的......甚至你可以应用样式、合并单元格等

于 2012-12-14T09:10:05.177 回答