0

我的脚本正在遍历一些电子表格信息。我阅读了文档,滚动面板只允许一个孩子。因此,我将水平面板信息包装在滚动面板中,但由于某种原因,滚动面板永远不会只显示彩色背景的内容。任何想法为什么会这样?

 var myscrollpanel = app.createScrollPanel().setPixelSize(100, 100);
  myscrollpanel.setWidth("100%");
  myscrollpanel.setStyleAttribute("background", "silver");
  var vpanel = app.createVerticalPanel();


 for (i=1; i <= mylastrow;++i)
{

 var cellsname= mydatarange.getCell(i,1).getValue().toLowerCase();
// Browser.msgBox(cellsname );
// Browser.msgBox(searchstr.toString());
 if (cellsname.toString() == searchstr.toString()) 
 {

   var panelrow = app.createHorizontalPanel();
   var ddate = app.createTextBox();
   var sbehavior = app.createTextBox();
   var sconsequence = app.createTextBox();
   var scomment = app.createLabel();
   var steacher = app.createTextBox();
   ddate.setText(mydatarange.getCell(i,5).getValue());
   sbehavior.setText(mydatarange.getCell(i,8).getValue());
   sconsequence.setText(mydatarange.getCell(i,6).getValue());
   scomment.setText(mydatarange.getCell(i,10).getValue());
   steacher.setText(mydatarange.getCell(i,7).getValue());
   panelrow.add(ddate);
   panelrow.add(sbehavior);
   panelrow.add(sconsequence);
   panelrow.add(steacher);
   panelrow.add(scomment);
   vpanel.add(panelrow);
   app.add(panelrow);


   cnt = ++cnt;

 }

 }  

//  Browser.msgBox(cnt);     

 myscrollpanel.add(vpanel);
app.add(myscrollpanel);
// return myscrollpanel;

return app    ;// update UI
4

1 回答 1

1

您的代码中有一些“异常”可能会导致一些问题,我建议进行一些更改(参见下面的代码)。

另一点是循环读取电子表格不是一个好主意,一次读取整个范围然后使用数组值进行迭代肯定会更有效。这是一个代码提案,我没有对其进行测试(它可能需要一些调试),但添加了一些注释来解释更改。

  var myscrollpanel = app.createScrollPanel()//.setPixelSize(100, 100);// 100 pixel is quite small to put all the items you add !!
  myscrollpanel.setWidth("100%");// 
  myscrollpanel.setStyleAttribute("background", "silver");// this will not affect the widgets you add to the panel...
  var vpanel = app.createVerticalPanel();

  var data = mydatarange.getValues();// get all data in an array

 for (i=0; i <data.length;++i)  // and work directly with array values (indexed to 0 instead of cells indexed to 1)
{

 var cellsname= data[i][0].toString().toLowerCase();
 if (cellsname == searchstr.toString()){
   var panelrow = app.createHorizontalPanel();
   var ddate = app.createTextBox();
   var sbehavior = app.createTextBox();
   var sconsequence = app.createTextBox();
   var scomment = app.createLabel();
   var steacher = app.createTextBox();
   ddate.setText(data[i][4].getValue());
   sbehavior.setText(data[i][7].getValue());
   sconsequence.setText(data[i][5].getValue());
   scomment.setText(data[i][9].getValue());
   steacher.setText(data[i][6].getValue());
   panelrow.add(ddate);
   panelrow.add(sbehavior);
   panelrow.add(sconsequence);
   panelrow.add(steacher);
   panelrow.add(scomment);
   vpanel.add(panelrow);// add only to the panel, not to the app or the row will be outside the panel
   cnt = ++cnt;
   }
 }  
  myscrollpanel.add(vpanel);
  app.add(myscrollpanel);
  return app    ;// update UI
}
于 2013-02-18T10:02:30.960 回答