2017-07-02

28: To Get and Set Spread Sheet Cell String Formats (Format Properties)

<The previous article in this series | The table of contents of this series | The next article in this series>

Main body START

To Know How to Handle (Read or Write) LibreOffice or Apache OpenOffice Calc Spread Sheets via Extensions from Java or Macro Programs

How Can We Get or Set Spread Sheet Cell String Formats?

-Hypothesizer

As we have set some spread sheet cell format properties, we can also set some format properties to sub strings in the spread sheet cell.

-Rebutter

I see.

-Hypothesizer

Again, I'm not interested in enumerating all the format properties; we will talk about only some format properties that seem useful, to us.

-Rebutter

OK.

-Hypothesizer

We will handle only these properties.

  • font color
  • font name
  • font size
  • font posture
  • font weight
  • text underline style
  • whether text underline color is automatic
  • text underline color
  • text overline style
  • whether text overline color is automatic
  • text overline color
  • text strikeout style
-Rebutter

They are a subset of spread sheet cell format properties. Obviously, sub strings don't have properties like a borderline.

-Hypothesizer

Yes. As names and values to be set are the same with those of spread sheet cell format properties, I won't cite them here.

-Rebutter

All right.

-Hypothesizer

We can handle spread sheet cell string format properties using a 'com.sun.star.text.XTextCursor' instance gotten from the cell UNO object.

-Rebutter

I see.

-Hypothesizer

The UNO component of the cursor UNO object implements the 'com.sun.star.beans.XPropertySet' UNO interface, and we just get a UNO proxy for the UNO interface and do the same thing as we did with spread sheet cell format properties.

However, actually, I don't know why, but I couldn't successfully set the text underline color.

-Rebutter

How you couldn't?

-Hypothesizer

Uncannily.

-Rebutter

I'm asking what happens when you try to set a text underline color.

-Hypothesizer

Whatever color I set, the underline becomes white.

-Rebutter

While overline colors can be set successfully?

-Hypothesizer

Yes. Only underlines becomes white.

-Rebutter

That's uncanny.

-Hypothesizer

As white is usually invisible, for the time being, we will make text underline colors automatic. As we don't have any necessity to color underlines, that won't be a trouble.

-Rebutter

OK.

-Hypothesizer

After all, I have written this code after the code of the previous article.

   l_textCursor.gotoStart (false);
   l_textCursor.goRight ( (short) 1,false);
   l_textCursor.goRight ( (short) 2,true);
   XPropertySet l_textCursorInXPropertySet = (XPropertySet) UnoRuntime.queryInterface (XPropertySet.class, l_textCursor);
   l_textCursorInXPropertySet.setPropertyValue ("CharColor", new Integer ( (new Color (0, 255, 0)).getRGB ()));
   l_textCursorInXPropertySet.setPropertyValue ("CharFontName", "Liberation Mono");
   l_textCursorInXPropertySet.setPropertyValue ("CharHeight", new Float (16.0F));
   l_textCursorInXPropertySet.setPropertyValue ("CharPosture", FontSlant.ITALIC);
   l_textCursorInXPropertySet.setPropertyValue ("CharWeight", new Float (FontWeight.BOLD));
   l_textCursorInXPropertySet.setPropertyValue ("CharUnderline", new Short (FontUnderline.DOTTED));
   l_textCursorInXPropertySet.setPropertyValue ("CharUnderlineHasColor", new Boolean (false));
   //l_currentSpreadSheetCellInXPropertySet.setPropertyValue ("CharUnderlineColor", new Integer ( (new Color (0, 0, 255)).getRGB ()));
   l_textCursorInXPropertySet.setPropertyValue ("CharOverline", new Short (FontUnderline.BOLDDOTTED));
   l_textCursorInXPropertySet.setPropertyValue ("CharOverlineHasColor", new Boolean (true));
   l_textCursorInXPropertySet.setPropertyValue ("CharOverlineColor", new Integer ( (new Color (255, 0, 0)).getRGB ()));
   l_textCursorInXPropertySet.setPropertyValue ("CharStrikeout", new Short (FontStrikeout.DOUBLE));
-Rebutter

All right.

Main body END

<The previous article in this series | The table of contents of this series | The next article in this series>