Google表格-值设置不正确

时间:2019-05-22 11:52:16

标签: google-apps-script google-sheets

我已经设置了一个带有附加脚本的google工作表,该脚本运行一个功能来提取chromebook设备信息,并且与两个我不感兴趣的字段“ cpuStatusReports”和“ diskVolumeReports”相距甚远,脚本记录器确实显示了正确的信息但是我的工作表单元格值设置为例如

  

{cpuUtilizationPercentageInfo = [Ljava.lang.Object; @ d151552,   cpuTemperatureInfo = [Ljava.lang.Object; @ f57094c,   reportTime = 2019-03-29T18:15:56.049Z}

我的功能是:-

  

function chromebookdetails2(){var domain,chromebooks,page,ss,   工作表,pageToken,我var sheetData4 =   onSheet.getSheetByName(“ chromebook”)//sheetData4.clear();域=   “ mydomainnamehere” chromebooks = new Array()do {page =   AdminDirectory.Chromeosdevices.list(“ my_customer”,{domain:域,   maxResults:1000,pageToken:pageToken})for(i in   page.chromeosdevices){chromebooks.push(page.chromeosdevices [i])}   pageToken = page.nextPageToken} while(pageToken){var row = 3   //(var i = 0; i      

if(chromebooks [i] .length == 0){       //数组为空Logger.log('empty'); } else {//数组不为空> Logger.log('not empty');

     

Logger.log(chromebooks [i] .cpuStatusReports);
  ///////////////////// Array Data ///////////////////////////// ////////
  sheetData4.getRange(row,1).setValue(chromebooks [i] .orgUnitPath);   sheetData4.getRange(row,2).setValue(chromebooks [i] .annotatedUser);   sheetData4.getRange(row,3).setValue(chromebooks [i] .annotatedLocation);   sheetData4.getRange(row,4).setValue(chromebooks [i] .annotatedAssetId);   sheetData4.getRange(row,5).setValue(chromebooks [i] .serialNumber);   sheetData4.getRange(row,6).setValue(chromebooks [i] .lastEnrollmentTime);   sheetData4.getRange(row,7).setValue(chromebooks [i] .deviceId);   sheetData4.getRange(row,8).setValue(chromebooks [i] .bootMode);   sheetData4.getRange(row,9).setValue(chromebooks [i] .recentUsers);   sheetData4.getRange(row,10).setValue(chromebooks [i] .macAddress);   sheetData4.getRange(row,11).setValue(chromebooks [i] .lastSync);   sheetData4.getRange(row,12).setValue(chromebooks [i] .osVersion);   sheetData4.getRange(row,13).setValue(chromebooks [i] .platformVersion);   sheetData4.getRange(row,14).setValue(chromebooks [i] .activeTimeRanges);   sheetData4.getRange(row,15).setValue(chromebooks [i] .model);   sheetData4.getRange(row,16).setValue(chromebooks [i] .etag);   sheetData4.getRange(row,17).setValue(chromebooks [i] .firmwareVersion);   sheetData4.getRange(row,18).setValue(chromebooks [i] .status);   sheetData4.getRange(row,19).setValue(chromebooks [i] .ethernetMacAddress);   sheetData4.getRange(row,20).setValue(chromebooks [i] .notes);   sheetData4.getRange(row,21).setValue(chromebooks [i] .systemRamTotal /   (1024 * 1024)/ 1024); //“ /(1024 * 1024)”将字节转换为Mb“ / 1024”   然后转换回Gb   sheetData4.getRange(row,22).setValue(chromebooks [i] .cpuStatusReports);

     

}

     

row ++ Logger.log(row)}}}

日志文件中的结果。...

  

[{cpuUtilizationPercentageInfo = [63],   cpuTemperatureInfo = [{温度= 24,标签= soc_dts0},   {temperature = 24,label = soc_dts1}],   reportTime = 2019-03-10T18:11:49.480Z}]

如何从cpuStatusReports中引用cpuUtilizationPercentageInfo,cpuTemperatureInfo?

谢谢

1 个答案:

答案 0 :(得分:0)

在循环中添加

var status = chromebooks[i].cpuStatusReports;
var cpuUtilizationPercentageInfo = status[0].cpuUtilizationPercentageInfo[0];
var cpuTemperatureInfo = status[0].cpuTemperatureInfo[0].temperature;
var label = status[0].cpuTemperatureInfo[0].label;

检查logger.log()以查看是否获得期望的结果。