微信小程序实用工具。

自律打卡100天

自律打卡100天,每日打卡习惯养成工具,支持早起打卡、阅读打卡、运动打卡、学习打卡、体重打卡等每日签到,自动生成打卡记录,助你坚持到底,养成好习惯,做更好的自己。

小程序码

照片压缩尺寸裁剪小助手

在线图片处理小程序。支持图片压缩、裁剪、旋转、拼接、加水印、格式转换和尺寸修改,还能一键制作九宫格裁剪图,快速完成日常照片编辑。

小程序码
Nicole McIntyre 发布于
php生成word
网络编程
php
文章来源: 100素材网 更新时间: 2014-08-04 17:48:26
php生成word php生成word文档 php生成excel php生成excel文件

通过php代码创建word文档、创建excel、csv文件的方法

php创建word文档(doc文件)代码


<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b>My first document</b>";
echo "</body>";
echo "</html>";
?>


php创建excel文档(xls文件)代码


<?php
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment;Filename=document_name.xls");

echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b>testdata1</b> \t <u>testdata2</u> \t \n ";
echo "</body>";
echo "</html>";
?>


php创建excel文档(csv文件)代码1


<?php
$table = 'table_name';
$outstr = NULL;

header("Content-Type: application/csv");
header("Content-Disposition: attachment;Filename=cars-models.csv");

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("db",$conn);

// Query database to get column names  
$result = mysql_query("show columns from $table",$conn);
// Write column names
while($row = mysql_fetch_array($result)){
    $outstr.= $row['Field'].',';
}  
$outstr = substr($outstr, 0, -1)."\n";

// Query database to get data
$result = mysql_query("select * from $table",$conn);
// Write data rows
while ($row = mysql_fetch_assoc($result)) {
    $outstr.= join(',', $row)."\n";
}

echo $outstr;
mysql_close($conn);
?>


php创建excel文档(csv文件)代码2


<?php 
$table = 'table_name';
$filename = tempnam(sys_get_temp_dir(), "csv");

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("db",$conn);

$file = fopen($filename,"w");

// Write column names
$result = mysql_query("show columns from $table",$conn);
for ($i = 0; $i < mysql_num_rows($result); $i++) {
    $colArray[$i] = mysql_fetch_assoc($result);
    $fieldArray[$i] = $colArray[$i]['Field'];
}
fputcsv($file,$fieldArray);

// Write data rows
$result = mysql_query("select * from $table",$conn);
for ($i = 0; $i < mysql_num_rows($result); $i++) {
    $dataArray[$i] = mysql_fetch_assoc($result);
}
foreach ($dataArray as $line) {
    fputcsv($file,$line);
}

fclose($file);

header("Content-Type: application/csv");
header("Content-Disposition: attachment;Filename=cars-models.csv");

// send file to browser
readfile($filename);
unlink($filename);
?>


除非特别声明,此稿为原稿转载请注明原文链接
原文地址: http://www.www100sucai.com/code/1245.html

浏览次数次

标签分类