2012-07-21 29 views
0

我在電子表格上有一個數據庫程序,數據經常按行和列排序,我正在處理的是一個UI,它允許用戶搜索數據庫並顯示如下所示的結果。 「表」顯示結果和滾動表中的15個下一項,其中最重要的數據和底部的文本區域應該包含選定項目,其格式可以複製並粘貼到任何文檔中,同時保留佈局(換行,間距...)。注意:腳本還應該檢測表中哪些行有焦點。 這個文本區域應該提供2個(現在)所謂的'格式',一個用於屏幕截圖中顯示的字母,另一個用所有字段(逗號或製表符分隔)放在幾行上(我稱它爲'raw數據')用於任何其他目的(用radioButtons選擇)。 (這裏終於是真正的問題)我不知道如何獲得textarea中的格式化文本...我應該使用HTML嗎?如何格式化文本,我可以使用電子表格中的數據複製/粘貼任何地方

下面是屏幕截圖,我用現在的UI代碼,我猜的畫面讓事情更清楚一點,至少我希望;-) enter image description here

function buildUi() { 
    var app = UiApp.createApplication().setTitle("BrowseList Test") 
     .setHeight(340).setWidth(800).setStyleAttribute("background-color","beige").setStyleAttribute('padding','20'); 
    var scroll = app.createScrollPanel().setPixelSize(750,150) 
    var vpanel = app.createVerticalPanel(); 
    var cell = new Array(); 
    var cellWidth = [45,135,150,250,50,100] 
    var row = new Array(); 
    for(vv=0;vv<15;++vv){ 
     row[vv]=app.createHorizontalPanel(); 
     vpanel.add(row[vv]); 
     for(hh=0;hh<cellWidth.length;++hh){ 
     cell[hh+(vv)*cellWidth.length]=app.createTextBox().setWidth(cellWidth[hh]+""); 
     row[vv].add(cell[hh+(vv)*cellWidth.length]) 
     } 
     } 
app.add(scroll.add(vpanel)) 
// Initial populate 
var data = ss.getDataRange().getValues(); 
    for(vv=0;vv<15;++vv){ 
     for(hh=0;hh<cellWidth.length;++hh){ 
     var rowpos=vv+1+offset 
     var cellpos = hh+(vv)*cellWidth.length 
     cell[cellpos].setValue(data[rowpos][hh]) 
     } 
     } 
    var grid = app.createGrid(2,9).setWidth('700') 
    grid.setWidget(1, 0, app.createLabel('search')); 
    grid.setWidget(1, 1, app.createTextBox().setName('search').setId('search')); 
    grid.setWidget(1, 2, app.createRadioButton('mode','strict')); 
    grid.setWidget(1, 3, app.createRadioButton('mode','global').setValue(true)); 
    grid.setWidget(1, 5, app.createLabel(' ').setWidth('100')); 
    grid.setWidget(1, 6, app.createLabel('show mode')); 
    grid.setWidget(1, 7, app.createRadioButton('show','letter').setValue(true)); 
    grid.setWidget(1, 8, app.createRadioButton('show','raw data')); 
    app.add(grid); 

    var result = app.createTextArea().setPixelSize(700,100) 
    app.add(result) 

ss.show(app); 
} 

回答

1

您是否考慮過Rich Text Area?並使用setHTML方法。

+0

我上次嘗試RichTextArea我沒有太多的成功([*](http://stackoverflow.com/questions/10850640/in-ui-service -trying-to-view-html-content)),但是從這一次開始,它會被'硬編碼',我會在這裏試試並更新。謝謝 – 2012-07-22 08:39:06

+0

好的,我們可以說它的工作原理......至少它顯示文本,我可以選擇和複製/粘貼,但不幸的是,HTML渲染不是很豐富...我不能改變tipeface也不能添加這麼多的樣式...無論如何,多謝Srik ;-) – 2012-07-22 15:42:57

+1

對不起,它似乎是一個瀏覽器問題,字體在Chrome和Firefox上不起作用,但適用於Safari ...作爲richTextArea本身的樣式屬性。 – 2012-07-22 16:13:57

0

爲什麼不創建一個flextable ,以保存您的搜索結果。將其更改爲所需格式(帶逗號)並通過ScriptProperties存儲即可複製/粘貼。

+0

謝謝,但我想直接從UI複製粘貼 - '普通用戶'只會看到這個用戶界面。 – 2012-07-21 20:30:13

+0

您正在遍歷行(結果),而不是按照您想要的方式構建結果。如果您設置了行項(行號與表中的位置),則可以通過以下方式訪問它們:app.getElementById('11' ).getValue ==先生+','等 – 2012-07-22 08:14:38

相關問題