refactor: add column commandCode
This commit is contained in:
parent
573a76448e
commit
803ba41a79
1 changed files with 8 additions and 24 deletions
|
|
@ -53,9 +53,10 @@ export async function exportToExcelPosition(data: DataPosition[]) {
|
||||||
{ header: "เลขที่คำสั่ง", key: "commandNo", width: 15 },
|
{ header: "เลขที่คำสั่ง", key: "commandNo", width: 15 },
|
||||||
{ header: "ปีเลขที่คำสั่ง", key: "commandYear", width: 12 },
|
{ header: "ปีเลขที่คำสั่ง", key: "commandYear", width: 12 },
|
||||||
{ header: "วันที่ลงนาม", key: "commandDateSign", width: 18 },
|
{ header: "วันที่ลงนาม", key: "commandDateSign", width: 18 },
|
||||||
{ header: "ประเภทคำสั่ง", key: "commandCode", width: 25 }, // AA
|
{ header: "ประเภทคำสั่ง", key: "commandCodeName", width: 25 }, // AA
|
||||||
{ header: "หมายเหตุ", key: "remark", width: 20 },
|
{ header: "หมายเหตุ", key: "remark", width: 20 },
|
||||||
{ header: "commandId", key: "commandId", width: 20 }, // AC (ลำดับที่ 29)
|
{ header: "commandId", key: "commandId", width: 20 }, // AC (ลำดับที่ 29)
|
||||||
|
{ header: "commandCode", key: "commandCode", width: 20 }, // AD (ลำดับที่ 30)
|
||||||
];
|
];
|
||||||
|
|
||||||
// 3. Map ข้อมูล
|
// 3. Map ข้อมูล
|
||||||
|
|
@ -86,9 +87,10 @@ export async function exportToExcelPosition(data: DataPosition[]) {
|
||||||
commandNo: e.commandNo,
|
commandNo: e.commandNo,
|
||||||
commandYear: e.commandYear ? Number(e.commandYear) + 543 : "",
|
commandYear: e.commandYear ? Number(e.commandYear) + 543 : "",
|
||||||
commandDateSign: date2Thai(e.commandDateSign),
|
commandDateSign: date2Thai(e.commandDateSign),
|
||||||
commandCode: store.convertCommandCodeName(e.commandCode),
|
commandCodeName: store.convertCommandCodeName(e.commandCode),
|
||||||
remark: e.remark,
|
remark: e.remark,
|
||||||
commandId: e.commandCode, // ใส่ค่าเริ่มต้นไว้
|
commandId: e.commandId,
|
||||||
|
commandCode: e.commandCode, // ใส่ค่าเริ่มต้นไว้
|
||||||
}));
|
}));
|
||||||
|
|
||||||
worksheet.addRows(newData);
|
worksheet.addRows(newData);
|
||||||
|
|
@ -97,24 +99,6 @@ export async function exportToExcelPosition(data: DataPosition[]) {
|
||||||
newData.forEach((_, index) => {
|
newData.forEach((_, index) => {
|
||||||
const rowIndex = index + 2;
|
const rowIndex = index + 2;
|
||||||
|
|
||||||
// --- ระบายสีเหลืองเข้ม (ถอด # ออกจาก ARGB) ---
|
|
||||||
["B", "O", "U", "V", "X", "Z"].forEach((col) => {
|
|
||||||
worksheet.getCell(`${col}${rowIndex}`).fill = {
|
|
||||||
type: "pattern",
|
|
||||||
pattern: "solid",
|
|
||||||
fgColor: { argb: "FFBF00" }, // ลบ # ออก
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- ระบายสีเหลืองอ่อน ---
|
|
||||||
["F", "G", "H", "N", "P", "Q", "R", "S", "T", "W", "Y"].forEach((col) => {
|
|
||||||
worksheet.getCell(`${col}${rowIndex}`).fill = {
|
|
||||||
type: "pattern",
|
|
||||||
pattern: "solid",
|
|
||||||
fgColor: { argb: "FFFFD7" }, // ลบ # ออก
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- ทำ Dropdown คอลัมน์ AA ---
|
// --- ทำ Dropdown คอลัมน์ AA ---
|
||||||
// อ้างอิงรายการจาก MasterData Sheet จะทำให้ Excel ทำงานได้เสถียรกว่า (กรณีรายการเยอะ)
|
// อ้างอิงรายการจาก MasterData Sheet จะทำให้ Excel ทำงานได้เสถียรกว่า (กรณีรายการเยอะ)
|
||||||
worksheet.getCell(`AA${rowIndex}`).dataValidation = {
|
worksheet.getCell(`AA${rowIndex}`).dataValidation = {
|
||||||
|
|
@ -123,9 +107,9 @@ export async function exportToExcelPosition(data: DataPosition[]) {
|
||||||
formulae: [`MasterData!$A$1:$A$${masterData.length}`],
|
formulae: [`MasterData!$A$1:$A$${masterData.length}`],
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- ผูกสูตรให้ commandId (AC) เปลี่ยนตามการเลือกใน AA ---
|
// --- ผูกสูตรให้ commandCode (AD) เปลี่ยนตามการเลือกใน AA ---
|
||||||
// AA คือประเภทคำสั่ง, AB คือหมายเหตุ, AC คือ commandId
|
// AA คือประเภทคำสั่ง, AD คือ commandCode
|
||||||
worksheet.getCell(`AC${rowIndex}`).value = {
|
worksheet.getCell(`AD${rowIndex}`).value = {
|
||||||
formula: `=IFERROR(VLOOKUP(AA${rowIndex}, MasterData!$A$1:$B$${masterData.length}, 2, FALSE), "")`,
|
formula: `=IFERROR(VLOOKUP(AA${rowIndex}, MasterData!$A$1:$B$${masterData.length}, 2, FALSE), "")`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue