Google Sheet 编译客户详细信息和订单的公式
Google Sheet formula to compile customer details and orders
我正在为我的小型企业使用 Google 表格和 Google Sheet。我给我的客户一个 Google 表格,让他们输入他们的名字、phone 号码和他们的订单是什么,我可以在 Google [=32= 中查看我所有客户的订单] 表格回复。
An Example
但是,有时项目列表可能太多,我无法左右滚动,所以我创建了一个新的 sheet 并使用以下代码在单个单元格中编译了它们的详细信息和订单:
=FormResponses1!B2&char(10)&
FormResponses1!C2&char(10)&
IF(FormResponses1!D2>0,FormResponses1!D2&" - "&FormResponses1!D1&char(10), "")&
IF(FormResponses1!E2>0,FormResponses1!E2&" - "&FormResponses1!E1&char(10), "")&
IF(FormResponses1!F2>0,FormResponses1!F2&" - "&FormResponses1!F1&char(10), "")&
IF(FormResponses1!G2>0,FormResponses1!G2&" - "&FormResponses1!G1&char(10), "")&
IF(FormResponses1!H2>0,FormResponses1!H2&" - "&FormResponses1!H1&char(10), "")&
IF(FormResponses1!I2>0,FormResponses1!I2&" - "&FormResponses1!I1&char(10), "")&
IF(FormResponses1!J2>0,FormResponses1!J2&" - "&FormResponses1!J1&char(10), "")&
IF(FormResponses1!K2>0,FormResponses1!K2&" - "&FormResponses1!K1&char(10), "")&
IF(FormResponses1!L2>0,FormResponses1!L2&" - "&FormResponses1!L1&char(10), "")&
IF(FormResponses1!M2>0,FormResponses1!M2&" - "&FormResponses1!M1&char(10), "")&
IF(FormResponses1!N2>0,FormResponses1!N2&" - "&FormResponses1!N1&char(10), "")&
IF(FormResponses1!O2>0,FormResponses1!O2&" - "&FormResponses1!O1&char(10), "")&
至少要进行60行IF语句才能得到下图的结果
the result
问题是,当我向下拖动公式时,“FormResponses1!D1”(项目名称)变为“FormResponses1!D2”。所以我必须单独更改它们。除此之外,它还有效,但我想知道是否有更简单的方法来实现相同的结果。提前致谢!
为了不更改参考框架,请在列或行或两者前使用 $
:
$D1
D
$D
F4是快捷键
尝试:
=INDEX(SUBSTITUTE(B2:B&CHAR(10)&C2:C&CHAR(10)&SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(D2:Z="",,D2:Z&"×-×"&SUBSTITUTE(D1:Z1, " ", "×"))),,9^9))), " ", CHAR(10)), "×", " "))
如果你想把它做成一个脚本,你可以使用下面的代码。
它将更改格式,使其看起来更像下图,我觉得这样更吸引人。如果您使用此选项,请不要忘记更改“numberOfItems”值。
function ConsolidateInfoTwo() {
let sheet = SpreadsheetApp.openById('YOUR_SHEET_ID').getSheetByName('YOUR_SHEET_NAME');
let sheetDB = sheet.getRange(2,3,sheet.getMaxRows(),sheet.getMaxColumns()).getValues();
let numberOfItems = 20; //Change this to however many you have
let categoryAray = sheet.getRange(1,3,1,(numberOfItems+2)).getValues();
let itemCategories = categoryAray[0];
for (i=0;i<sheet.getLastRow();i++)
{
var info = "";
let currentData = sheetDB[i];
for (h=0;h<(numberOfItems+2);h++)
{
if (currentData[h] != '')
{
//If you don't want the items to come out as "Item 1: 3", you can change the order here
info += (itemCategories[h]+": "+currentData[h] + "\n");
}
sheet.getRange(i+2,1).setValue(info);
}
}
}
我正在为我的小型企业使用 Google 表格和 Google Sheet。我给我的客户一个 Google 表格,让他们输入他们的名字、phone 号码和他们的订单是什么,我可以在 Google [=32= 中查看我所有客户的订单] 表格回复。
An Example
但是,有时项目列表可能太多,我无法左右滚动,所以我创建了一个新的 sheet 并使用以下代码在单个单元格中编译了它们的详细信息和订单:
=FormResponses1!B2&char(10)&
FormResponses1!C2&char(10)&
IF(FormResponses1!D2>0,FormResponses1!D2&" - "&FormResponses1!D1&char(10), "")&
IF(FormResponses1!E2>0,FormResponses1!E2&" - "&FormResponses1!E1&char(10), "")&
IF(FormResponses1!F2>0,FormResponses1!F2&" - "&FormResponses1!F1&char(10), "")&
IF(FormResponses1!G2>0,FormResponses1!G2&" - "&FormResponses1!G1&char(10), "")&
IF(FormResponses1!H2>0,FormResponses1!H2&" - "&FormResponses1!H1&char(10), "")&
IF(FormResponses1!I2>0,FormResponses1!I2&" - "&FormResponses1!I1&char(10), "")&
IF(FormResponses1!J2>0,FormResponses1!J2&" - "&FormResponses1!J1&char(10), "")&
IF(FormResponses1!K2>0,FormResponses1!K2&" - "&FormResponses1!K1&char(10), "")&
IF(FormResponses1!L2>0,FormResponses1!L2&" - "&FormResponses1!L1&char(10), "")&
IF(FormResponses1!M2>0,FormResponses1!M2&" - "&FormResponses1!M1&char(10), "")&
IF(FormResponses1!N2>0,FormResponses1!N2&" - "&FormResponses1!N1&char(10), "")&
IF(FormResponses1!O2>0,FormResponses1!O2&" - "&FormResponses1!O1&char(10), "")&
至少要进行60行IF语句才能得到下图的结果
the result
问题是,当我向下拖动公式时,“FormResponses1!D1”(项目名称)变为“FormResponses1!D2”。所以我必须单独更改它们。除此之外,它还有效,但我想知道是否有更简单的方法来实现相同的结果。提前致谢!
为了不更改参考框架,请在列或行或两者前使用 $
:
$D1
D
$D
F4是快捷键
尝试:
=INDEX(SUBSTITUTE(B2:B&CHAR(10)&C2:C&CHAR(10)&SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(D2:Z="",,D2:Z&"×-×"&SUBSTITUTE(D1:Z1, " ", "×"))),,9^9))), " ", CHAR(10)), "×", " "))
如果你想把它做成一个脚本,你可以使用下面的代码。 它将更改格式,使其看起来更像下图,我觉得这样更吸引人。如果您使用此选项,请不要忘记更改“numberOfItems”值。
function ConsolidateInfoTwo() {
let sheet = SpreadsheetApp.openById('YOUR_SHEET_ID').getSheetByName('YOUR_SHEET_NAME');
let sheetDB = sheet.getRange(2,3,sheet.getMaxRows(),sheet.getMaxColumns()).getValues();
let numberOfItems = 20; //Change this to however many you have
let categoryAray = sheet.getRange(1,3,1,(numberOfItems+2)).getValues();
let itemCategories = categoryAray[0];
for (i=0;i<sheet.getLastRow();i++)
{
var info = "";
let currentData = sheetDB[i];
for (h=0;h<(numberOfItems+2);h++)
{
if (currentData[h] != '')
{
//If you don't want the items to come out as "Item 1: 3", you can change the order here
info += (itemCategories[h]+": "+currentData[h] + "\n");
}
sheet.getRange(i+2,1).setValue(info);
}
}
}