/home/mjc1/public_html/j3demo/xls_write.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
<?php
include("./_common.php");

//echo "막혔음"; 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;

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}' and xls_left <> '' 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}' and xls_left <> '' 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']);
        
//$objPHPExcel->setActiveSheetIndex(0)->getRowDimension($info['xls_no'])->setRowHeight(21);
        
$objPHPExcel->setActiveSheetIndex($sheet_key)->setCellValue($alpha.$info['xls_no'], $info['xls_left']);
    }

    
//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']);

// 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

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

?>