creating excel file via php and downloading it in android -
Using phpExcel, an Excel file is created in the server.
$ objPHPExcel-> SetActiveSheetIndex (0); // Save excel file to server $ objWriter = PHPExcel_IOFactory :: createWriter ($ objPHPExcel, 'Excel2007'); $ ObjWriter- & gt; Save ('newrecord.xlsx'); As a class with AsyncTask
@ Override is used as protected voice backbone (string ... parameter) {HTTP Client Httpclient = new DefaultHttpClient (); HttpPost httppost = New HttpPost ("http://10.1.1.5/connect/createexcelreport.php"); Try {HttpResponse response = httpclient.execute (httppost); String response string = EntityUtils.toString (response.getEntity ()); JSONObject jsonObj = New JSONObject (responseString); Int success = jsonObj.getInt (TAG_SUCCESS); If (success == 1) {// file has been created // via browser, I use it in http: //10.1.1.5/connect/newreport.xlsx Please share how I can get Android in this thread. I tried
if (success == 1) {InputStream data = response.getEntity () GetContent (); {Try OutputStream Output = New FileOpstream ("NewRecord .xlsx"); {Mimic bytestream (data, output); } Finally {Closeables.close (output, true); }} Finally {..............} but this file was not found an exception. Newbie, please be nice.
I have already searched for any possible solutions, so please compare queries before duplicate tagging
A file name like Newrecord.xlsx You are saving the file on the webserver where you are running PHP if you are calling it Android device), you can save it in the php: // output (sending the appropriate headers) Area is required. // Redirect output to a client's web browser (Excel 2007) header ('content-type: application / vnd.openxmlformats-officedocument.spreadsheetml.sheet'); Header ('content-dispute: attachment; filename = "01simple.xlsx"'); Header ('cache-control: max-age = 0'); $ ObjWriter = PHPExcel_IOFactory :: createWriter ($ objPHPExcel, 'Excel 2007'); $ ObjWriter- & gt; Save ('php: // output'); Go out;
Comments
Post a Comment