[ 첨부된 파일들은 엑셀을 읽는데에 도움을 주는 라이브러리들이다. ]
1. Excel 파일 보내기(excelUpload.php)
<!DOCTYPE html>
<html>
<head>
<title>Excel Uploading PHP</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>Excel Upload</h1>
<form method="POST" action="upload_test.php" enctype="multipart/form-data">
<div class="form-group">
<label>Upload Excel File</label>
<input type="file" name="file" class="form-control">
</div>
<div class="form-group">
<button type="submit" name="Submit" class="btn btn-success">Upload</button>
</div>
<p>Download Demo File from here : <a href="demo.ods">Demo.ods</a></p>
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['Submit']))
{
$mimes = ['application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
if(in_array($_FILES["file"]["type"],$mimes))
{
$uploadFilePath = "uploads/reply.xlsx";
if(file_exists($uploadFilePath))
unlink($uploadFilePath);
move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath);
echo "<br/>파일 업로드 성공";
}
else
{
die("<br/>엑셀 파일을 선택해주세요.");
}
}
?>
2. Excel 파일 읽기
<?php
// If you need to parse XLS files, include php-excel-reader
require('./excel_reader2.php');
require('./SpreadsheetReader.php');
$uploadFilePath = "uploads/reply.xlsx";
$Reader = new SpreadsheetReader($uploadFilePath);
$totalSheet = count($Reader->sheets());
echo "<br/>You have total ".$totalSheet." sheets".
$html="<table border='1'>";
$html.="<tr><th>Title</th><th>Description</th></tr>";
/* For Loop for all sheets */
for($i=0;$i<$totalSheet;$i++)
{
$Reader->ChangeSheet($i);
foreach ($Reader as $Row)
{
echo $Row[0];
$html.="<tr>";
$title = isset($Row[0]) ? $Row[0] : '';
$description = isset($Row[1]) ? $Row[1] : '';
$html.="<td>".$title."</td>";
$html.="<td>".$description."</td>";
$html.="</tr>";
//$query = "insert into items(title,description) values('".$title."','".$description."')";
//$mysqli->query($query);
}
}
$html.="</table>";
echo $html;
?>
'일상 > 기본' 카테고리의 다른 글
데이터 클러스터링(30분 공부하기) (0) | 2019.03.28 |
---|---|
c# winhttp 유니코드 에러 (0) | 2019.03.27 |
IT상식) 프레임워크란 (0) | 2019.03.26 |
아마존 AWS 공부하기(30분) (0) | 2019.03.26 |
Git 명령어 (0) | 2019.03.23 |