메뉴 건너뛰기

프로그램언어

조회 수 20356 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
웹페이지 상의 문서를 엑셀이나, 파워포인트, 위드 문서로 변환해 줘야 되는 경우
만약에 엑셀 파일로 변환을 하고 싶으시면

PHP는
<?

header(\"Content-Type: application/vnd.ms-excel\");

?>

JSP는

<%@ page contentType="application/vnd.ms-excel; name='My_Excel'" %>
<%
response.setHeader("Content-Disposition", "inline; filename=myfile.xls");
response.setHeader("Content-Description", "JSP Generated Data");
%>

저 부분을 <HTML> 태그 앞에 넣으면 끝나지요.
저 페이지가 호출이 되면 오피스가 깔려있는 사용자들은 저장할것인지 그냥 열것인지를 물어보구여, 안깔려 있는 사용자들은 파일을 다운받을수 있게 되지요.


그럼 워드 파일은
<?
header(\"Content-Type: application/msword\");
?>

파워포인트 역시 같은 방법으로
<?
header(\"Content-Type: application/vnd.ms-powerpoint\");
?>


그럼 마지막으로 ASP에서는
<%
Response.Buffer = TRUE
Response.ContentType = \"application/vnd.ms-excel\"
%>


다음은 header 내용을 변경해서 excel로 바꾸어 주는 구문입니다.

* excel.php

<?php

header(\"Content-type: application/vnd.ms-excel\");

header(\"Content-Disposition: attachment; filename=test.xls\");

header(\"Content-Description: PHP4 Generated Data\");

?>

<html>

<body>

<table>

<tr>

<td>테스트1</td>

<td>테스트1</td>

<td>테스트1</td>

<td>테스트1</td>

</tr>

<tr>

<td>테스트2</td>

<td>테스트2</td>

<td>테스트2</td>

<td>테스트2</td>

</tr>

</table>

</body>

</html>



실행시켜보세요. 어떻게 되죠? test.xls 이름으로 excel 화일이 다운로드 되죠.

혹 DB내용을 excel형태로 출력해야될 때 유용할거 같습니다








[JSP] 쿼리결과를 엑셀로 추출
<%@ page contentType="application/vnd.ms-excel;charset=euc-kr" import="java.sql.*,java.text.*"%><%

response.setHeader("Content-Disposition", "inline; filename=myfile.xls"); // 파일 이름 지정
response.setHeader("Content-Description", "JSP Generated Data");

Connection con = null ;
Statement st = null ;
ResultSet rs = null ;


try{
con = ## 컨넥션 얻기 ##
st = con.createStatement();
rs = st.executeQuery("## 쿼리 ##");
ResultSetMetaData rsmd = rs.getMetaData();

%><html>
<body bgcolor=white>
<table border=1>
<tr bgcolor="#CACACA">
<% for ( int i = 1 ; i <= rsmd.getColumnCount() ; i ++ ) { %>

<th><%=rsmd.getColumnName(i)%></th>

<% } %>
</tr>
<%
while(rs.next()) {
%>
<tr>
<% for ( int i = 1 ; i <= rsmd.getColumnCount() ; i ++ ) { %>

<td><%

if ( rs.getString(rsmd.getColumnName(i)) == null ) {
out.print("");
} else {

out.print(rs.getString(rsmd.getColumnName(i)));
}

%></td>

<% } %>
</tr>
<% } %>
</table>
</body>
</html>
<%


} catch (Exception eee) {}
finally {
if ( rs != null ) rs.close();
if ( st != null ) st.close();
if (con != null ) con.close;
}
%>

List of Articles
번호 제목 날짜 조회 수
160 PHP의 유동변수!? - $a1 ~ $a2 같은 형식의 변수를 반복문 돌릴때... 2017.03.06 16610
159 PHP웹 보안 취약점 TOP5(웹해킹) 2023.01.12 292
158 PHP와 HTML과 자바스크립트의 관계 2021.03.26 311
157 PHP에서의 대칭 암호화/복호화 ― 간단한 예제에서 DB 입/출력까지 2018.09.14 3548
156 php에서 체크박스 선택한 것 보여주기 file 2019.01.08 1807
155 PHP에서 조건문 처리 2015.04.14 22038
154 PHP에서 자바스크립트 값 가져오기 2014.02.27 31635
153 PHP에서 자료, 데이터의 타입을 확인하는 방법, gettype() 2018.08.29 2465
152 PHP에서 암호화 encrypt 복호화 decrypt 해서 값을 넘기기 2018.02.09 10626
151 PHP에서 모든 세션 정보를 화면에 출력하는 방법 2018.08.29 2694
150 PHP에서 데이터를 엑셀(Excel)로 저장 2017.02.19 18428
149 PHP에서 UTF와 EUC-KR 변환 2019.02.19 1554
148 PHP에서 PDF파일 생성하기 2014.02.27 32777
147 PHP에서 Excel 파일을 만들 수 있는 PHPExcel file 2017.03.06 17112
146 PHP에서 CSV 파일 export file 2016.04.22 22335
145 PHP로 엑셀 자료 MySQL에 넣기 2017.03.06 17875
144 PHP로 Excel 파일 만들기... 2014.02.27 30257
143 php로 db 컨트롤 1 2017.03.06 15769
142 phpMyAdmin WebMysql 에 CSV 엑셀 파일 업로드 입력하기 ( Excel / Upload / data / 데이터 / 데이타 ) file 2021.03.25 760
141 phpexcel을 이용한 PHP로 엑셀파일 읽기와 생성 file 2017.03.06 22787
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved