我有一个Google电子表格,其中记录了我的自由职业。我已经设置好了,每一行都计算是否付款。 (付款是从另一张纸上提取的。)
我想做的是生成一张发票,选择客户,然后列出该客户的所有未付费条目的清单。
使用数组过滤器功能可以完成这项工作,但是我不能将其用作发票,因为我需要下面的总行,并且希望使用与条目数匹配的表格格式。
是否可以将此类信息作为表格插入到Google文档中,或插入到表格中,以将数组后的行向下推?
我认为这将是一个足够简单的概念,但是我找不到能完全解决问题的任何东西。
答案 0 :(得分:1)
您可以尝试使用此脚本。我不确定最终结果是否是您想要的。如果不是这样,可以很容易地对其进行修改:
function onEdit(e) {
//If you change the Customer in the Invoice sheet, it runs the code
if (e.range.getA1Notation() == 'A1' && e.source.getSheetName() == 'Invoice'){
var sprsheet = SpreadsheetApp.getActiveSpreadsheet();
var invoice = sprsheet.getSheetByName("Invoice");
var times = sprsheet.getSheetByName("Times");
var in_customer = invoice.getRange("A1").getValue(); //Name you selected in the dropdown menu
var data = times.getRange("A1:H").getValues(); //All the data from the Time sheet
var total = 0;
//Loops through all the data looking for unpaid subtotals from that customer
for (var i = 0; i < data.length; i++){
/*> "i" represents the row, the second number is the column
> The rows start at 0 since it is the first array position.
*/
if (in_customer == data[i][2]) {
if (data[i][7] == 'N'){
total += Number(data[i][5]); //Accumulates each subtotal into total
invoice.appendRow([data[i][0], data[i][1], data[i][3], data[i][5]]);
}
}
}
invoice.appendRow(["Total: ","","", total]);
}
}
这导致(我更改了一些值进行测试)
如您所见,我添加了一些标题。
参考: