Excel Import
Import การตั้งค่าวงเงินสวัสดิการพนักงานจากไฟล์ Excel (.xlsx) หลายพนักงานพร้อมกันในครั้งเดียว ระบบจะอ่านข้อมูลจาก Excel แล้วแทนที่ Config เดิมด้วยข้อมูลใหม่
Endpoint
POST /api/v1/open-apis/welfare/excel_importContent-Type: multipart/form-data
Request Body
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
_fileUpd | file | Yes | ไฟล์ Excel (.xlsx) | @/path/to/welfare_config.xlsx |
year | string | Yes | ปีสวัสดิการ (YYYY) | "2026" |
โครงสร้างไฟล์ Excel
ข้อมูลเริ่มที่ Row 3 (Row 1-2 เป็น Header)
Row 1: [Header Row - ไม่อ่านข้อมูล]
Row 2: [Header Row - ไม่อ่านข้อมูล]
Row 3: EMP001 | ... | ... | ... | ... | SAL_MED | ... | 5000 | 20000
Row 4: EMP002 | ... | ... | ... | ... | SAL_DEN | ... | 0 | 10000
...| Column | Field | Description |
|---|---|---|
| A | employee_code | รหัสพนักงาน (ต้องมีอยู่ในระบบ) |
| F | salary_type_code | รหัสประเภทสวัสดิการ (ต้องมีอยู่ในระบบ) |
| H | welfare_prev_amt | ยอดยกมาจากปีก่อน (ตัวเลข) |
| I | welfare_quota_amt | วงเงินสวัสดิการ (ตัวเลข) |
Validation Rules
| Rule | Description |
|---|---|
_fileUpd | ต้องแนบไฟล์มาด้วย |
year | ต้องไม่ว่างเปล่า (รูปแบบ YYYY) |
| ไฟล์ | ต้องเป็นไฟล์ .xlsx เท่านั้น |
| employee_code (Column A) | ต้องมีอยู่ในระบบ — ถ้าไม่พบจะข้ามรายการนั้น |
| salary_type_code (Column F) | ต้องมีอยู่ในระบบ — ถ้าไม่พบจะข้ามรายการนั้น |
Response Format
Success Response (HTTP 200)
{
"code": 200,
"message": "Import สำเร็จ",
"payload": {
"year": "2026",
"all_record": 50,
"insert_record": 45,
"update_record": 0,
"delete_record": 0,
"error_record": 5,
"import_log_file_path": "https://example.com/file-import/employee-welfares/20260327/ABCD1234.xlsx",
"error_log": "https://example.com/file-import/employee-welfares/20260327/ABCD1234_error_log.txt"
}
}Response Fields
| Field | Type | Nullable | Description |
|---|---|---|---|
year | string | No | ปีที่ Import |
all_record | integer | No | จำนวน Row ทั้งหมดที่อ่านได้ |
insert_record | integer | No | จำนวน Row ที่เพิ่มสำเร็จ |
update_record | integer | No | จำนวน Row ที่อัปเดต (ปัจจุบัน = 0 เสมอ) |
delete_record | integer | No | จำนวน Row ที่ลบ (= จำนวนที่ถูก replace) |
error_record | integer | No | จำนวน Row ที่ Error (ข้ามไป) |
import_log_file_path | string | Yes | URL ไฟล์ Excel ที่ upload ไว้ |
error_log | string | Yes | URL ไฟล์ Log ผลการ Import |
Error Response - Validation Failed (HTTP 422)
{
"code": 422,
"message": "Validation failed",
"errors": [
"'_fileUpd' file and 'year' are required"
]
}Error Response - Wrong File Type (HTTP 400)
{
"code": 400,
"message": "Exception File type not support"
}Error Response - Server Error (HTTP 400)
{
"code": 400,
"message": "Exception Cannot copy files"
}Code Examples
cURL
curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/welfare/excel_import" \
-H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
-F "year=2026" \
-F "_fileUpd=@/path/to/welfare_config_2026.xlsx"Notes
ข้อควรทราบ:
- ไฟล์ต้องเป็น
.xlsxเท่านั้น (ไม่รองรับ.xls,.csv) - ข้อมูลต้องเริ่มที่ Row 3 (Row 1-2 เป็น Header)
- ระบบจะ แทนที่ Config เดิม ก่อนสร้างใหม่เสมอ (Replace ไม่ใช่ Update)
- Row ที่ Column A ว่างจะถือเป็นสัญญาณหยุดอ่าน
- Row ที่ Column H และ I ว่างทั้งคู่จะถูกข้ามไป
- ตัวเลขใน Excel รองรับ comma separator เช่น
20,000.00
Related APIs
- Excel Template - ดาวน์โหลด template Excel พร้อม pre-fill ข้อมูลพนักงาน
- Import File Log - อัปโหลดไฟล์ + สร้าง import log (ยังไม่ประมวลผลข้อมูลในไฟล์)
- Import JSON - ส่งข้อมูลแถวที่ parse แล้วเป็น JSON เพื่อ import
- Update Multiple - อัปเดตหลายพนักงานผ่าน JSON แทน Excel
- List Welfare Employee By Type - ตรวจสอบผลหลัง Import
Last updated on