将以上数据保存在Google Sheet sheet1的单个单元格中。需要将其带到sheet2中的各个col。
categories: ScreenGuard item_meta: {'Brand': 'Lenovo', 'Series': 'Z', 'Model': '7r883', 'Length (mm)': '134', 'Width (mm)': '132', 'Total Area (sq mm)': '17688', '_measurement_data': '{"length":"{\\"value\\":\\"134\\",\\"unit\\":\\"mm\\"}","width":"{\\"value\\":\\"132\\",\\"unit\\":\\"mm\\"}","_measurement_needed":"17688","_measurement_needed_unit":"sq mm"}'} line_subtotal: 176.88 line_subtotal_tax: 0.00 line_tax: 0.00 line_total: 176.88 name: Screen Guard product_id: 10 quantity: 1 sku: tags: tax_class: type: simple unit_price: 176.88 variation_id: 0
可以在同一单元格中重复此操作,以获取更多示例
https://docs.google.com/spreadsheets/d/1NTqAi361vmaVQhgjWhs0y7oEZcb7K09W9unEE12nOkI/edit?usp=sharing
在下一张表中需要Brand,Series,Model,Length,Width值。可以使用公式来实现吗?
在Timmer给出的答案的基础上,我构建了一个函数,用于拆分值并将其发布到第二张表的不同列中。
干得好:
function split_values(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("Original_Data"); //Your original Sheet Name
var sheet2 = ss.getSheetByName("Product_Measurement"); //Your modified Sheet Name
var cellRange = sheet.getDataRange();
var cellValues = sheet.getDataRange().getValues(); //All values from original sheet.
var arrayItems = [];
var array_to_print = [];
cellValues.forEach(function(row, index) {
//Uncomment the below line if in sheet 1 we have header row that needs to be ignored.
//if (index !== 0) {
var cell = sheet.getRange(index+1, 2)
if(cell.getValue() != "Success"){ //Check if we have already parsed this row
cell.setValue("Success") //If not, parse it and set status as Success.
var split_item = row[0].split(/item_meta: /g);
for(var i=1;i<split_item.length;i++){
var item = split_item[i].split(/, 'Total Area/)[0].split(/, 'Total Area/)[0].replace(/'/g,'"')+ '}';
item = JSON.parse(item);
arrayItems.push(item); //Add all the split prdoducts to an Array.
//} Uncomment for header.
}}
});
//Add only required details to the array that needs to be put in different columns.
for (var i = 0; i < arrayItems.length ; i++) {
array_to_print.push([arrayItems[i].Brand,arrayItems[i].Series,arrayItems[i].Model,arrayItems[i]['Length (mm)'],arrayItems[i]['Width (mm)'],"Success"])
}
//Print the array in the Modified sheet.
if(array_to_print.length>0){
sheet2.getRange(sheet2.getLastRow()+1, 1,array_to_print.length,6).setValues(array_to_print);
}
}
在工作表中,我还添加了一些菜单选项,并创建了第三张工作表来转移成功项。您可以从菜单项“ Google脚本功能”运行功能。
希望这对您有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句