-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
55 lines (45 loc) · 1.26 KB
/
index.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
<?php
include 'PHPExcel/Classes/PHPExcel.php';
convertXLStoCSV('Domestic_Import_PO_Report_(04-10-2019) (1).xls','output.csv');
function convertXLStoCSV($infile,$outfile)
{
$fileType = PHPExcel_IOFactory::identify($infile);
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($infile);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->save($outfile);
copy($outfile, 'output/'.$outfile);
unlink($outfile);
}
$i=0;
$file = fopen('output/output.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
//$line[0] = '1004000018' in first iteration
$fileinfo[$i]=$line;
$i++;
}
fclose($file);
unset($fileinfo[0]);
unset($fileinfo[1]);
unset($fileinfo[2]);
// print_r( $fileinfo);
$fp = fopen('file.csv','w');
$list=$fileinfo;
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
$file = fopen('file.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
//$line[0] = '1004000018' in first iteration
$fileinfo[$i]=$line;
$i++;
}
unset($fileinfo[3]);
foreach ($fileinfo as $value) {
echo "INSERT INTO table_name (column1, column2, column3)
VALUES ($value[0],$value[1], $value[2])";
echo "<br>";
}
?>