/home/mjc1/public_html/emillennium/sale_buy_xls.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
$dir 
".";
include_once(
$dir."/_common.php");

if(
$eid==''){
    
alert('e천년경영 로그인 후에 이용가능합니다.',"index.php"); exit;
}

$where " ";

$sql "select a.pname, a.pnorm, b.unit, a.qty, a.price, a.sup_amt, a.vat, a.tot_amt, b.tax_yn, a.remarks, ifnull(a.taxno,'') as taxno, a.data_created  from {$mode}_d a left join product_m b on a.pcode = b.code where midx = '{$midx}' ";
$result      =    mysql_query($sql,$connect_e1000y);
//echo $sql; exit;

while($cus_info=mysql_fetch_array($result)){
    
$list_array[] = $cus_info;
}

//_pr($list_array); exit;

//echo dirname(__FILE__) . '/lib/phpexcel/PHPExcel.php';
require_once dirname(__FILE__) . '/lib/phpexcel/PHPExcel.php';

$objPHPExcel = new PHPExcel();

/*$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->getAlignment()->setWrapText(true); // 워드랩 기능 추가
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);*/


$title_array = Array("상품명","규격","단위","수량","단가","공급가액","부가세","합계금액","과세구분","비고","계산서번호","자료등록일시");

for(
$i=0;$i<count($title_array);$i++){
    if(
$i>25){
        
$vv floor($i/26);
        
$v $i-(26*$vv);
        
$alpha chr(65+$v);
        
$alpha chr(64+$vv).$alpha;
    } else {
        
$alpha chr(65+$i);
    }
    
$objPHPExcel->setActiveSheetIndex(0)
            ->
setCellValue($alpha.'1'$title_array[$i]);
    
$objPHPExcel->getActiveSheet()->getColumnDimension($alpha)->setAutoSize(true);
    
$objPHPExcel->getActiveSheet()->getColumnDimension($alpha)->setAutoSize(true);
}

for(
$i=0;$i<count($list_array);$i++){
    
$it $list_array[$i];
    
$x 0;
    
$xx 0;
    foreach(
$it as $key => $val){
        if(
$xx%2==0){
            if(
$x>25){
                
$vv floor($x/26);
                
$v $x-(26*$vv);
                
$alpha chr(65+$v);
                
$alpha chr(64+$vv).$alpha;
            } else {
                
$alpha chr(65+$x);
            }

            if(
$key=='8'){
                if(
$val=='0'){ $val "면세품"; } else if($val=='1') { $val "과세품"; } else if($val=='1'){ $val "영세품"; }
            }

            
$objPHPExcel->setActiveSheetIndex(0)
                ->
setCellValue($alpha.($i+2), $val);
            
$x++;
        }
        
$xx++;
    }
}

$objPHPExcel->getActiveSheet()->setTitle('customers');
$objPHPExcel->setActiveSheetIndex(0);

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$mode.'_xls_'.date("Ymd",time()).'.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter PHPExcel_IOFactory::createWriter($objPHPExcel'Excel5');
$objWriter->save('php://output');

?>