Home > other >  #gsheet export timesheet sheet in anual calendar view sheet
#gsheet export timesheet sheet in anual calendar view sheet

Time:07-23

I would like some help for pulling people time activity in a global annual sheet

The Purpose

Every week we report our time base on the activity and day of the week

The Goal

Because we do this each week, I would like to export the data in an annual sheet before rewrite the data for the next week of activity.

The source SheetName= 'Timesheet'

enter image description here

The Data exported

  1. In "A" The DATE of the time consumed from source (C:I)
  2. In "B" The ACTIVITY from source (A:A)
  3. In "C" The name of the people from source (B:B)
  4. In "D" The time consumed by the person for the activity on the specific day of year from source (C:I)

The destination SheetName= 'Anual_Timesheet'

enter image description here

Conclusion

Every week by the script I will be able to keep the data automatically exported and save time without doing manual error.

The File

The file for the purpose enter image description here

Code.gs

function saveTimeRecords() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet = spread.getSheetByName("Sheet1");
    let records = sheet.getRange(4,1,sheet.getLastRow()-3,sheet.getLastColumn()).getValues();
    let dates = records.shift();  // get the dates and remove from records
    dates = dates.slice(2,8); // get only the columns with dates
    records.shift(); // remove headers
    let archive = [];
    records.forEach( record => {
      for( let i=2; i<9; i   ) {
        if( record[i] !== "" ) {
          archive.push([dates[i-2],record[0],record[1],record[i]]);
        }
      }
    });
    sheet = spread.getSheetByName("Sheet2");
    sheet.getRange(sheet.getLastRow() 1,1,archive.length,archive[0].length).setValues(archive);
  }
  catch(err) {
    Logger.Log(err);
  }
}

References

  • Related