<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    翻譯:OpenOffice.org API介紹(三)

    Posted on 2007-07-18 11:37 Tommy Jian 閱讀(3226) 評論(2)  編輯  收藏 所屬分類: OpenOffice.org

      3.3  數據的設置

       我們需要使用的有三種類型的數據。在開始之前,我們需要有個方法來獲得對單元格的訪問。這一節(jié)的其他輔助性方法也將使用此方法,定義如下:

    public XCell getXCellByPosition(XSpreadsheet xSpreadsheet, int x, int y)
        throws Exception 
    {
        return xSpreadsheet.getCellByPosition(x, y);
    }

     

       

       首先,我們將要接觸到文本類型的數據,比如說Javalobby文章的標題。對于這種數據,輔助性方法需要電子表對象、列位置、行位置以及數據本身作為參數。

    public void setTextValueOfXCellAtPosition(XSpreadsheet
        xSpreadsheet, 
    int x, int y, String value) throws Exception 
    {
        //We first identify the cell we need to work with,
        //using the incoming x and y values:
        XCell xCell = getXCellByPosition(xSpreadsheet, x, y);
        //Next, since we're working with text, we define
        //a text object and a cursor object and insert the received content into the cell:
        XText xText = (com.sun.star.text.XText)UnoRuntime.queryInterface(com.sun.
            star.text.XText.
    class, xCell);
        XTextCursor xTextCursor 
    = xText.createTextCursor();
        xText.insertString(xTextCursor, value, 
    false);
    }

     

       其次,對于數字類型的數據,比如說“Reply”列的數據,輔助性方法要求傳遞double類型的參數:

    public void setNumValueOfXCellAtPosition(XSpreadsheet
        xSpreadsheet, 
    int x, int y, double value) throws Exception 
    {
        //First we get the cell identified by the received x and y values:
        XCell xCell = getXCellByPosition(xSpreadsheet, x, y);
        //Then we add the received value to the identified cell:
        xCell.setValue(value);
    }

     

       最后,盡管Calc的公式是普通的字符串,我們可以使用OpenOffice.org的API所包含的單元格樣式屬性來為單元格設置預定義的“Result”樣式,這主要是針對我們匯總回復總數的計算公式來進行設置:

    public void setFormulaOfXCellAtPosition(XSpreadsheet
        xSpreadsheet, 
    int x, int y, String formula) throws Exception 
    {
        //We get the cell defined by the incoming x and y values"
        XCell xCell = getXCellByPosition(xSpreadsheet, x, y);
        //We add a Calc formula to the cell, as received by the helper method:
        xCell.setFormula(formula);
        //We attach a property set to our cell, so that we can define a property:
        XPropertySet xCellProps = (XPropertySet)UnoRuntime.
            queryInterface(XPropertySet.
    class, xCell);
        //We set the style of the cell, using a predefined "Result" style,
        //which comes out of the box with the OpenOffic.org API:
        xCellProps.setPropertyValue("CellStyle""Result");
    }

     

      3.4  顏色的使用

       下面的代碼將在隨后被使用:

    if (position%2 == 0
    {
        oooHelper.setColorRow(xSpreadsheet, position, 
    0xFF9933);
    }

     

       在ARGB顏色空間中,0xFF9933代表橙色。如果行數是偶數,那么電子表、行數以及橙色會被作為參數傳遞給方法:

    public void setColorRow(XSpreadsheet
        xSpreadsheet, 
    int row, int color) throws Exception 
    {
        //First we get the range of cells we want to deal with,
        //which is the whole spreadsheet:
        XCellRange xCellRange = (XCellRange)UnoRuntime.queryInterface
            ( XCellRange.
    class, xSpreadsheet );
        //Next, we narrow down our selection further,
        //going from column 0/current row to column 3/current row,
        //which is a whole row from left to right:
        XCellRange xSelectedCells = xCellRange.getCellRangeByPosition(0, row, 3, row);
        //Next, we create a property set and assign it to our selected range:
        XPropertySet xCellProps =
            (XPropertySet)UnoRuntime.queryInterface(XPropertySet.
    class,xSelectedCells);
        //This line sets the color to white, which basically
        //refreshes the row color before we add our new row color:
        xCellProps.setPropertyValue("CellBackColor"new Integer(16777215));
        //This line sets the color to whatever is received,
        //in this case orange:
        xCellProps.setPropertyValue("CellBackColor"new Integer(color));
    }

     

       如果用戶需要看到“Most Replies”或者“Least Replies”,我們將使用以下代碼進行設置:

    ooHelper.setColorCell(xSpreadsheet, 2, jTable1.getRowCount()+50x008000);

     

       以下的方法需要電子表、列數、行數以及顏色值作為參數:

    public void setColorCell(XSpreadsheet xSpreadsheet, int column, int row, int color)
        throws Exception 
    {
        //First, we select the entire received spreadsheet:
        XCellRange xCellRange = (XCellRange)UnoRuntime.queryInterface( XCellRange.class,
            xSpreadsheet );
        //From the received spreadsheet, we select a single cell,
        //defined by the row and column received:
        XCellRange xSelectedCells = xCellRange.getCellRangeByPosition(column,
            row, column, row);
        //We define a property set, an object to contain the cell's properties:
        XPropertySet xCellProps = (XPropertySet)UnoRuntime.queryInterface
            (XPropertySet.
    class, xSelectedCells);
        //This line sets the color to white, to refresh the cell:
        xCellProps.setPropertyValue("CellBackColor"new Integer(16777215));
        //This line sets the background color of the cell to whatever is received:
        xCellProps.setPropertyValue("CellBackColor"new Integer(color));
    }

     


    本文譯自NetBeans.org中的文章,其中的代碼也都經過譯者測試。未完待續(xù)!!!

    Feedback

    # 如何獲取單元格的合并數據信息呀  回復  更多評論   

    2007-12-20 16:54 by lhslove@126.com
    如何獲取單元格的合并數據信息呀
    比如我想得到某個單元格合并了幾個單元格,用什么方法得到?謝謝

    # re: 翻譯:OpenOffice.org API介紹(四)  回復  更多評論   

    2008-07-09 15:47 by xiaowu
    aaa
    主站蜘蛛池模板: 国产美女a做受大片免费| 亚洲国产精品lv| 国产白丝无码免费视频| 亚洲国产综合自在线另类| 天天摸天天碰成人免费视频| 日韩在线视频播放免费视频完整版 | 久久久亚洲欧洲日产国码二区 | 四虎影视在线影院在线观看免费视频 | 亚洲精品亚洲人成在线观看| 精品无码人妻一区二区免费蜜桃| 亚洲人成色在线观看| 亚洲日韩乱码中文无码蜜桃臀网站 | 好爽…又高潮了毛片免费看| yellow免费网站| 99热亚洲色精品国产88| 国产亚洲一区二区三区在线不卡| 又黄又爽又成人免费视频| 男女一边桶一边摸一边脱视频免费| 亚洲区视频在线观看| 伊伊人成亚洲综合人网7777| 成人一a毛片免费视频| 免费国产成人18在线观看| 国产午夜亚洲精品不卡| 亚洲视频在线观看不卡| 久久久久噜噜噜亚洲熟女综合| 免费三级毛片电影片| 青青操视频在线免费观看| 国产亚洲福利精品一区二区| 亚洲va乱码一区二区三区| 亚洲av最新在线网址| 亚洲AV无码乱码在线观看牲色| 久久午夜免费视频| 免费无码一区二区三区| 一级毛片不卡免费看老司机| 亚洲乱码无人区卡1卡2卡3| 亚洲黄色在线网站| 亚洲视频2020| 日韩亚洲一区二区三区| 亚洲中文字幕丝袜制服一区| 国产免费人人看大香伊| 成人激情免费视频|