๐งapp.writeAwardList()
/**
* app.writeAwardList()
* ====================
* ไธป่ฆๅ่ฝ๏ผๅฐๅ็ๅๅฎๅฏซๅ
ฅใๅพ็ๅๅฎใ้ ้ข
*/
app.writeAwardList = function() {
/* ------------------------ ๆบๅ Sheet --------------------------- */
// ใๅ็ญๅนณๅใ้ ้ข
let sheet = app.sheet.byName('ๅพ็ๅๅฎ');
sheet.clear();
/* ------------------------ ๆบๅ Data --------------------------- */
const award = app.award; // ็้
let data = [
['็ทจ่', '็ญ็ด', 'ๅงๅ', 'ๆฅๅธธ็ๆดป่กจ็พ', 'ๅญธๆฅญ็ธฝๅนณๅ', '้้ก', '่็ซ ๆ็ฐฝๅ']
];
app.awardList.forEach((s, i) => {
data.push([i+1, s.classNo, s.name, '่กจ็พๅช็ง', s.average, award, '']);
});
const rows = data.length;
const cols = data[0].length;
/* ------------------------ ่จญๅฎไธปๆจ้ก --------------------------- */
sheet.getRange(1,1).setFormula('="่บๅๅธ "&Year&" ๅญธๅนดๅบฆ็ฌฌ "&Semester&" ๅญธๆ้ซ็ดไธญ็ญๅญธๆ กๅญธ็็ๅญธ้ๅฐ้ ๆธ
ๅ"');
sheet.getRange(2,1).setValue(`ๆ กๅ๏ผ่บๅๅธ็ซ้ฝๆ้ซ็ดไธญๅญธ`);
/* ------------------------ ๅฏซๅ
ฅ Data --------------------------- */
const r0 = 4;
app.sheet.writeData('ๅพ็ๅๅฎ', data, r0, 1);
/* ------------------------ ๅฏซๅ
ฅ่กจๅฐพ --------------------------- */
const n = rows - 1; // ็ธฝไบบๆธ
const total = n * +award; // ๅ่จ็ธฝ้้ก
const junior = (+app.semester === 2) ? `๏ผไธๅนด็ดไธๅญธๆๅ้กไฝตๅ
ฅๆฌๅญธๆ๏ผ็ฐๆฏ็ญๅ้
2 ๅ` : '';
const footer = [
[`ๅ่จ็ธฝไบบๆธ๏ผ${n}`, '', '', `ๅ่จ็ธฝ้้ก๏ผ${total}`, '', '', ''],
[`ๅญธๆ ก็ธฝไบบๆธ๏ผ`, '', '', `ๅญธๆ ก็ธฝ็ญ็ดๆธ๏ผ`, '', '', ''],
['', '', '', '', '', '', ''],
['ๆฟ่พฆไบบ๏ผ', '', '', '่จปๅ็ต้ท๏ผ', 'ๆๅไธปไปป๏ผ', '', 'ๆ ก้ท๏ผ'],
['', '', '', '', '', '', ''],
['', '', '', '', '', '', ''],
['ๅบ็ด๏ผ', '', '', 'ไธป่จไบบๅก๏ผ', 'ๆ่จไธปไปป๏ผ', '', '',],
['', '', '', '', '', '', ''],
['', '', '', '', '', '', ''],
['โญ๏ธ ๆฌ่กจๅกซๅฆฅๅพ๏ผ่ซๆ ธ็ซ ใ', '', '', '', '', '', ''],
[`โญ๏ธ ไบใไธๅนด็ดๆฏ็ญๅ้
1 ๅ${junior}ใ`, '', '', '', '', '', ''],
];
app.sheet.writeData('ๅพ็ๅๅฎ', footer, r0+rows+1, 1);
/* ------------------------ ็ฏๅ (Range) --------------------------- */
const tableRange = sheet.getRange(r0, 1, rows, cols);
const tableHeader = sheet.getRange(r0, 1, 1, cols);
const avgColumn = sheet.getRange(r0+1, 5, rows-1, 1);
const tableFooter = sheet.getRange(r0+rows+1, 1, footer.length, footer[0].length);
const A1 = sheet.getRange(1,1);
/* ------------------------ ๅฐ้ฝ --------------------------- */
app.range.alignCenter(tableRange);
app.range.alignCenter(A1);
tableFooter.setHorizontalAlignment('left'); // ้ ๅทฆ
/* ------------------------ ๆก็ท --------------------------- */
app.range.setBorder(tableRange, BorderStyle.allThin);
/* ------------------------ ่จญๅฎ่ๆฏ --------------------------- */
tableHeader.setBackground('#eeeeee');
/* ------------------------ ่จญๅฎๆธๅญๆ ผๅผ --------------------------- */
avgColumn.setNumberFormat('0.00');
/* ------------------------ ๅ
ถไป่จญๅฎ --------------------------- */
app.sheet.trim(sheet); // ๅช้คๅค้ค็ๆฌไฝ
sheet.setColumnWidths(1, 2, 40); // ็ทจ่ ็ญ็ด
sheet.setColumnWidths(3, 1, 60); // ๅงๅ
sheet.setColumnWidths(4, 1, 100); // ๆฅๅธธ็ๆดป่กจ็พ
sheet.setColumnWidths(5, 1, 80); // ๅญธๆฅญ็ธฝๅนณๅ
sheet.setColumnWidths(6, 1, 60); // ้้ก
sheet.setColumnWidths(7, 1, 120); // ่็ซ ๆ็ฐฝๅ
sheet.getRange(1, 1, 1, cols).mergeAcross(); // ๅไฝตๅฒๅญๆ ผ๏ผไธปๆจ้ก๏ผ
}
Last updated