我得到了下面的代碼,它沒有按應有的方式繪制值。
我們的想法是旋轉它,以某種方式為第 4 行中的每個日期重復一組產品、數量和其他資訊,以創建一個類似資料庫的表。
function salvarPrevProducao() {
const srcSheetName = "Previs?o Entreposto"; // This is the source sheet name.
const dstSheetName = "DB"; // Please set the destination sheet name.
// This is from https://stackoverflow.com/a/44563639
Object.prototype.get1stNonEmptyRowFromBottom = function (columnNumber, offsetRow = 1) {
const search = this.getRange(offsetRow, columnNumber, this.getMaxRows()).createTextFinder(".").useRegularExpression(true).findPrevious();
return search ? search.getRow() : offsetRow;
};
// 1. Retrieve values from the source sheet.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const srcSheet = ss.getSheetByName(srcSheetName);
const lastRow = srcSheet.get1stNonEmptyRowFromBottom(1);
const [[, , , ...header1], header2, ...srcValues] = srcSheet.getRange("A4:M" lastRow).getValues();
Logger.log('Header1: ' header1)
Logger.log('Header2: ' header2)
// 2. Create an array for putting to the destination sheet.
const values = header1.reduce((ar, h, i) => {
srcValues.forEach(([a, b, c, ...dm]) => ar.push([h, a, b, c, dm[i] || 0, "", dm.pop(), h]));
return ar;
}, [["Data", "Tipo", "Cod", "Descri??o", "Qtd", "Usuário", "TimeStamp", "Semana"]]);
// 3. Put the array to the destination sheet.
const dstSheet = ss.getSheetByName(dstSheetName);
dstSheet.getRange(dstSheet.getLastRow() 1, 1, values.length, values[0].length).setValues(values);
}
以下是處理前的資料:

結果應該是這樣的:

這是電子表格的鏈接:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/394852.html
上一篇:在輸入日期和輸入后啟用btn
