Przeglądaj źródła

新增 寫入專案工具

manto07m 3 lat temu
rodzic
commit
7ec7accca9
2 zmienionych plików z 33 dodań i 1 usunięć
  1. 32 0
      insert_project.php
  2. 1 1
      script/php/excel/read_excel.php

+ 32 - 0
insert_project.php

@@ -0,0 +1,32 @@
+<?php
+include("./script/php/permission/connect_sql.php");
+include("./script/php/excel/read_excel.php");
+
+$data = $excelData["工作表1"];
+
+for ($i = 1; $i < count($data); $i++) {    
+    $sql = "INSERT INTO [21000X].[dbo].[Project_Table_Test]
+               ([year]
+               ,[projectID]
+               ,[projectName]
+               ,[department]
+               ,[technician]
+               ,[engineer]
+               ,[proprietor]
+               ,[projectDate])
+         VALUES
+               (?,?,?,?,?,?,?,?);";
+    $stmt = sqlsrv_query($conn, $sql, array($data[$i][0],$data[$i][1],$data[$i][2],$data[$i][3],$data[$i][4],$data[$i][5],$data[$i][6],$data[$i][7]));
+
+}
+if ($stmt === false) {
+    if (($errors = sqlsrv_errors()) != null) {
+        foreach ($errors as $error) {
+            echo "SQLSTATE: " . $error['SQLSTATE'] . "<br />";
+            echo "code: " . $error['code'] . "<br />";
+            echo "message: " . $error['message'] . "<br />";
+        }
+    }
+}else{
+    echo('success');
+}

+ 1 - 1
script/php/excel/read_excel.php

@@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 
 $excelData = array();
-$file = "./assets/excels/公司人員資料.xlsx";
+$file = "./assets/excels/計畫編號.xlsx";
 
 $extension = pathinfo($file, PATHINFO_EXTENSION);