๐Ÿšง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