메뉴 건너뛰기

프로그램언어

조회 수 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;
}
%>

  1. PHP 에서의 소켓(Socket) 통신

    Date2014.04.12 Views20395
    Read More
  2. PHP 세션에서 시작, 변수등록, 변수삭제, 부수기

    Date2014.03.26 Views19490
    Read More
  3. 어떤 스마트폰으로 접속했는지 알아내는 소스 , (안드로이드 아이폰 )

    Date2014.03.26 Views17716
    Read More
  4. PHP 소스 : 이미지 리사이즈, 섬네일

    Date2014.03.26 Views20704
    Read More
  5. 네이버 지도 api php버전

    Date2014.03.26 Views19434
    Read More
  6. Drag/Drop HTML elements

    Date2014.03.26 Views19535
    Read More
  7. 이미지 워터마크 구현

    Date2014.03.26 Views19667
    Read More
  8. 특수문자 없애는 정규표현식

    Date2014.03.26 Views21623
    Read More
  9. jQuery 개발자를 위한 메모 - 레퍼런스

    Date2014.03.26 Views19522
    Read More
  10. JSON and JavaScript usage

    Date2014.03.26 Views19064
    Read More
  11. jQuery 개발자를 위한 메모 - 플러그 인

    Date2014.03.26 Views19257
    Read More
  12. 웹에서 Excel 로 출력하기

    Date2014.03.26 Views20356
    Read More
  13. 웹페이지 프린트 하기 html 수준

    Date2014.03.26 Views19805
    Read More
  14. [PHP] 한글명 파일 다운로드받기

    Date2014.03.26 Views20551
    Read More
  15. FPDF - PHP로 PDF 만들기

    Date2014.02.27 Views21075
    Read More
  16. 해당하는 날짜가 그달의 몇주째인지 계산

    Date2014.02.27 Views26351
    Read More
  17. php 파일 다운로드 구현

    Date2014.02.27 Views19794
    Read More
  18. php 파일 확장자

    Date2014.02.27 Views20234
    Read More
  19. MYSQL 업데이트 두 번 하기

    Date2014.02.27 Views19729
    Read More
  20. mysql 에러 구문 표시

    Date2014.02.27 Views20349
    Read More
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved