Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.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
通过php创建excel文件并在android中下载_Php_Android_Android Asynctask_Phpexcel - Fatal编程技术网

通过php创建excel文件并在android中下载

通过php创建excel文件并在android中下载,php,android,android-asynctask,phpexcel,Php,Android,Android Asynctask,Phpexcel,使用phpExcel,已在服务器中创建excel文件 $objPHPExcel->setActiveSheetIndex(0); // Save Excel file in server $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('newrecord.xlsx'); 已将带有AsyncTask的类用作 @Override protected V

使用phpExcel,已在服务器中创建excel文件

$objPHPExcel->setActiveSheetIndex(0);
// Save Excel file in server
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('newrecord.xlsx');
已将带有AsyncTask的类用作

@Override
protected Void doInBackground(String... params) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://10.1.1.5/connect/createexcelreport.php");

    try {
        HttpResponse response = httpclient.execute(httppost);
        String responseString = EntityUtils.toString(response.getEntity());

        JSONObject jsonObj = new JSONObject(responseString);
        int success = jsonObj.getInt(TAG_SUCCESS);
        if (success==1){
            //file has been created. 
            //through browser, I can access it in http://10.1.1.5/connect/newreport.xlsx
任何人都可以在这个帖子中分享我如何在android中获得它。 我试过了

但它给出了文件未找到异常。 新手,请友善点


我已经找到了任何可能的解决办法。因此,请在标记重复之前比较问题,将文件保存到newrecord.xlsx这样的文件名,您正在将文件保存到运行PHP的Web服务器。如果您想将其作为响应直接发送到android设备的呼叫客户端,则需要将其保存到php://output 发送适当的标题

// Redirect output to a client’s web browser (Excel2007)
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');
exit;
// Redirect output to a client’s web browser (Excel2007)
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');
exit;