Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何手动将数据保存到excel_Javascript_Php_Html_Mysql_Phpexcel - Fatal编程技术网

Javascript 如何手动将数据保存到excel

Javascript 如何手动将数据保存到excel,javascript,php,html,mysql,phpexcel,Javascript,Php,Html,Mysql,Phpexcel,如何使代码手动保存在excel中?因为到目前为止,在我的代码中,它会将过滤后的数据从mysql数据库传输到Excel文件……我如何在程序文件夹中手动保存,而不生成Excel文件,以便在数据中生成Excel报告 我的代码: <!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <?php require_once 'C:\xampp\

如何使代码手动保存在excel中?因为到目前为止,在我的代码中,它会将过滤后的数据从mysql数据库传输到Excel文件……我如何在程序文件夹中手动保存,而不生成Excel文件,以便在数据中生成Excel报告

我的代码:

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<?php
require_once 'C:\xampp\htdocs\test\Classes\PHPExcel\IOFactory.php';
$filename = 'file.xlsx';
mysql_connect("localhost","root","") or die ("cant connect!");
mysql_select_db("test") or die ("cant find database!");

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);

$objPHPExcel = $objReader->load($filename);
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);

$results = mysql_query("SELECT * FROM score");
while($row = mysql_fetch_assoc($results)){
}
$result = mysql_query("SELECT * FROM score");
if(isset($_POST['send'])){

$headings = array(
    'ID', 
    'NAME',
    'SCORE 1',
    'SCORE 2',
    'OTHER QUALITIES',
    'INTERVIEW',
    'TOTAL',
    'AIC',
    'BATCHCODE',
);
$objPHPExcel->getActiveSheet()->fromArray($headings, null, 'A1');
$row = 2;
while( $rows = mysql_fetch_row($result)){
   $objPHPExcel->getActiveSheet()->fromArray($rows, null, 'A' . $row);
   $row++;
}
echo 'saved';
header('Location: Index.php');
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($filename);
?>
<form id="form1" name="form1" method="post" action="" >
<input type="submit" name="send" value="send to excel" id="send" />
</form>
</body>
</html>

测试
我想做的是,如果我单击“发送到excel”(按钮)…将弹出一个excel保存对话框,以便将过滤后的数据保存到excel。

save('sphp://output');
<?php
if (!isset($_POST['send']) { ?>
    <!DOCTYPE html>
    <html>
    <head>
    <title>test</title>
    </head>
    <body>
<?php } else {
    require_once 'C:\xampp\htdocs\test\Classes\PHPExcel\IOFactory.php';
    $filename = 'file.xlsx';
    mysql_connect("localhost","root","") or die ("cant connect!");
    mysql_select_db("test") or die ("cant find database!");

    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objReader->setReadDataOnly(true);

    $objPHPExcel = $objReader->load($filename);
    $objWorksheet = $objPHPExcel->getActiveSheet();
    $objWorksheet = $objPHPExcel->setActiveSheetIndex(0);

    $result = mysql_query("SELECT * FROM score");
    if(isset($_POST['send'])){

        $headings = array(
            'ID', 
            'NAME',
            'SCORE 1',
            'SCORE 2',
            'OTHER QUALITIES',
            'INTERVIEW',
            'TOTAL',
            'AIC',
            'BATCHCODE',
        );
        $objPHPExcel->getActiveSheet()->fromArray($headings, null, 'A1');
        $row = 2;
        while( $rows = mysql_fetch_row($result)){
            $objPHPExcel->getActiveSheet()->fromArray($rows, null, 'A' . $row);
            $row++;
        }
    }

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="01simple.xlsx"');
    header('Cache-Control: max-age=0');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');
}
if (!isset($_POST['send']) { ?>
    <form id="form1" name="form1" method="post" action="" >
    <input type="submit" name="send" value="send to excel" id="send" />
    </form>
    </body>
    </html>
<?php }
} 如果(!isset($_POST['send']){?>
消除脚本或非php块中的所有回显或打印字符(例如
标记标记等);发送适当的标题,告诉浏览器需要Excel格式的文件,将文件保存到
php://output
…正如PHPExcel中的
示例/01简单下载xls.php
中所示distribution@Mark贝克:你能编辑我的代码吗?我只是一个新手程序员…我试过这个例子,但它会自动下载文件…我想如果我点击按钮,会弹出一个excel保存对话框,这样我就可以手动更改文件名了…你知道怎么做吗?解析错误:语法错误,在C:\xampp\htdocs\test\index.php的第2行出现意外的“{”错误…有错误吗