/home/mjc1/public_html/j3demo/xls_merge.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
include("./_common.php");

//exit;

$f1['fname'] = "합본-khh-CWA Inspection Language 요청 190918-1.xls";
$f1['sheet'][0]['name'] = '255';
$f1['sheet'][0]['rows'] = 1;
$f1['sheet'][0]['cols'] = 1387;
$f1['sheet'][1]['name'] = '256';
$f1['sheet'][1]['rows'] = 1;
$f1['sheet'][1]['cols'] = 3031;
$f1['sheet'][2]['name'] = '257';
$f1['sheet'][2]['rows'] = 1;
$f1['sheet'][2]['cols'] = 637;
$f1['sheet'][3]['name'] = '258';
$f1['sheet'][3]['rows'] = 1;
$f1['sheet'][3]['cols'] = 442;
$xls_file[] = $f1;

$f2['fname'] = "합본-khh-CWA Stacking Language 요청 190918-1.xls";
$f2['sheet'][0]['name'] = '3';
$f2['sheet'][0]['rows'] = 1;
$f2['sheet'][0]['cols'] = 1856;
$f2['sheet'][1]['name'] = '255';
$f2['sheet'][1]['rows'] = 1;
$f2['sheet'][1]['cols'] = 978;
$f2['sheet'][2]['name'] = '256';
$f2['sheet'][2]['rows'] = 1;
$f2['sheet'][2]['cols'] = 2959;
$f2['sheet'][3]['name'] = '257';
$f2['sheet'][3]['rows'] = 1;
$f2['sheet'][3]['cols'] = 103;

$xls_file[] = $f2;

$f3['fname'] = "합본-khh-CWA Taping Language 요청 190918-2.xls";
$f3['sheet'][0]['name'] = '3';
$f3['sheet'][0]['rows'] = 1;
$f3['sheet'][0]['cols'] = 895;
$f3['sheet'][1]['name'] = '254';
$f3['sheet'][1]['rows'] = 1;
$f3['sheet'][1]['cols'] = 7985;
$f3['sheet'][2]['name'] = '255';
$f3['sheet'][2]['rows'] = 1;
$f3['sheet'][2]['cols'] = 2972;
$f3['sheet'][3]['name'] = '256';
$f3['sheet'][3]['rows'] = 1;
$f3['sheet'][3]['cols'] = 291;
$f3['sheet'][4]['name'] = '257';
$f3['sheet'][4]['rows'] = 1;
$f3['sheet'][4]['cols'] = 711;
$f3['sheet'][5]['name'] = '258';
$f3['sheet'][5]['rows'] = 1;
$f3['sheet'][5]['cols'] = 910;
$xls_file[] = $f3;

$f4['fname'] = "합본-khh-CWA Unloader Language 요청 190918-1.xls";
$f4['sheet'][0]['name'] = '255';
$f4['sheet'][0]['rows'] = 1;
$f4['sheet'][0]['cols'] = 889;
$f4['sheet'][1]['name'] = '256';
$f4['sheet'][1]['rows'] = 1;
$f4['sheet'][1]['cols'] = 649;
$xls_file[] = $f4;

$idx 3;

$fp fopen($j3['j3_data_path']."/paylog/xls.txt",'a');
chmod($j3['j3_data_path']."/paylog/xls.txt",0707);

require_once 
$j3_lib_path."/phpexcel/PHPExcel.php";

$objPHPExcel = new PHPExcel();

foreach(
$xls_file[$idx]['sheet'] as $sheet_key=>$val){

    
$objPHPExcel->createSheet();

    
$alpha_array null;
    
$info_array null;

    
$objPHPExcel->setActiveSheetIndex($sheet_key);

    
$sql "select xls_alpha from xls_reader where xls_file = '{$idx}' and xls_sheet = '{$sheet_key}' group by xls_alpha";
    
$res mysql_query($sql,$connect_j3);
    while(
$info=mysql_fetch_array($res)){
        
$alpha_array[] = $info;
    }

    
$sql "select * from xls_reader where xls_file = '{$idx}' and xls_sheet = '{$sheet_key}' order by xls_no, xls_alpha ";
    
$res mysql_query($sql,$connect_j3);

    while(
$info=mysql_fetch_array($res)){
        
$info_array[] = $info;
    }

    foreach(
$alpha_array as $key=>$info){
        
$alpha chr(64+$info['xls_alpha']);
        
$objPHPExcel->getActiveSheet()->getColumnDimension($alpha)->setAutoSize(true);
    }

    
$cnt=0$update_cnt 0;
    foreach(
$info_array as $key=>$info){
        
$alpha chr(64+$info['xls_alpha']);

        
$v "";
        if(
$info['xls_conv']!=''){
            
$v $info['xls_conv'];
        } else if(
$info['xls_content']!=''){
            
$v $info['xls_content'];
        }
        if(
substr($v,0,1)=="="){ $v =  " ".$v; } // 내용 첫글자가 =가 있으면 엑셀생성시 에러남

        /*$content = $sheet_key."-".$alpha."-".$info['xls_no'].":".$v.chr(10);
        //fwrite($fp,$content);*/

        //$objPHPExcel->setActiveSheetIndex(0)->getRowDimension($info['xls_no'])->setRowHeight(21);
        
$objPHPExcel->setActiveSheetIndex($sheet_key)->setCellValue($alpha.$info['xls_no'], $v);
    }

    
$content "시트한개 처리 : ".$xls_file[$idx]['sheet'][$sheet_key]['name'].chr(10);
    
fwrite($fp,$content);

    
//echo $xls_file[$idx]['sheet'][$sheet_key]['name'];
    
$objPHPExcel->getActiveSheet()->setTitle($xls_file[$idx]['sheet'][$sheet_key]['name']);
    
}

    
$xls_file[$idx]['fname'] = iconv("utf-8","euc-kr",$xls_file[$idx]['fname']);

    
$content "파일명 : ".chr(10);
    
fwrite($fp,$content);

// Redirect output to a client’s web browser (Excel5)
    
header('Content-Type: application/vnd.ms-excel');
    
header('Content-Disposition: attachment;filename="'.$xls_file[$idx]['fname'].'"');
    
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

    
$content "마무리 : ".chr(10);
    
fwrite($fp,$content);

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

    
$content "끝 : ".chr(10);
    
fwrite($fp,$content);

?>