MySQL에서 데이터를 내보내고 파일을 내보내려고합니다. 파일이 안드로이드 장치에 다운로드 파일을 만들 자마자. 내가 만들이 코드에 의해 파일을 엑셀 :mysql에서 데이터를 내보내 엑셀로 다운로드하여 android를 통해 다운로드
$result = mysql_query("SELECT * FROM `tbl_notes` WHERE `user_id` = '$user_id' ") or
die(mysql_error());
include_once ("jdf.php");
$date = jdate('Y/n/j');
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$date.xls");
header("Pragma: no-cache");
header("Expires: 0");
$sep = "\t";
while ($row = mysql_fetch_row($result)) {
$schema_insert = "";
for ($j = 0; $j < mysql_numfields($result); $j++) {
if (!isset($row)) {
$schema_insert .= "NULL" . $sep;
} else
if ($row[$j] != "") {
$schema_insert .= "$row[$j]" . $sep;
} else {
$schema_insert .= "" . $sep;
}
}
$schema_insert = str_replace($sep . "$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print (trim($schema_insert));
print "\n";
}
내가 PHP 코드에서 파일을 다운로드 안드로이드 장치를 강제하는 방법을 모르겠어요. 덕분에 . 귀하의 질문에
안드로이드 애플 리케이션에서 http 연결로 명령을 보내고 json.my로 데이터를 수신하는 방법은 생성 된 Excel 파일을 다운로드하는 방법입니다. –
코드에 관한 특정 질문이있는 경우 코드를 게시하십시오. Json은 데이터를 구조화하기위한 텍스트 기반 표기법입니다. 그러나 텍스트 파일이 아닌 Excel 파일을 다운로드하려고합니다. 따라서 바이너리 데이터를 처리해야합니다. [Here] (http://stackoverflow.com/questions/6660243/how-do-i-use-httpclient-in-java-to-retrieve-a-binary-file) HttpClient를 사용하여이 작업을 수행하는 예제를 찾을 수 있습니다. . [Here] (http://stackoverflow.com/questions/3221979/reading-binary-file-from-urlconnection) URLConnection 클래스를 사용하여 파일을 다운로드하는 예제도 있습니다. – joel