我在网上搜索了一下从数据电子表格建立报表的方法,好像是 谷歌数据工作室 和 谷歌表 是实现这一目标的一个选择。
尽管在LibreOffice Calc上有一定的经验,但我在Google Sheets和DataStudio上是新手。
我在Google Sheets的数据是。
我想建立的报告,其必须更新时,新的数据将到达谷歌表(比方说,每一天或左右)。
我只是彩色的字段名(objId; objDesc; objMore; objProgress; taskId; taskDesc; taskMore; event。),并将数据整理成电子表格,便于理解我想实现的目标。
欣赏你的帮助。
因此,基本上,你想生成一个报告,你的对象,任务和事件的层次结构,每当你点击一个按钮的描述顺序。
在这个解决方案中,我提供了最复杂的部分所需的代码,然后为其余步骤提供指导。
=iferror(ArrayFormula(lookup(unique(Sheet1!A1:A),Sheet1!A1:A,row(Sheet1!A1:A)+1)))
和
=iferror(ArrayFormula(lookup(unique(Sheet1!E2:E),Sheet1!E2:E,row(Sheet1!E2:E)+1)))
这些函数基本上会检测指定列(在我们的例子中是对象ID和任务ID的列)中任何值的变化,这将有助于生成报告。
对于这个数据。
这将是运行函数后生成的对象。
[{ObjectId=1.0, 1={TaskId=S02, Events=[[3242.0]], TaskMore=ppp, Description=ppp}, 0={TaskId=S01, Description=qqq, Events=[[1.0], [23.0], [324.0]], TaskMore=qqq}, ObjectMore=aaaa, ObjectDesc=aaaa, 2={TaskMore=lll, Events=[[3.0]], TaskId=S03, Description=lll}, ObjectProgress=0.7}, {3={Description=www, Events=[[43.0]], TaskMore=www, TaskId=T01}, 5={TaskId=T03, Events=[[5.0]], TaskMore=ttt, Description=ttt}, ObjectMore=bbbb, 4={Description=eee, TaskId=T02, TaskMore=eee, Events=[[54.0], [4.0]]}, ObjectDesc=bbbb, 6={Description=yyy, Events=[[345.0], [343.0]], TaskId=T04, TaskMore=yyy}, ObjectProgress=0.33, ObjectId=2.0}]
function myFunction() {
// Get sheets
var sheetData = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var sheetHelp = SpreadsheetApp.getActive().getSheetByName('Sheet2');
// This is the array where we will be storing our info
var Objects = []
// Get the ranges of values from our helper sheet that detect changes in that column
var ObjectIds = sheetHelp.getRange(2, 1,sheetHelp.getLastRow(),1).getValues().flat();
var TaskIds = sheetHelp.getRange(2, 2,sheetHelp.getLastRow(),2).getValues().flat();
// Delete all the blank elements in the flaten array of values
ObjectIds = ObjectIds.filter(item => item);
TaskIds = TaskIds.filter(item => item);
// Delete the last item as this would just be the change between a value and a blank cell
ObjectIds.pop();
TaskIds.pop();
// Lets iterate through all our main objects detected
for(i=0;i<ObjectIds.length;i++){
// for each object insert its details and information
Objects.push({
ObjectId: sheetData.getRange(parseInt(ObjectIds[i]), 1).getValue(),
ObjectDesc : sheetData.getRange(parseInt(ObjectIds[i]), 2).getValue(),
ObjectMore : sheetData.getRange(parseInt(ObjectIds[i]), 3).getValue(),
ObjectProgress : sheetData.getRange(parseInt(ObjectIds[i]), 4).getValue()
});
// for each object iterate through all its possible tasks
for(j=0;j<TaskIds.length;j++){
// get the last row value as for the last element of the tasks if we do not have anything it will
// have issues in the following if condition if this is null
var lastRow = sheetHelp.getLastRow();
ObjectIds.push(lastRow);
// If the task is within the object index range (i.e for an object between indices 8 and 12
// his tasks are those between these indices as well
if(TaskIds[j]<ObjectIds[i+1] && TaskIds[j]>=ObjectIds[i]){
TaskIds.push(lastRow);
// get all the events for this specific task checking that they are within the indices
// of the task itself (only events that are within the index boundaries of the task
var events = sheetData.getRange(TaskIds[j], 8,TaskIds[j+1]-TaskIds[j],1).getValues();
// add the new task object
Objects[i][j] = {
TaskId : sheetData.getRange(parseInt(TaskIds[j]),5).getValue(),
Description : sheetData.getRange(parseInt(TaskIds[j]),6).getValue(),
TaskMore : sheetData.getRange(parseInt(TaskIds[j]),7).getValue(),
Events : events
};
TaskIds.pop();
}
ObjectIds.pop();
}
}
}
myFunction
. 一旦你有了这个具有正确层次信息的对象数组,那么就看你想用它来生成报表的方式了。你可以
我希望这对你有所帮助。如果你还需要什么,或者你有什么不明白的地方,请告诉我 :)