Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Notice: Undefined index: include in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php on line 351

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 145

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Notice: Undefined index: visitedfid in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/forum.func.php on line 110

Notice: Undefined index: visitedfid in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/forum.func.php on line 122

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Notice: Undefined index: allowreply in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/viewthread.php on line 345

Notice: Undefined index: allowpost in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/viewthread.php on line 346
AbyssalSwamp 定制与源代码Technology Exchange - Case Board(C版) - using chatGPT develop - php export,合计编写了28个版本 - www.caffz.com
AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 冻结用户(激活) | Residents
Notice: Undefined index: links in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/forumdata/templates/1_header.tpl.php on line 59

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
       
Title: using chatGPT develop - php export,合计编写了28个版本  
  This topic was added by com at 2024-11-22 11:53 移动 
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3867
码币MB 2624 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
using chatGPT develop - php export,合计编写了28个版本

最终取第28号版本进行了编辑与修改。内容就寄放如下。


<?
//Version 28.1

// 引入 PHPExcel 库
require_once '/PHPExcel-1.8/PHPExcel-1.8/Classes/PHPExcel.php';

$servername = "";
$username = "";
$password = "";
$dbname = "";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检测连接是否成功
if ($conn->connect_error) {
  die("连接失败: " . $conn->connect_error);
}

// 计算出30天前的日期
$thirtyDaysAgo = date('Y-m-d', strtotime('-30 days'));

$sql = "SELECT p.author, p.pid, p.tid, p.dateline, p.message
        FROM dz41_posts AS p
        INNER JOIN dz41_threads AS t ON p.tid = t.tid AND p.author = t.author
        WHERE t.typeid=12 AND p.dateline >= '{$thirtyDaysAgo}'
        ORDER BY p.author ASC, p.dateline ASC";
$result = $conn->query($sql);

// 创建一个新的 Excel 文件
$objPHPExcel = new PHPExcel();

// 设置文件属性
$objPHPExcel->getProperties()
    ->setCreator("Your Name")
    ->setLastModifiedBy("Your Name")
    ->setTitle("MySQL Export")
    ->setSubject("MySQL Export")
    ->setDescription("MySQL Export");

$rowIndex = 2;
$currentAuthor = null;

// 添加标题行
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'pid');
$objPHPExcel->getActiveSheet()->setCellValue('B1', '版面');
$objPHPExcel->getActiveSheet()->setCellValue('C1', '星期'); // 添加星期几标题
$objPHPExcel->getActiveSheet()->setCellValue('D1', '时间');
$objPHPExcel->getActiveSheet()->setCellValue('E1', '内容');
$objPHPExcel->getActiveSheet()->setCellValue('F1', '备注');

if ($result && mysqli_num_rows($result) > 0) {
    while($row = $result->fetch_assoc()) {
        $author = $row["author"];

        // 当作者发生变化时,添加新的一行表示该作者的信息
        if ($author != $currentAuthor) {
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $rowIndex, "Author: " . $author);
            $rowIndex++;
            $currentAuthor = $author;
        }

        // 将值写入当前工作表
        $dateTime = date('Y-m-d H:i:s', $row["dateline"]);
        $weekday = date('N', strtotime($dateTime)); // 获取星期几
        $objPHPExcel->getActiveSheet()->setCellValue('A' . $rowIndex, $row["pid"]);
        $objPHPExcel->getActiveSheet()->setCellValue('B' . $rowIndex, $row["tid"]);
        $objPHPExcel->getActiveSheet()->setCellValue('C' . $rowIndex, $weekday); // 写入星期几
        $objPHPExcel->getActiveSheet()->setCellValue('D' . $rowIndex, $dateTime);
        $objPHPExcel->getActiveSheet()->setCellValue('E' . $rowIndex, $row["message"]);

        $rowIndex++;
    }
}

// 设置列宽自适应
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);

// 设置 HTTP 头信息,输出 Excel 文件
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="mysql_export.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

?>

[ 本帖最后由 sky999 于 2023-5-23 18:19 编辑 ]

Notice: Undefined variable: relatedkeywords in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/forumdata/templates/1_viewthread.tpl.php on line 208




CAFFZ.com
2023-5-23 18:08#1
View profile  Blog  Send a short message  Top
       


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2025-8-31 17:09 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE
 


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/urlcheck.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/urlcheck.php on line 2