正在保存phpexcel目录以供下载?

正在保存phpexcel目录以供下载?,php,phpexcel,Php,Phpexcel,我如何让用户能够像下载文件那样选择保存文件的位置?您知道,下面是代码: echo date('H:i:s').' Set title row bold'.EOL; $objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); // Set autofilter echo date('H:i:s').' Set autofilter'.EOL; // Always include

我如何让用户能够像下载文件那样选择保存文件的位置?您知道,下面是代码:

echo date('H:i:s').' Set title row bold'.EOL;
$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);

// Set autofilter
echo date('H:i:s').' Set autofilter'.EOL;
// Always include the complete filter range!
// Excel does support setting only the caption
// row, but that's not a best practise...
$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()-           >calculateWorksheetDimension());

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace(__FILE__, 'C:/DOSTX.xlsx', __FILE__));

$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;

echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx',     pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;

// Echo memory usage

echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024)  , " MB" , EOL;

// Save Excel 95 file
echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
ECHO $filename= str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) ,     EOL;
echo date('H:i:s') , " File written to " , str_replace('.php', '.xls',    pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;

// Echo memory usage

echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024)  , " MB" , EOL;


// Echo memory peak usage

echo date('H:i:s').' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).'   MB'.EOL;

// Echo done
echo date('H:i:s').' Done writing files'.EOL;

echo "<script>alert('File saved at drive C')</script>";
echo date('H:i:s')。'Set title row bold'。下线;
$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
//设置自动过滤器
回显日期('H:i:s')。'Set autofilter'。下线;
//始终包括完整的过滤器范围!
//Excel只支持设置标题
//划船,但这不是最好的做法。。。
$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension());
//将活动工作表索引设置为第一张工作表,以便Excel将其作为第一张工作表打开
$objPHPExcel->setActiveSheetIndex(0);
//保存Excel2007文件
回显日期('H:i:s'),“写入Excel2007格式”,EOL;
$callStartTime=微时间(true);
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save(str_replace(_FILE__,'C:/DOSTX.xlsx',_FILE__));
$callEndTime=微时间(真);
$callTime=$callEndTime-$callStartTime;
回显日期('H:i:s'),“文件写入”,str_replace('.php','.xlsx',pathinfo('uuuu文件,pathinfo_基本名称)),下线;
echo“编写工作簿的调用时间为”,sprintf('%.4f',$callTime),“秒”,EOL;
//回显内存使用
回显日期('H:i:s'),'Current memory usage:',(memory\u get\u usage(true)/1024/1024),“MB”,下线;
//保存excel95文件
回显日期('H:i:s'),“写入Excel5格式”,EOL;
$callStartTime=微时间(true);
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');
$objWriter->save(str_replace('.php'、'.xls'、_文件));
$callEndTime=微时间(真);
$callTime=$callEndTime-$callStartTime;
ECHO$filename=str_replace('.php','.xlsx',pathinfo('.php',.xlsx',pathinfo('.php',pathinfo'.BASENAME)),EOL;
回显日期('H:i:s'),“文件写入”,str_replace('.php','.xls',pathinfo('uuuu文件,pathinfo_基本名称)),下线;
echo“编写工作簿的调用时间为”,sprintf('%.4f',$callTime),“秒”,EOL;
//回显内存使用
回显日期('H:i:s'),'Current memory usage:',(memory\u get\u usage(true)/1024/1024),“MB”,下线;
//回波存储器峰值使用率
回显日期('H:i:s')。'Peak memory usage:'(memory\u get\u Peak\u usage(true)/1024/1024)。'MB'.EOL;
//回音完成
回显日期('H:i:s')。'Done writing files'。EOL;
回显“警报('文件保存在驱动器C')”;
我以前做过很多标题,但不只是用phpoutput做的,但excel是不可接受的输出,excel文件无法读取为我想要的输出,请帮助我。

现在我明白了

替换:

$objWriter->save(str_replace('.php', '.xls', __FILE__));
与:


您必须删除所有输出,否则标题调用将失败。

我正在使用excel 2007,我应该使用哪些标题?phpexcel上的示例可以在其文件上工作,但当我为此复制它时,它就不工作了?我在10autofilter.phpsa上工作,本地保存或保存在服务器上?是本地,就像它执行文件时自动下载一样?我以前使用过phpoutput,但excel无法正确查看要使用的标题?或者如何正确使用phpoutput?用户的浏览器决定位置,你无法控制是的,他们控制,但我的意思是,当这个程序运行时,然后下载,然后由用户打开并保存,你知道,所以用户下载这个,抱歉,糟糕的英语直到无法正确查看我也尝试了01 Simple上的代码:(要添加,在我的查询$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension())下面有此代码;具体问题是什么?excel未正确查看,但输入不正确,但下载已经正常
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="your_name.xls"');
header('Cache-Control: max-age=0');


// This line will force the file to download
$objWriter->save('php://output');