메뉴 건너뛰기

프로그램언어

조회 수 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. No Image 12Apr
    by
    2014/04/12 Views 20395 

    PHP 에서의 소켓(Socket) 통신

  2. No Image 26Mar
    by 조쉬
    2014/03/26 Views 20356 

    웹에서 Excel 로 출력하기

  3. No Image 27Feb
    by
    2014/02/27 Views 20349 

    mysql 에러 구문 표시

  4. No Image 12Apr
    by
    2014/04/12 Views 20341 

    jquery 이용 아이디 중복체크 실시간

  5. No Image 06Apr
    by
    2015/04/06 Views 20324 

    [PHP] 서버 운영하시는분 서버 꺼졌을때 메시지 띄우기

  6. No Image 14Apr
    by
    2015/04/14 Views 20297 

    fopen 파일 열기

  7. CodeIgniter에서 PHPExcel 사용하기

  8. No Image 27Feb
    by
    2014/02/27 Views 20234 

    php 파일 확장자

  9. No Image 23Dec
    by
    2016/12/23 Views 20223 

    깨진 한글 체크

  10. No Image 06Mar
    by
    2017/03/06 Views 20184 

    파일 업로드 (중복처리)

  11. No Image 14Apr
    by
    2015/04/14 Views 20157 

    MySQL DB 중복여부 검사하여 없는 것만 추가

  12. No Image 07Mar
    by
    2017/03/07 Views 20061 

    파일 이름에서 확장자 추출마스터

  13. No Image 23Dec
    by
    2016/12/23 Views 20051 

    정규표현식 매치를 수행 (preg_match)

  14. No Image 07Mar
    by
    2017/03/07 Views 19977 

    날짜 일수 차이 계산

  15. No Image 22Dec
    by
    2016/12/22 Views 19972 

    PHP Mcrypt 라이브러리를 활용한 암호화 시스템

  16. No Image 23Dec
    by
    2016/12/23 Views 19951 

    implode — 문자열로 배열 원소를 결합

  17. No Image 23Dec
    by
    2016/12/23 Views 19943 

    explode - 문자열 나눔

  18. No Image 23Dec
    by
    2016/12/23 Views 19881 

    class_exists 클래스가 정의되었는지 확인

  19. No Image 26Mar
    by
    2014/03/26 Views 19805 

    웹페이지 프린트 하기 html 수준

  20. No Image 27Feb
    by
    2014/02/27 Views 19794 

    php 파일 다운로드 구현

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved