https://wiki.openoffice.org/w/api.php?action=feedcontributions&user=Andreh&feedformat=atom
Apache OpenOffice Wiki - User contributions [en]
2024-03-28T22:41:58Z
User contributions
MediaWiki 1.23.13
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Charts/Common_Parts_of_all_Chart_Types
Documentation/DevGuide/Charts/Common Parts of all Chart Types
2009-10-05T08:09:45Z
<p>Andreh: /* Axis */ fixed IDL tag for com.sun.star.chart.ChartAxisXSupplier</p>
<hr />
<div>{{Documentation/DevGuide/ChartsTOC<br />
|Charts2b=block<br />
|ChartsParts=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Charts/Chart Document Parts<br />
|NextPage=Documentation/DevGuide/Charts/Features of Special Chart Types<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Charts/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Common Parts of all Chart Types}}<br />
=== Diagram ===<br />
<br />
The diagram object is an important object of a chart document. The diagram represents the visualization of the underlying data. The diagram object is a graphic object group that lies on the same level as the titles and the legend. From the diagram, data rows and data points are obtain that are also graphic objects that represent the respective data. Several properties can be set at a diagram to influence its appearance. Note that the term data series is used instead of data rows.<br />
<br />
Some diagrams support the service <idl>com.sun.star.chart.Dim3DDiagram</idl> that contains the property <code>Dim3D</code>. If this is set to true, you get a three-dimensional view of the chart, which in {{PRODUCTNAME}} is usually rendered in OpenGL. In 3-D charts, you can access the z-axis, which is not available in 2-D.<br />
<br />
The service <idl>com.sun.star.chart.StackableDiagram</idl> offers the properties ''Percent'' and ''Stacked''. With these properties, accumulated values can be stacked for viewing. When setting <code>Percent</code> to <code>true</code>, all slices through the series are summed up to 100 percent, so that for an <code>AreaDiagram</code> the whole diagram space would be filled with the series. Note that setting the <code>Percent</code> property also sets the <code>Stacked</code> property, because <code>Percent</code> is an addition to <code>Stacked</code>.<br />
<br />
There is a third service that extends a base diagram type for displaying statistical elements called <idl>com.sun.star.chart.ChartStatistics</idl>. With this service, error indicators or a mean value line are added. The mean value line represents the mean of all values of a series. The regression curve is only available for the <code>XYDiagram</code>, because a numeric x-axis, is required.<br />
<br />
[[Image:Diagram.png|none|thumb|400px|Diagram]]<br />
<br />
The illustration above shows that there are eight base types of diagrams. The three services, <code>StackableDiagram</code>, <code>Dim3DDiagram</code> and <code>ChartStatistics</code> are also supported for several diagram types and allows extensions of the base types as discussed. For instance, a three-dimensional pie chart can be created, because the <idl>com.sun.star.chart.PieDiagram</idl> service points to the <idl>com.sun.star.chart.Dim3DDiagram</idl> service.<br />
<br />
The services <idl>com.sun.star.chart.AreaDiagram</idl>, <idl>com.sun.star.chart.LineDiagram</idl>, and <idl>com.sun.star.chart.BarDiagram</idl> support all three feature services.<br />
<br />
=== Axis ===<br />
<br />
All charts can have one or more axis, except for pie charts. A typical two-dimensional chart has two axis, an x- and y-axis. Secondary x- or y-axis can be added to have up to four axis. In a three-dimensional chart, there are typically three axis, x-, y- and z-axis. There are no secondary axis in 3-dimensional charts.<br />
<br />
An axis combines two types of properties:<br />
<br />
* Scaling properties that affect other objects in the chart. A minimum and maximum values are set that spans the visible area for the displayed data. A step value can also be set that determines the distance between two tick-marks, and the distance between two grid-lines if grids are switched on for the corresponding axis.<br />
* Graphical properties that influence the visual impression. These are character properties (see <idl>com.sun.star.style.CharacterProperties</idl>) affecting the labels and line properties (see <idl>com.sun.star.drawing.LineProperties</idl>) that are applied to the axis line and the tick-marks.<br />
<br />
[[Image:Axis.png|none|thumb|400px|Axis]]<br />
<br />
Different diagram types support a different number of axis. In the above illustration, a <idl>com.sun.star.chart.XYDiagram</idl>, also known as a scatter diagram, is shown. The scatter diagram supports x- and y-axis, but not a z-axis as there is no 3-dimensional mode. The <idl>com.sun.star.chart.PieDiagram</idl> supports no axis at all. The <idl>com.sun.star.chart.BarDiagram</idl> supports all kinds of axis. Note that the z-Axis is only supported in a three-dimensional chart. Note that there is a <idl>com.sun.star.chart.ChartTwoAxisXSupplier</idl> that includes the <idl>com.sun.star.chart.ChartAxisXSupplier</idl> and is supported by all diagrams in {{PRODUCTNAME}} required to support the service <code>ChartAxisXSupplier</code>.<br />
<br />
The following example shows how to obtain an axis and how to change the number format.<br />
<source lang="java"><br />
import com.sun.star.chart.*;<br />
import com.sun.star.beans.XPropertySet;<br />
import com.sun.star.util.XNumberFormatsSupplier;<br />
<br />
...<br />
<br />
// class members<br />
XChartDocument aChartDocument;<br />
XDiagram aDiagram;<br />
<br />
...<br />
<br />
// get an XChartDocument and assign it to aChartDocument<br />
// get the diagram from the document and assign it to aDiagram<br />
// ...<br />
<br />
// check whether the current chart supports a y-axis<br />
XAxisYSupplier aYAxisSupplier = (XAxisYSupplier) UnoRuntime.queryInterface(<br />
XAxisYSupplier.class, aDiagram);<br />
<br />
if (aYAxisSupplier != null) {<br />
XPropertySet aAxisProp = aYAxisSupplier.getYAxis();<br />
<br />
// initialize new format with value for standard<br />
int nNewNumberFormat = 0;<br />
<br />
XNumberFormatsSupplier aNumFmtSupp = (XNumberFormatsSupplier)<br />
UnoRuntime.queryInterface(XNumberFormatsSupplier.class,<br />
aChartDocument);<br />
<br />
if (aNumFmtSupp != null) {<br />
com.sun.star.util.XNumberFormats aFormats = aNumFmtSupp.getNumberFormats();<br />
<br />
Locale aLocale = new Locale("de", "DE", "de");<br />
<br />
String aFormatStr = aFormats.generateFormat(<br />
0, // base key<br />
aLocale, // locale<br />
true, // thousands separator on<br />
true, // negative values in red<br />
(short)3, // number of decimal places<br />
(short)1 // number of leading ciphers<br />
);<br />
<br />
nNewNumberFormat = aFormats.addNew(aFormatStr, aLocale);<br />
}<br />
<br />
aAxisProp.setPropertyValue("NumberFormat", new Integer(nNewNumberFormat));<br />
}<br />
</source><br />
<br />
=== Data Series and Data Points ===<br />
<br />
The objects that visualize the actual data are data series. The API calls them data rows that are not rows in a two-dimensional spreadsheet table, but as sets of data, because the data for a ''data row'' can reside in a column of a spreadsheet table.<br />
<br />
The data rows contain data points. The following two methods at the <idl>com.sun.star.chart.XDiagram</idl> interface allow changes to the properties of a whole series or single data point:<br />
<source lang="idl"><br />
com::sun::star::beans::XPropertySet getDataRowProperties( [in] long nRow)<br />
com::sun::star::beans::XPropertySet getDataPointProperties( [in] long nCol,<br />
[in] long nRow) <br />
</source><br />
The index provided in these methods is 0-based, that is, 0 is the first series. In <code>XYDiagrams</code>, the first series has an index 1, because the first array of values contains the x-values of the diagram that is not visualized. This behavior exists for historical reasons.<br />
<br />
In a spreadsheet context, the indexes for <code>getDataPointProperties()</code> are called <code>nCol</code> and <code>nRow</code> and are misleading. The <code>nRow</code> parameter gives the data row, that is, the series index. The <code>nCol</code> gives the index of the data point inside the series, regardless if the series is taken from rows or columns in the underlying table. To get the sixth point of the third series, write <code>getDataPointProperties(5, 2)</code>.<br />
<br />
Data rows and data points have <idl>com.sun.star.drawing.LineProperties</idl> and <idl>com.sun.star.drawing.FillProperties</idl>. They also support <idl>com.sun.star.style.CharacterProperties</idl> for text descriptions that can be displayed next to data points.<br />
<br />
Properties can be set for symbols and the type of descriptive text desired. With the <code>SymbolType</code> property, one of several predefined symbols can be set. With <code>SymbolBitmapURL</code>, a URL that points to a graphic in a format known by {{PRODUCTNAME}} can be set that is then used as a symbol in a <idl>com.sun.star.chart.LineDiagram</idl> or <idl>com.sun.star.chart.XYDiagram</idl>.<br />
<br />
The following example demonstrates how to set properties of a data point. Before implementing this example, create a chart document and diagram of the type <code>XYDiagram</code>.<br />
<source lang="java"><br />
com.sun.star.chart.XChartDocument aChartDocument;<br />
com.sun.star.chart.XDiagram aXYDiagram;<br />
<br />
// get a chart document and assign it to aChartDocument<br />
// set an "XYDiagram" and remember the diagram in aXYDiagram<br />
// ...<br />
<br />
// get the properties of the fifth data point of the first series<br />
// note that index 1 is the first series only in XYDiagrams<br />
try {<br />
com.sun.star.beans.XPropertySet aPointProp = maDiagram.getDataPointProperties(4, 1);<br />
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) {<br />
System.out.println("Index is out of bounds: " + ex);<br />
System.exit(0);<br />
}<br />
<br />
try {<br />
// set a bitmap via URL as symbol for the first series<br />
aPointProp.setPropertyValue("SymbolType", new Integer(ChartSymbolType.BITMAPURL));<br />
aPointProp.setPropertyValue("SymbolBitmapURL", <br />
"http://graphics.openoffice.org/chart/bullet1.gif");<br />
<br />
// add a label text with bold font, bordeaux red 14pt<br />
aPointProp.setPropertyValue("DataCaption", new Integer(ChartDataCaption.VALUE));<br />
aPointProp.setPropertyValue("CharHeight", new Float(14.0));<br />
aPointProp.setPropertyValue("CharColor", new Integer(0x993366));<br />
aPointProp.setPropertyValue("CharWeight", new Float(FontWeight.BOLD));<br />
} catch (com.sun.star.uno.Exception ex) {<br />
System.out.println("Exception caught: " + ex);<br />
}<br />
</source><br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Charts]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T22:15:54Z
<p>Andreh: added example to add a border to a cell</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
//--------------------<br />
// use bold font<br />
//--------------------<br />
xPropSet.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD);<br />
xPropSet.setPropertyValue("CharWeightAsian", com.sun.star.awt.FontWeight.BOLD);<br />
xPropSet.setPropertyValue("CharWeightComplex", com.sun.star.awt.FontWeight.BOLD);<br />
<br />
//--------------------<br />
// add a cell border <br />
//--------------------<br />
<br />
// one point seems to be 1/72 inch<br />
double lineWidthInPoints = 2.5;<br />
<br />
// convert to units of 1/100 mm<br />
short integerLineWidth = (short) Math.round(2540 / 72.0 * lineWidthInPoints);<br />
<br />
final String[] borderNames = {<br />
"LeftBorder", "RightBorder", "TopBorder", "BottomBorder"<br />
};<br />
<br />
for (int i = 0; i < borderNames.length; ++i)<br />
{<br />
com.sun.star.table.BorderLine borderLine = new com.sun.star.table.BorderLine();<br />
borderLine.OuterLineWidth = integerLineWidth;<br />
xPropSet.setPropertyValue(borderNames[i], borderLine);<br />
}<br />
<br />
}<br />
<br />
See also [[Documentation/DevGuide/FirstSteps/Example:_Working_with_a_Spreadsheet_Document|Working with a Spreadsheet Document (Example)]].<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of <code>mxDocCursor</code>), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
| see also <idl>com.sun.star.awt.FontWeight</idl><br />
|-<br />
| CharWeightAsian<br />
| float<br />
| see also <idl>com.sun.star.awt.FontWeight</idl><br />
|-<br />
| CharWeightComplex<br />
| float<br />
| see also <idl>com.sun.star.awt.FontWeight</idl><br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:49:47Z
<p>Andreh: added link to com.sun.star.awt.FontWeight for the three CharWeight* attributes in table</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
//--------------------<br />
// use bold font<br />
//--------------------<br />
xPropSet.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD);<br />
xPropSet.setPropertyValue("CharWeightAsian", com.sun.star.awt.FontWeight.BOLD);<br />
xPropSet.setPropertyValue("CharWeightComplex", com.sun.star.awt.FontWeight.BOLD);<br />
<br />
}<br />
<br />
See also [[Documentation/DevGuide/FirstSteps/Example:_Working_with_a_Spreadsheet_Document|Working with a Spreadsheet Document (Example)]].<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of <code>mxDocCursor</code>), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
| see also <idl>com.sun.star.awt.FontWeight</idl><br />
|-<br />
| CharWeightAsian<br />
| float<br />
| see also <idl>com.sun.star.awt.FontWeight</idl><br />
|-<br />
| CharWeightComplex<br />
| float<br />
| see also <idl>com.sun.star.awt.FontWeight</idl><br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:47:22Z
<p>Andreh: replaced font weight 150.0 by constant com.sun.star.awt.FontWeight.BOLD</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
//--------------------<br />
// use bold font<br />
//--------------------<br />
xPropSet.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD);<br />
xPropSet.setPropertyValue("CharWeightAsian", com.sun.star.awt.FontWeight.BOLD);<br />
xPropSet.setPropertyValue("CharWeightComplex", com.sun.star.awt.FontWeight.BOLD);<br />
<br />
}<br />
<br />
See also [[Documentation/DevGuide/FirstSteps/Example:_Working_with_a_Spreadsheet_Document|Working with a Spreadsheet Document (Example)]].<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of <code>mxDocCursor</code>), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:43:11Z
<p>Andreh: added example for making characters bold</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
//--------------------<br />
// use bold font<br />
//--------------------<br />
xPropSet.setPropertyValue("CharWeight", 150.0);<br />
xPropSet.setPropertyValue("CharWeightAsian", 150.0);<br />
xPropSet.setPropertyValue("CharWeightComplex", 150.0);<br />
<br />
}<br />
<br />
See also [[Documentation/DevGuide/FirstSteps/Example:_Working_with_a_Spreadsheet_Document|Working with a Spreadsheet Document (Example)]].<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of <code>mxDocCursor</code>), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:20:32Z
<p>Andreh: added link to example page 'working with a spreadsheet document'</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
}<br />
<br />
See also [[Documentation/DevGuide/FirstSteps/Example:_Working_with_a_Spreadsheet_Document|Working with a Spreadsheet Document (Example)]].<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of <code>mxDocCursor</code>), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:18:30Z
<p>Andreh: added 'code' tags around mxDocCursor</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of <code>mxDocCursor</code>), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:11:32Z
<p>Andreh: added example for horizontal and vertical alignment</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
<br />
//--------------------<br />
// set horizontal alignment to 'centered'<br />
//--------------------<br />
xPropSet.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.CENTER);<br />
<br />
//--------------------<br />
// set vertical alignment to 'top'<br />
//--------------------<br />
xPropSet.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);<br />
<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of mxDocCursor), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:06:54Z
<p>Andreh: fixed missing spaces</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of mxDocCursor), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T21:04:29Z
<p>Andreh: simplified the code: obtaining the properties object only once now</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// get the cell properties<br />
//--------------------<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of mxDocCursor), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T20:46:33Z
<p>Andreh: removed second 'end of table delimiter'</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of mxDocCursor), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T20:45:44Z
<p>Andreh: added example attributes of a cell (obtained from example linked from this page)</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an object of type <idl>com.sun.star.table.XCell</idl> instead of mxDocCursor), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
{| class="wikitable"<br />
|-<br />
! Attribute Name<br />
! Type<br />
! Remark<br />
|-<br />
| AbsoluteName<br />
| string<br />
| READONLY<br />
|-<br />
| AsianVerticalMode <br />
| boolean<br />
|<br />
|-<br />
| BottomBorder <br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| CellBackColor<br />
| long<br />
|<br />
|-<br />
| CellProtection<br />
| <idl>com.sun.star.util.CellProtection</idl><br />
|<br />
|-<br />
| CellStyle<br />
| string<br />
|<br />
|-<br />
| CharColor<br />
| long<br />
|<br />
|-<br />
| CharContoured<br />
| boolean<br />
|<br />
|-<br />
| CharCrossedOut<br />
| boolean<br />
|<br />
|-<br />
| CharEmphasis<br />
| short<br />
|<br />
|-<br />
| CharFont<br />
| short<br />
|<br />
|-<br />
| CharFontCharSet<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetAsian<br />
| short<br />
|<br />
|-<br />
| CharFontCharSetComplex<br />
| short<br />
|<br />
|-<br />
| CharFontFamily<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyAsian<br />
| short<br />
|<br />
|-<br />
| CharFontFamilyComplex<br />
| short<br />
|<br />
|-<br />
| CharFontName<br />
| string<br />
|<br />
|-<br />
| CharFontNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontNameComplex<br />
| string<br />
|<br />
|-<br />
| CharFontPitch<br />
| short<br />
|<br />
|-<br />
| CharFontPitchAsian<br />
| short<br />
|<br />
|-<br />
| CharFontPitchComplex<br />
| short<br />
|<br />
|-<br />
| CharFontStyleName<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameAsian<br />
| string<br />
|<br />
|-<br />
| CharFontStyleNameComplex<br />
| string<br />
|<br />
|-<br />
| CharHeight<br />
| float<br />
|<br />
|-<br />
| CharHeightAsian<br />
| float<br />
|<br />
|-<br />
| CharHeightComplex<br />
| float<br />
|<br />
|-<br />
| CharLocale<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleAsian<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharLocaleComplex<br />
| <idl>com.sun.star.lang.Locale</idl><br />
|<br />
|-<br />
| CharPosture<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureAsian<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharPostureComplex<br />
| <idl>com.sun.star.awt.FontSlant</idl><br />
|<br />
|-<br />
| CharRelief<br />
| short<br />
|<br />
|-<br />
| CharShadowed<br />
| boolean<br />
|<br />
|-<br />
| CharStrikeout<br />
| short<br />
|<br />
|-<br />
| CharUnderline<br />
| short<br />
|<br />
|-<br />
| CharUnderlineColor<br />
| long<br />
|<br />
|-<br />
| CharUnderlineHasColor<br />
| boolean<br />
|<br />
|-<br />
| CharWeight<br />
| float<br />
|<br />
|-<br />
| CharWeightAsian<br />
| float<br />
|<br />
|-<br />
| CharWeightComplex<br />
| float<br />
|<br />
|-<br />
| CharWordMode<br />
| boolean<br />
|<br />
|-<br />
| ChartColumnAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ChartRowAsLabel<br />
| boolean<br />
|<br />
|-<br />
| ConditionalFormat<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatLocal<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
|<br />
|-<br />
| ConditionalFormatXML<br />
| <idl>com.sun.star.sheet.XSheetConditionalEntries</idl><br />
| READONLY<br />
|-<br />
| DiagonalBLTR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| DiagonalTLBR<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| FormulaLocal<br />
| string<br />
|<br />
|-<br />
| FormulaResultType<br />
| <idl>com.sun.star.table.CellContentType</idl><br />
| READONLY<br />
|-<br />
| HoriJustify<br />
| <idl>com.sun.star.table.CellHoriJustify</idl><br />
|<br />
|-<br />
| IsCellBackgroundTransparent<br />
| boolean<br />
|<br />
|-<br />
| IsTextWrapped<br />
| boolean<br />
|<br />
|-<br />
| LeftBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| NumberFormat<br />
| long<br />
|<br />
|-<br />
| NumberingRules<br />
| <idl>com.sun.star.container.XIndexReplace</idl><br />
|<br />
|-<br />
| Orientation<br />
| <idl>com.sun.star.table.CellOrientation</idl><br />
|<br />
|-<br />
| ParaAdjust<br />
| short<br />
|<br />
|-<br />
| ParaBottomMargin<br />
| long<br />
|<br />
|-<br />
| ParaIndent<br />
| short<br />
|<br />
|-<br />
| ParaIsCharacterDistance<br />
| boolean<br />
|<br />
|-<br />
| ParaIsForbiddenRules<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHangingPunctuation<br />
| boolean<br />
|<br />
|-<br />
| ParaIsHyphenation<br />
| boolean<br />
|<br />
|-<br />
| ParaLastLineAdjust<br />
| short<br />
|<br />
|-<br />
| ParaLeftMargin<br />
| long<br />
|<br />
|-<br />
| ParaRightMargin<br />
| long<br />
|<br />
|-<br />
| ParaTopMargin<br />
| long<br />
|<br />
|-<br />
| Position<br />
| <idl>com.sun.star.awt.Point</idl><br />
| READONLY<br />
|-<br />
| RightBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| RotateAngle<br />
| long<br />
|<br />
|-<br />
| RotateReference<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| ShadowFormat<br />
| <idl>com.sun.star.table.ShadowFormat</idl><br />
|<br />
|-<br />
| ShrinkToFit<br />
| boolean<br />
|<br />
|-<br />
| Size<br />
| <idl>com.sun.star.awt.Size</idl><br />
| READONLY<br />
|-<br />
| TableBorder<br />
| <idl>com.sun.star.table.TableBorder</idl><br />
|<br />
|-<br />
| TopBorder<br />
| <idl>com.sun.star.table.BorderLine</idl><br />
|<br />
|-<br />
| UserDefinedAttributes<br />
| <idl>com.sun.star.container.XNameContainer</idl><br />
|<br />
|-<br />
| Validation<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationLocal<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
|<br />
|-<br />
| ValidationXML<br />
| <idl>com.sun.star.beans.XPropertySet</idl><br />
| READONLY<br />
|-<br />
| VertJustify<br />
| <idl>com.sun.star.table.CellVertJustify</idl><br />
|<br />
|-<br />
| WritingMode<br />
| short<br />
|<br />
|}<br />
<br />
|}<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T20:29:27Z
<p>Andreh: will add a list of example properties</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
Running [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|an example showing how to find out which properties an object provides]] (with an <idl>com.sun.star.table.XCell</idl> object instead of mxDocCursor), one gets for example the following properties (OpenOffice.org 2.4):<br />
<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T20:07:25Z
<p>Andreh: fixed link added in previous edit</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
See also: [[Documentation/DevGuide/ProUNO/Properties#Example:_find_out_which_properties_an_object_provides|example showing how to find out which properties an object provides]]<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T20:05:25Z
<p>Andreh: added a link to the example how to obtain properties of an object</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
See also: [[Properties#Example:_find_out_which_properties_an_object_provides|example showing how to find out which properties an object provides]]<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Properties
Documentation/DevGuide/ProUNO/Properties
2009-10-01T19:57:51Z
<p>Andreh: added more section headings for examples</p>
<hr />
<div>{{Documentation/DevGuide/ProUNOTOC<br />
|ProUNO2b=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/ProUNO/Using UNO Interfaces<br />
|NextPage=Documentation/DevGuide/ProUNO/Collections and Containers<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}}<br />
{{DISPLAYTITLE:Properties}}<br />
<!--<idltopic>com.sun.star.beans.XPropertySet;com.sun.star.beans.XMultiPropertySet;com.sun.star.beans.XFastPropertySet;com.sun.star.beans.XPropertySetInfo;com.sun.star.beans.XPropertyState</idltopic>--><br />
Properties are name-value pairs belonging to a service and determine the characteristics of an object in a service instance. Usually, properties are used for non-structural attributes, such as font, size or color of objects, whereas get and set methods are used for structural attributes like a parent or sub-object.<br />
<br />
In almost all cases, <idl>com.sun.star.beans.XPropertySet</idl> is used to access properties by name. Other interfaces, for example, are <idl>com.sun.star.beans.XPropertyAccess</idl> which is used to set and retrieve all properties at once or <idl>com.sun.star.beans.XMultiPropertySet</idl> which is used to access several specified properties at once. This is useful on remote connections. Additionally, there are interfaces to access properties by numeric ID, such as <idl>com.sun.star.beans.XFastPropertySet</idl>.<br />
<br />
==== Example: query and change the properties ====<br />
<br />
The following example demonstrates how to query and change the properties of a given text document cursor using its XPropertySet interface:<br />
<source lang="java"><br />
// get an XPropertySet, here the one of a text cursor<br />
XPropertySet xCursorProps = (XPropertySet) <br />
UnoRuntime.queryInterface(XPropertySet.class, mxDocCursor);<br />
<br />
// get the character weight property <br />
Object aCharWeight = xCursorProps.getPropertyValue("CharWeight");<br />
float fCharWeight = AnyConverter.toFloat(aCharWeight);<br />
System.out.println("before: CharWeight=" + fCharWeight);<br />
<br />
// set the character weight property to BOLD<br />
xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD));<br />
<br />
// get the character weight property again<br />
aCharWeight = xCursorProps.getPropertyValue("CharWeight");<br />
fCharWeight = AnyConverter.toFloat(aCharWeight);<br />
System.out.println("after: CharWeight=" + fCharWeight);<br />
</source><br />
A possible output of this code could be:<br />
<br />
before: CharWeight=100.0<br />
after: CharWeight=150.0<br />
<br />
{{Documentation/Caution|The sequence of property names must be sorted.}}<br />
<br />
==== Example: dealing with multiple properties at once ====<br />
<br />
The following example deals with multiple properties at once:<br />
<source lang="java"><br />
// get an XMultiPropertySet, here the one of the first paragraph<br />
XEnumerationAccess xEnumAcc = (XEnumerationAccess) UnoRuntime.queryInterface(<br />
XEnumerationAccess.class, mxDocText);<br />
XEnumeration xEnum = xEnumAcc.createEnumeration();<br />
Object aPara = xEnum.nextElement();<br />
XMultiPropertySet xParaProps = (XMultiPropertySet) UnoRuntime.queryInterface(<br />
XMultiPropertySet.class, aPara);<br />
<br />
// get three property values with a single UNO call<br />
String[] aNames = new String[3];<br />
aNames[0] = "CharColor";<br />
aNames[1] = "CharFontName";<br />
aNames[2] = "CharWeight";<br />
Object[] aValues = xParaProps.getPropertyValues(aNames);<br />
<br />
// print the three values<br />
System.out.println("CharColor=" + AnyConverter.toLong(aValues[0]));<br />
System.out.println("CharFontName=" + AnyConverter.toString(aValues[1]));<br />
System.out.println("CharWeight=" + AnyConverter.toFloat(aValues[2]));<br />
</source><br />
Properties can be assigned flags to determine a specific behavior of the property, such as read-only, bound, constrained or void. Possible flags are specified in <idl>com.sun.star.beans.PropertyAttribute</idl>. Read-only properties cannot be set. Bound properties broadcast changes of their value to registered listeners and constrained properties veto changes to these listeners.<br />
<br />
Properties might have a status specifying where the value comes from. See <idl>com.sun.star.beans.XPropertyState</idl>. The value determines if the value comes from the object, a style sheet or if it cannot be determined at all. For example, in a multi-selection with multiple values within this selection.<br />
<br />
==== Example: obtain status information of property values ====<br />
<br />
The following example shows how to find out status information about property values:<br />
<source lang="java"><br />
// get an XPropertySet, here the one of a text cursor<br />
XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(<br />
XPropertySet.class, mxDocCursor);<br />
<br />
// insert "first" in NORMAL character weight<br />
mxDocText.insertString(mxDocCursor, "first ", true);<br />
xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.NORMAL));<br />
<br />
// append "second" in BOLD character weight<br />
mxDocCursor.collapseToEnd();<br />
mxDocText.insertString(mxDocCursor, "second", true);<br />
xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD));<br />
<br />
// try to get the character weight property of BOTH words<br />
mxDocCursor.gotoStart(true);<br />
try {<br />
Object aCharWeight = xCursorProps.getPropertyValue("CharWeight");<br />
float fCharWeight = AnyConverter.toFloat(aCharWeight );<br />
System.out.println("CharWeight=" + fCharWeight);<br />
} catch (NullPointerException e) { <br />
System.out.println("CharWeight property is NULL");<br />
}<br />
<br />
// query the XPropertState interface of the cursor properties<br />
XPropertyState xCursorPropsState = (XPropertyState) UnoRuntime.queryInterface(<br />
XPropertyState.class, xCursorProps);<br />
<br />
// get the status of the character weight property<br />
PropertyState eCharWeightState = xCursorPropsState.getPropertyState("CharWeight");<br />
System.out.print("CharWeight property state has ");<br />
if (eCharWeightState == PropertyState.AMBIGUOUS_VALUE)<br />
System.out.println("an ambiguous value");<br />
else<br />
System.out.println("a clear value");<br />
</source><br />
The property state of character weight is queried for a string like this:<br />
<br />
first '''second'''<br />
<br />
And the output is:<br />
<br />
CharWeight property is NULL<br />
CharWeight property state has an ambiguous value<br />
<br />
The description of properties available for a certain object is given by <idl>com.sun.star.beans.XPropertySetInfo</idl>. Multiple objects can share the same property information for their description. This makes it easier for introspective caches that are used in scripting languages where the properties are accessed directly, without directly calling the methods of the interfaces mentioned above.<br />
<br />
==== Example: find out which properties an object provides ====<br />
<br />
This example shows how to find out which properties an object provides using <idl>com.sun.star.beans.XPropertySetInfo</idl>:<br />
<source lang="java"><br />
try {<br />
// get an XPropertySet, here the one of a text cursor<br />
XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(<br />
XPropertySet.class, mxDocCursor);<br />
<br />
// get the property info interface of this XPropertySet<br />
XPropertySetInfo xCursorPropsInfo = xCursorProps.getPropertySetInfo();<br />
<br />
// get all properties (NOT the values) from XPropertySetInfo<br />
Property[] aProps = xCursorPropsInfo.getProperties();<br />
int i;<br />
for (i = 0; i < aProps.length; ++i) {<br />
// number of property within this info object<br />
System.out.print("Property #" + i);<br />
<br />
// name of property<br />
System.out.print(": Name<" + aProps[i].Name);<br />
<br />
// handle of property (only for XFastPropertySet)<br />
System.out.print("> Handle<" + aProps[i].Handle);<br />
<br />
// type of property<br />
System.out.print("> " + aProps[i].Type.toString());<br />
<br />
// attributes (flags)<br />
System.out.print(" Attributes<");<br />
short nAttribs = aProps[i].Attributes;<br />
if ((nAttribs & PropertyAttribute.MAYBEVOID) != 0)<br />
System.out.print("MAYBEVOID|");<br />
if ((nAttribs & PropertyAttribute.BOUND) != 0)<br />
System.out.print("BOUND|");<br />
if ((nAttribs & PropertyAttribute.CONSTRAINED) != 0)<br />
System.out.print("CONSTRAINED|");<br />
if ((nAttribs & PropertyAttribute.READONLY) != 0)<br />
System.out.print("READONLY|");<br />
if ((nAttribs & PropertyAttribute.TRANSIENT) != 0)<br />
System.out.print("TRANSIENT|");<br />
if ((nAttribs & PropertyAttribute.MAYBEAMBIGUOUS ) != 0)<br />
System.out.print("MAYBEAMBIGUOUS|");<br />
if ((nAttribs & PropertyAttribute.MAYBEDEFAULT) != 0)<br />
System.out.print("MAYBEDEFAULT|");<br />
if ((nAttribs & PropertyAttribute.REMOVEABLE) != 0)<br />
System.out.print("REMOVEABLE|");<br />
System.out.println("0>");<br />
}<br />
} catch (Exception e) {<br />
// If anything goes wrong, give the user a stack trace<br />
e.printStackTrace(System.out);<br />
}<br />
</source><br />
The following is an example output for the code above. The output shows the names of the text cursor properties, and their handle, type and property attributes. The handle is not unique, since the specific object does not implement <idl>com.sun.star.beans.XFastPropertySet</idl>, so proper handles are not needed here.<br />
<br />
Using default connect string: socket,host=localhost,port=8100<br />
Opening an empty Writer document<br />
Property #0: Name<BorderDistance> Handle<93> Type<long> Attributes<MAYBEVOID|0><br />
Property #1: Name<BottomBorder> Handle<93> Type<com.sun.star.table.BorderLine> Attributes<MAYBEVOID|0><br />
Property #2: Name<BottomBorderDistance> Handle<93> Type<long> Attributes<MAYBEVOID|0><br />
Property #3: Name<BreakType> Handle<81> Type<com.sun.star.style.BreakType> Attributes<MAYBEVOID|0><br />
<br />
...<br />
<br />
Property #133: Name<TopBorderDistance> Handle<93> Type<long> Attributes<MAYBEVOID|0><br />
Property #134: Name<UnvisitedCharStyleName> Handle<38> =Type<string> Attributes<MAYBEVOID|0><br />
Property #135: Name<VisitedCharStyleName> Handle<38> Type<string> Attributes<MAYBEVOID|0><br />
<br />
In some cases properties are used to specify the options in a sequence of <idl>com.sun.star.beans.PropertyValue</idl>. See <idl>com.sun.star.view.PrintOptions</idl> or <idl>com.sun.star.document.MediaDescriptor</idl> for examples of properties in sequences. These are not accessed by the methods mentioned above, but by accessing the sequence specified in the language binding.<br />
<br />
==== Example: sequences of property values ====<br />
<br />
This example illustrates how to deal with sequences of property values:<br />
<source lang="java"><br />
// create a sequence of PropertyValue<br />
PropertyValue[] aArgs = new PropertyValue[2];<br />
<br />
// set name/value pairs (other fields are irrelevant here)<br />
aArgs[0] = new PropertyValue();<br />
aArgs[0].Name = "FilterName";<br />
aArgs[0].Value = "HTML (StarWriter)";<br />
aArgs[1] = new PropertyValue();<br />
aArgs[1].Name = "Overwrite";<br />
aArgs[1].Value = Boolean.TRUE;<br />
<br />
// use this sequence of PropertyValue as an argument<br />
// where a service with properties but without any interfaces is specified<br />
com.sun.star.frame.XStorable xStorable = (com.sun.star.frame.XStorable) UnoRuntime.queryInterface(<br />
com.sun.star.frame.XStorable.class, mxDoc);<br />
xStorable.storeAsURL("file:///tmp/devmanual-test.html", aArgs);<br />
</source><br />
Usually the properties supported by an object, as well as their type and flags are fixed over the lifetime of the object. There may be exceptions. If the properties can be added and removed externally, the interface <idl>com.sun.star.beans.XPropertyContainer</idl> has to be used. In this case, the fixed <idl>com.sun.star.beans.XPropertySetInfo</idl> changes its supplied information over the lifetime of the object. Listeners for such changes can register at <idl>com.sun.star.beans.XPropertyChangeListener</idl>.<br />
<br />
{{Documentation/Tip|If you use a component from other processes or remotely, try to adhere to the rule to use <idl>com.sun.star.beans.XPropertyAccess</idl> and <idl>com.sun.star.beans.XMultiPropertySet</idl> instead of having a separate call for each single property.}}<br />
<br />
The following diagram shows the relationship between the property-related interfaces.<br />
<br />
[[Image:Properties.png|none|thumb|400px|The relationship between property related interfaces]]<br />
<br />
Starting with {{PRODUCTNAME}} {{OOo2.x}}, interface attributes are comparable in expressiveness to the properties described above:<br />
<br />
* A <code>[property] T P</code> (with type <code>T</code> and name <code>P</code>) corresponds to an <code>[attribute] T P</code>.<br />
* A <code>[property, readonly] T P</code> corresponds to an <code>[attribute, readonly] T P</code>.<br />
* A <code>[property, bound] T P</code> corresponds to an <code>[attribute, bound] T P</code>.<br />
* A <code>[property, maybeambiguous] T P</code> corresponds to an <code>[attribute] com.sun.star.beans.Ambiguous<T> P</code>.<br />
* A <code>[property, maybedefault] T P</code> corresponds to an <code>[attribute] com.sun.star.beans.Defaulted<T> P</code>.<br />
* A <code>[property, maybevoid] T P</code> corresponds to an <code>[attribute] com.sun.star.beans.Optional<T> P</code>.<br />
* A <code>[property, optional] T P</code> corresponds to an <code>[attribute] T P { get raises (com.sun.star.beans.UnknownPropertyException); set raises (com.sun.star.beans.UnknownPropertyException); }</code>.<br />
* A <code>[property, constrained] T P</code> corresponds to an <code>[attribute] T P { set raises (com.sun.star.beans.PropertyVetoException); }</code>.<br />
<br />
Interface attributes offer the following advantages compared to properties:<br />
<br />
* The attributes an object supports follows directly from the description of the interface types the object supports.<br />
* Accessing an interface attribute is type-safe, whereas accessing a property uses the generic any. This is an advantage mainly in statically typed languages like Java and C++, where accessing an interface attribute typically also requires less code to be written than for accessing a generic property.<br />
<br />
The main disadvantage is that the set of interface attributes supported by an object is static, so that scenarios that exploit the dynamic nature of <code>XpropertySet</code>, and so on, do not map well to interface attributes. In cases where it might be useful to have all the interface attributes supported by an object also accessible via <code>XPropertySet</code> etc., the Java and C++ language bindings offer experimental, not yet published support to do just that.See [http://www.openoffice.org www.openoffice.org] to find out more.<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Professional UNO]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Properties
Documentation/DevGuide/ProUNO/Properties
2009-10-01T19:55:32Z
<p>Andreh: added section header for some examples (will allow referencing from other pages of this wiki)</p>
<hr />
<div>{{Documentation/DevGuide/ProUNOTOC<br />
|ProUNO2b=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/ProUNO/Using UNO Interfaces<br />
|NextPage=Documentation/DevGuide/ProUNO/Collections and Containers<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}}<br />
{{DISPLAYTITLE:Properties}}<br />
<!--<idltopic>com.sun.star.beans.XPropertySet;com.sun.star.beans.XMultiPropertySet;com.sun.star.beans.XFastPropertySet;com.sun.star.beans.XPropertySetInfo;com.sun.star.beans.XPropertyState</idltopic>--><br />
Properties are name-value pairs belonging to a service and determine the characteristics of an object in a service instance. Usually, properties are used for non-structural attributes, such as font, size or color of objects, whereas get and set methods are used for structural attributes like a parent or sub-object.<br />
<br />
In almost all cases, <idl>com.sun.star.beans.XPropertySet</idl> is used to access properties by name. Other interfaces, for example, are <idl>com.sun.star.beans.XPropertyAccess</idl> which is used to set and retrieve all properties at once or <idl>com.sun.star.beans.XMultiPropertySet</idl> which is used to access several specified properties at once. This is useful on remote connections. Additionally, there are interfaces to access properties by numeric ID, such as <idl>com.sun.star.beans.XFastPropertySet</idl>.<br />
<br />
==== Example: query and change the properties ====<br />
<br />
The following example demonstrates how to query and change the properties of a given text document cursor using its XPropertySet interface:<br />
<source lang="java"><br />
// get an XPropertySet, here the one of a text cursor<br />
XPropertySet xCursorProps = (XPropertySet) <br />
UnoRuntime.queryInterface(XPropertySet.class, mxDocCursor);<br />
<br />
// get the character weight property <br />
Object aCharWeight = xCursorProps.getPropertyValue("CharWeight");<br />
float fCharWeight = AnyConverter.toFloat(aCharWeight);<br />
System.out.println("before: CharWeight=" + fCharWeight);<br />
<br />
// set the character weight property to BOLD<br />
xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD));<br />
<br />
// get the character weight property again<br />
aCharWeight = xCursorProps.getPropertyValue("CharWeight");<br />
fCharWeight = AnyConverter.toFloat(aCharWeight);<br />
System.out.println("after: CharWeight=" + fCharWeight);<br />
</source><br />
A possible output of this code could be:<br />
<br />
before: CharWeight=100.0<br />
after: CharWeight=150.0<br />
<br />
{{Documentation/Caution|The sequence of property names must be sorted.}}<br />
<br />
The following example deals with multiple properties at once:<br />
<source lang="java"><br />
// get an XMultiPropertySet, here the one of the first paragraph<br />
XEnumerationAccess xEnumAcc = (XEnumerationAccess) UnoRuntime.queryInterface(<br />
XEnumerationAccess.class, mxDocText);<br />
XEnumeration xEnum = xEnumAcc.createEnumeration();<br />
Object aPara = xEnum.nextElement();<br />
XMultiPropertySet xParaProps = (XMultiPropertySet) UnoRuntime.queryInterface(<br />
XMultiPropertySet.class, aPara);<br />
<br />
// get three property values with a single UNO call<br />
String[] aNames = new String[3];<br />
aNames[0] = "CharColor";<br />
aNames[1] = "CharFontName";<br />
aNames[2] = "CharWeight";<br />
Object[] aValues = xParaProps.getPropertyValues(aNames);<br />
<br />
// print the three values<br />
System.out.println("CharColor=" + AnyConverter.toLong(aValues[0]));<br />
System.out.println("CharFontName=" + AnyConverter.toString(aValues[1]));<br />
System.out.println("CharWeight=" + AnyConverter.toFloat(aValues[2]));<br />
</source><br />
Properties can be assigned flags to determine a specific behavior of the property, such as read-only, bound, constrained or void. Possible flags are specified in <idl>com.sun.star.beans.PropertyAttribute</idl>. Read-only properties cannot be set. Bound properties broadcast changes of their value to registered listeners and constrained properties veto changes to these listeners.<br />
<br />
Properties might have a status specifying where the value comes from. See <idl>com.sun.star.beans.XPropertyState</idl>. The value determines if the value comes from the object, a style sheet or if it cannot be determined at all. For example, in a multi-selection with multiple values within this selection.<br />
<br />
The following example shows how to find out status information about property values:<br />
<source lang="java"><br />
// get an XPropertySet, here the one of a text cursor<br />
XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(<br />
XPropertySet.class, mxDocCursor);<br />
<br />
// insert "first" in NORMAL character weight<br />
mxDocText.insertString(mxDocCursor, "first ", true);<br />
xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.NORMAL));<br />
<br />
// append "second" in BOLD character weight<br />
mxDocCursor.collapseToEnd();<br />
mxDocText.insertString(mxDocCursor, "second", true);<br />
xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD));<br />
<br />
// try to get the character weight property of BOTH words<br />
mxDocCursor.gotoStart(true);<br />
try {<br />
Object aCharWeight = xCursorProps.getPropertyValue("CharWeight");<br />
float fCharWeight = AnyConverter.toFloat(aCharWeight );<br />
System.out.println("CharWeight=" + fCharWeight);<br />
} catch (NullPointerException e) { <br />
System.out.println("CharWeight property is NULL");<br />
}<br />
<br />
// query the XPropertState interface of the cursor properties<br />
XPropertyState xCursorPropsState = (XPropertyState) UnoRuntime.queryInterface(<br />
XPropertyState.class, xCursorProps);<br />
<br />
// get the status of the character weight property<br />
PropertyState eCharWeightState = xCursorPropsState.getPropertyState("CharWeight");<br />
System.out.print("CharWeight property state has ");<br />
if (eCharWeightState == PropertyState.AMBIGUOUS_VALUE)<br />
System.out.println("an ambiguous value");<br />
else<br />
System.out.println("a clear value");<br />
</source><br />
The property state of character weight is queried for a string like this:<br />
<br />
first '''second'''<br />
<br />
And the output is:<br />
<br />
CharWeight property is NULL<br />
CharWeight property state has an ambiguous value<br />
<br />
The description of properties available for a certain object is given by <idl>com.sun.star.beans.XPropertySetInfo</idl>. Multiple objects can share the same property information for their description. This makes it easier for introspective caches that are used in scripting languages where the properties are accessed directly, without directly calling the methods of the interfaces mentioned above.<br />
<br />
==== Example: find out which properties an object provides ====<br />
<br />
This example shows how to find out which properties an object provides using <idl>com.sun.star.beans.XPropertySetInfo</idl>:<br />
<source lang="java"><br />
try {<br />
// get an XPropertySet, here the one of a text cursor<br />
XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(<br />
XPropertySet.class, mxDocCursor);<br />
<br />
// get the property info interface of this XPropertySet<br />
XPropertySetInfo xCursorPropsInfo = xCursorProps.getPropertySetInfo();<br />
<br />
// get all properties (NOT the values) from XPropertySetInfo<br />
Property[] aProps = xCursorPropsInfo.getProperties();<br />
int i;<br />
for (i = 0; i < aProps.length; ++i) {<br />
// number of property within this info object<br />
System.out.print("Property #" + i);<br />
<br />
// name of property<br />
System.out.print(": Name<" + aProps[i].Name);<br />
<br />
// handle of property (only for XFastPropertySet)<br />
System.out.print("> Handle<" + aProps[i].Handle);<br />
<br />
// type of property<br />
System.out.print("> " + aProps[i].Type.toString());<br />
<br />
// attributes (flags)<br />
System.out.print(" Attributes<");<br />
short nAttribs = aProps[i].Attributes;<br />
if ((nAttribs & PropertyAttribute.MAYBEVOID) != 0)<br />
System.out.print("MAYBEVOID|");<br />
if ((nAttribs & PropertyAttribute.BOUND) != 0)<br />
System.out.print("BOUND|");<br />
if ((nAttribs & PropertyAttribute.CONSTRAINED) != 0)<br />
System.out.print("CONSTRAINED|");<br />
if ((nAttribs & PropertyAttribute.READONLY) != 0)<br />
System.out.print("READONLY|");<br />
if ((nAttribs & PropertyAttribute.TRANSIENT) != 0)<br />
System.out.print("TRANSIENT|");<br />
if ((nAttribs & PropertyAttribute.MAYBEAMBIGUOUS ) != 0)<br />
System.out.print("MAYBEAMBIGUOUS|");<br />
if ((nAttribs & PropertyAttribute.MAYBEDEFAULT) != 0)<br />
System.out.print("MAYBEDEFAULT|");<br />
if ((nAttribs & PropertyAttribute.REMOVEABLE) != 0)<br />
System.out.print("REMOVEABLE|");<br />
System.out.println("0>");<br />
}<br />
} catch (Exception e) {<br />
// If anything goes wrong, give the user a stack trace<br />
e.printStackTrace(System.out);<br />
}<br />
</source><br />
The following is an example output for the code above. The output shows the names of the text cursor properties, and their handle, type and property attributes. The handle is not unique, since the specific object does not implement <idl>com.sun.star.beans.XFastPropertySet</idl>, so proper handles are not needed here.<br />
<br />
Using default connect string: socket,host=localhost,port=8100<br />
Opening an empty Writer document<br />
Property #0: Name<BorderDistance> Handle<93> Type<long> Attributes<MAYBEVOID|0><br />
Property #1: Name<BottomBorder> Handle<93> Type<com.sun.star.table.BorderLine> Attributes<MAYBEVOID|0><br />
Property #2: Name<BottomBorderDistance> Handle<93> Type<long> Attributes<MAYBEVOID|0><br />
Property #3: Name<BreakType> Handle<81> Type<com.sun.star.style.BreakType> Attributes<MAYBEVOID|0><br />
<br />
...<br />
<br />
Property #133: Name<TopBorderDistance> Handle<93> Type<long> Attributes<MAYBEVOID|0><br />
Property #134: Name<UnvisitedCharStyleName> Handle<38> =Type<string> Attributes<MAYBEVOID|0><br />
Property #135: Name<VisitedCharStyleName> Handle<38> Type<string> Attributes<MAYBEVOID|0><br />
<br />
In some cases properties are used to specify the options in a sequence of <idl>com.sun.star.beans.PropertyValue</idl>. See <idl>com.sun.star.view.PrintOptions</idl> or <idl>com.sun.star.document.MediaDescriptor</idl> for examples of properties in sequences. These are not accessed by the methods mentioned above, but by accessing the sequence specified in the language binding.<br />
<br />
This example illustrates how to deal with sequences of property values:<br />
<source lang="java"><br />
// create a sequence of PropertyValue<br />
PropertyValue[] aArgs = new PropertyValue[2];<br />
<br />
// set name/value pairs (other fields are irrelevant here)<br />
aArgs[0] = new PropertyValue();<br />
aArgs[0].Name = "FilterName";<br />
aArgs[0].Value = "HTML (StarWriter)";<br />
aArgs[1] = new PropertyValue();<br />
aArgs[1].Name = "Overwrite";<br />
aArgs[1].Value = Boolean.TRUE;<br />
<br />
// use this sequence of PropertyValue as an argument<br />
// where a service with properties but without any interfaces is specified<br />
com.sun.star.frame.XStorable xStorable = (com.sun.star.frame.XStorable) UnoRuntime.queryInterface(<br />
com.sun.star.frame.XStorable.class, mxDoc);<br />
xStorable.storeAsURL("file:///tmp/devmanual-test.html", aArgs);<br />
</source><br />
Usually the properties supported by an object, as well as their type and flags are fixed over the lifetime of the object. There may be exceptions. If the properties can be added and removed externally, the interface <idl>com.sun.star.beans.XPropertyContainer</idl> has to be used. In this case, the fixed <idl>com.sun.star.beans.XPropertySetInfo</idl> changes its supplied information over the lifetime of the object. Listeners for such changes can register at <idl>com.sun.star.beans.XPropertyChangeListener</idl>.<br />
<br />
{{Documentation/Tip|If you use a component from other processes or remotely, try to adhere to the rule to use <idl>com.sun.star.beans.XPropertyAccess</idl> and <idl>com.sun.star.beans.XMultiPropertySet</idl> instead of having a separate call for each single property.}}<br />
<br />
The following diagram shows the relationship between the property-related interfaces.<br />
<br />
[[Image:Properties.png|none|thumb|400px|The relationship between property related interfaces]]<br />
<br />
Starting with {{PRODUCTNAME}} {{OOo2.x}}, interface attributes are comparable in expressiveness to the properties described above:<br />
<br />
* A <code>[property] T P</code> (with type <code>T</code> and name <code>P</code>) corresponds to an <code>[attribute] T P</code>.<br />
* A <code>[property, readonly] T P</code> corresponds to an <code>[attribute, readonly] T P</code>.<br />
* A <code>[property, bound] T P</code> corresponds to an <code>[attribute, bound] T P</code>.<br />
* A <code>[property, maybeambiguous] T P</code> corresponds to an <code>[attribute] com.sun.star.beans.Ambiguous<T> P</code>.<br />
* A <code>[property, maybedefault] T P</code> corresponds to an <code>[attribute] com.sun.star.beans.Defaulted<T> P</code>.<br />
* A <code>[property, maybevoid] T P</code> corresponds to an <code>[attribute] com.sun.star.beans.Optional<T> P</code>.<br />
* A <code>[property, optional] T P</code> corresponds to an <code>[attribute] T P { get raises (com.sun.star.beans.UnknownPropertyException); set raises (com.sun.star.beans.UnknownPropertyException); }</code>.<br />
* A <code>[property, constrained] T P</code> corresponds to an <code>[attribute] T P { set raises (com.sun.star.beans.PropertyVetoException); }</code>.<br />
<br />
Interface attributes offer the following advantages compared to properties:<br />
<br />
* The attributes an object supports follows directly from the description of the interface types the object supports.<br />
* Accessing an interface attribute is type-safe, whereas accessing a property uses the generic any. This is an advantage mainly in statically typed languages like Java and C++, where accessing an interface attribute typically also requires less code to be written than for accessing a generic property.<br />
<br />
The main disadvantage is that the set of interface attributes supported by an object is static, so that scenarios that exploit the dynamic nature of <code>XpropertySet</code>, and so on, do not map well to interface attributes. In cases where it might be useful to have all the interface attributes supported by an object also accessible via <code>XPropertySet</code> etc., the Java and C++ language bindings offer experimental, not yet published support to do just that.See [http://www.openoffice.org www.openoffice.org] to find out more.<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Professional UNO]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T19:37:12Z
<p>Andreh: added spaces for correct formatting</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Example:_Editing_Spreadsheet_Cells
Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells
2009-10-01T19:36:17Z
<p>Andreh: added setting of background and foreground (text) color</p>
<hr />
<div>{{Documentation/DevGuide/SpreadsheetsTOC<br />
|SpreadsheetDocs2a=block<br />
|ShowPrevNext=block<br />
|PrevPage=Documentation/DevGuide/Spreadsheets/Example: Adding a New Spreadsheet<br />
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files<br />
}}<br />
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} <br />
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}<br />
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>: <br />
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]--><br />
<br />
void cellWork(XSpreadsheet xRange) {<br />
<br />
com.sun.star.beans.XPropertySet xPropSet = null;<br />
com.sun.star.table.XCell xCell = null;<br />
<br />
// Access and modify a VALUE CELL<br />
xCell = xRange.getCellByPosition(0, 0);<br />
// Set cell value.<br />
xCell.setValue(1234);<br />
<br />
// Get cell value.<br />
double nDblValue = xCell.getValue() * 2;<br />
xRange.getCellByPosition(0, 1).setValue(nDblValue);<br />
<br />
// Create a FORMULA CELL<br />
xCell = xRange.getCellByPosition(0, 2);<br />
// Set formula string.<br />
xCell.setFormula("=1/0");<br />
<br />
// Get error type.<br />
boolean bValid = (xCell.getError() == 0);<br />
// Get formula string.<br />
String aText = "The formula " + xCell.getFormula() + " is ";<br />
aText += bValid ? "valid." : "erroneous.";<br />
<br />
// Insert a TEXT CELL using the XText interface<br />
xCell = xRange.getCellByPosition(0, 3);<br />
com.sun.star.text.XText xCellText = (com.sun.star.text.XText)<br />
UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);<br />
com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();<br />
xCellText.insertString(xTextCursor, aText, false);<br />
<br />
//--------------------<br />
// set the cell's background color<br />
//--------------------<br />
<br />
Integer bg_color = new Integer(0x008000);<br />
xPropSet = (com.sun.star.beans.XPropertySet)<br />
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CellBackColor", bg_color);<br />
<br />
//--------------------<br />
// set the cell's foreground (text) color<br />
//--------------------<br />
<br />
Integer fg_color = new Integer(0x800000);<br />
xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,<br />
xCell);<br />
<br />
xPropSet.setPropertyValue("CharColor", fg_color);<br />
}<br />
<br />
<br />
{{PDL1}}<br />
<br />
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]</div>
Andreh