0
選擇不同的表我目前使用具有幾年在不同的表的數字數據(也被稱爲通過一些標籤!?)的電子表格,表示每個表/選項卡一年的工作價值。繼幾個在線教程後,我爲任何給定年份創建了一個簡單的圖表儀表板。這是我的代碼有閱讀塞爾的回答後至今(除部分繪製圖表),與2次修改(使「SS」一個全球性的,並使用setActiveSheet)的片段。使用谷歌Apps腳本列表框在電子表格
var ss = SpreadsheetApp.openById(ssID);
ss.setActiveSheet(ss.getSheetByName("2012"));
function doGet() {
var sheet = ss.getActiveSheet();
var data = sheet.getRange(1,1,sheet.getMaxRows(),sheet.getMaxColumns());
var dashboard = Charts.newDashboardPanel()
.setDataTable(data)
.build();
var uiApp = UiApp.createApplication().setTitle("My Dashboard");
// Dropdown box
var listBox = uiApp.createListBox() // Choose data by year
.setId('listBox')
.setName('listBox')
.setVisibleItemCount(1);
for (i=0; i<ss.getNumSheets(); i++) {
listBox.addItem(ss.getSheets()[i].getSheetName());
}
var infoLabel = uiApp.createLabel('Select from List').setId('info').setVisible(false);
// Add a handler to the ListBox when its value is changed
var handler = uiApp.createServerChangeHandler('showSelectedinfo');
handler.addCallbackElement(listBox);
listBox.addChangeHandler(handler);
// UI Element: Grid
var mygrid = uiApp.createGrid(1, 3);
mygrid.setWidget(0, 0, uiApp.createLabel('By Year:'));
mygrid.setWidget(0, 1, listBox);
mygrid.setWidget(0, 2, infoLabel)
var controlsPanel = uiApp.createVerticalPanel().add(mygrid);
uiApp.add(controlsPanel).add(dashboard);
return uiApp;
}
function showSelectedinfo(e){
var app = UiApp.getActiveApplication();
var selectedItem = e.parameter.listBox;
var listBox = app.getElementById('listBox');
app.getElementById('info').setText('You selected :'+selectedItem).setVisible(true)
.setStyleAttribute('color','#008000');
ss.setActiveSheet(ss.getSheetByName(selectedItem));
return app;
}
現在我想用下拉框選擇不同的表,即年,有圖表相應地更新。不過,雖然我可以選擇「年份」並正確顯示,但仍然無法更改爲使用新工作表中的數據。也許這裏的任何專家都可以提供一些指導?
謝謝您的回答。但正如我在最後提到的那樣,這些圖表仍然沒有正確更新?也許你現在可以看到一些明顯的錯誤,我已經上傳了我的代碼的相關位? – Louis
我做了一些測試,我也得到重建的處理功能的儀表盤和隱藏的第一個,當它的工作...但我不知道它是真正去...我希望有人會提出一個更好的解決方案的正確方法爲你。 –
如果你的意思是創建爲每片不同的面板和不斷變化的知名度,然後是啊,聽起來不是很有效。 :-)無論如何感謝您的建議! – Louis