コード例 #1
0
    /** Returns the spreadsheet with the specified index (0-based).
     *  @param nIndex  The index of the sheet.
     *  @return  XSpreadsheet interface of the sheet. */
    public unoidl.com.sun.star.sheet.XSpreadsheet getSpreadsheet(int nIndex)
    {
        // Collection of sheets
        unoidl.com.sun.star.sheet.XSpreadsheets xSheets =
            mxDocument.getSheets();

        unoidl.com.sun.star.container.XIndexAccess xSheetsIA =
            (unoidl.com.sun.star.container.XIndexAccess)xSheets;

        unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
            (unoidl.com.sun.star.sheet.XSpreadsheet)
            xSheetsIA.getByIndex(nIndex).Value;

        return(xSheet);
    }
コード例 #2
0
        /// <summary>
        /// Returns a list of addresses of all cell ranges contained in thecollection.
        /// </summary>
        /// <param name="unoidl.com.sun.star.container.XIndexAccess">The XIndexAccess interface of the collection.</param>
        /// <returns>A string containing the cell range address list.</returns>
        public String getCellRangeListString(unoidl.com.sun.star.container.XIndexAccess xRangesIA)
        {
            String aStr   = "";
            int    nCount = xRangesIA.getCount();

            for (int nIndex = 0; nIndex < nCount; ++nIndex)
            {
                if (nIndex > 0)
                {
                    aStr += " ";
                }
                uno.Any aRangeObj = xRangesIA.getByIndex(nIndex);
                unoidl.com.sun.star.sheet.XSheetCellRange xCellRange =
                    (unoidl.com.sun.star.sheet.XSheetCellRange)aRangeObj.Value;
                aStr += getCellRangeAddressString(xCellRange, false);
            }
            return(aStr);
        }
コード例 #3
0
    /** This sample function performs all changes on the view. */
    public void doSampleFunction()
    {
        unoidl.com.sun.star.sheet.XSpreadsheetDocument xDoc = getDocument();
        unoidl.com.sun.star.frame.XModel xModel             =
            (unoidl.com.sun.star.frame.XModel)xDoc;
        unoidl.com.sun.star.frame.XController xController =
            xModel.getCurrentController();

        // --- Spreadsheet view ---
        // freeze the first column and first two rows
        unoidl.com.sun.star.sheet.XViewFreezable xFreeze =
            (unoidl.com.sun.star.sheet.XViewFreezable)xController;
        if (null != xFreeze)
        {
            Console.WriteLine("got xFreeze");
        }
        xFreeze.freezeAtPosition(1, 2);

        // --- View pane ---
        // get the cell range shown in the second pane and assign
        // a cell background to them
        unoidl.com.sun.star.container.XIndexAccess xIndex =
            (unoidl.com.sun.star.container.XIndexAccess)xController;
        uno.Any aPane = xIndex.getByIndex(1);
        unoidl.com.sun.star.sheet.XCellRangeReferrer xRefer =
            (unoidl.com.sun.star.sheet.XCellRangeReferrer)aPane.Value;
        unoidl.com.sun.star.table.XCellRange   xRange     = xRefer.getReferredCells();
        unoidl.com.sun.star.beans.XPropertySet xRangeProp =
            (unoidl.com.sun.star.beans.XPropertySet)xRange;
        xRangeProp.setPropertyValue(
            "IsCellBackgroundTransparent", new uno.Any(false));
        xRangeProp.setPropertyValue(
            "CellBackColor", new uno.Any((Int32)0xFFFFCC));

        // --- View settings ---
        // change the view to display green grid lines
        unoidl.com.sun.star.beans.XPropertySet xProp =
            (unoidl.com.sun.star.beans.XPropertySet)xController;
        xProp.setPropertyValue(
            "ShowGrid", new uno.Any(true));
        xProp.setPropertyValue(
            "GridColor", new uno.Any((Int32)0x00CC00));

        // --- Range selection ---
        // let the user select a range and use it as the view's selection
        unoidl.com.sun.star.sheet.XRangeSelection xRngSel =
            (unoidl.com.sun.star.sheet.XRangeSelection)xController;
        ExampleRangeListener aListener = new ExampleRangeListener();

        xRngSel.addRangeSelectionListener(aListener);
        unoidl.com.sun.star.beans.PropertyValue[] aArguments =
            new unoidl.com.sun.star.beans.PropertyValue[2];
        aArguments[0]       = new unoidl.com.sun.star.beans.PropertyValue();
        aArguments[0].Name  = "Title";
        aArguments[0].Value = new uno.Any("Please select a range");
        aArguments[1]       = new unoidl.com.sun.star.beans.PropertyValue();
        aArguments[1].Name  = "CloseOnMouseRelease";
        aArguments[1].Value = new uno.Any(true);
        xRngSel.startRangeSelection(aArguments);
        Monitor.Enter(aListener);
        try
        {
            Monitor.Wait(aListener);         // wait until the selection is done
        }
        finally
        {
            Monitor.Exit(aListener);
        }
        xRngSel.removeRangeSelectionListener(aListener);
        if (aListener.aResult != null && aListener.aResult.Length != 0)
        {
            unoidl.com.sun.star.view.XSelectionSupplier xSel =
                (unoidl.com.sun.star.view.XSelectionSupplier)xController;
            unoidl.com.sun.star.sheet.XSpreadsheetView xView =
                (unoidl.com.sun.star.sheet.XSpreadsheetView)xController;
            unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
                xView.getActiveSheet();
            unoidl.com.sun.star.table.XCellRange xResultRange =
                xSheet.getCellRangeByName(aListener.aResult);
            xSel.select(
                new uno.Any(
                    typeof(unoidl.com.sun.star.table.XCellRange),
                    xResultRange));
        }
    }