Bug 116129 - Calc Cell Range method ClearContents does not work with com.sun.star.sheet.CellFlags.STYLES
Summary: Calc Cell Range method ClearContents does not work with com.sun.star.sheet.Ce...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected) release
Hardware: All All
: medium normal
Assignee: Not Assigned
Depends on:
Blocks: Macro-UNOAPI
  Show dependency treegraph
Reported: 2018-03-01 18:20 UTC by Volker Lenhardt
Modified: 2021-09-25 13:45 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:
Regression By:

Macros to display bugs using Calc cell range method clearContents with some CellFlags (13.26 KB, application/vnd.oasis.opendocument.spreadsheet)
2018-03-02 13:04 UTC, Volker Lenhardt

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Lenhardt 2018-03-01 18:20:22 UTC
If I try to remove cell style formatting on a Calc sheet cell range by a macro, nothing happens:


But if I combine STYLES with HARDATTR, not only all hard formatting is set to default, but formatting with cell styles is removed as well. This way you can remove cell style formatting, but with the drawback of getting default formats in the rest of the cells.

This behavior is proved for Windows 7, LO 5.3.7., Windows 10, LO (32 bit) and for Linux openSUSE LEAP 42.2 with LO 5.3.0 and LO (both generic versions).

Steps to Reproduce:
1. Format a sheet cell with some cell style.
2. Take a cell range oRange containing that cell.
3. oRange.clearContents(com.sun.star.sheet.CellFlags.STYLES)
4. Nothing happens
5. oRange.clearContents(com.sun.star.sheet.CellFlags.HARDATTR Or com.sun.star.sheet.CellFlags.STYLES)

Actual Results:  
With (com.sun.star.sheet.CellFlags.STYLES) alone nothing happens.
With (com.sun.star.sheet.CellFlags.HARDATTR Or com.sun.star.sheet.CellFlags.STYLES) all cells in the range are reset to default formats incl. the cell with cell style.

Expected Results:
With (com.sun.star.sheet.CellFlags.STYLES) alone all cells formatted by cell styles should be reset to default formats.

Reproducible: Always

User Profile Reset: No

Additional Info:

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Comment 1 Hans-Werner 2018-03-01 19:12:02 UTC
Confirmed for:
+ LibO (x64) @ Windows 7 Home Premium 64-bit
+ LibO (x64) @ Windows 7 Home Premium 64-bit
Greetings Hans-Werner
Comment 2 Gerhard Weydt 2018-03-01 20:21:35 UTC
I can confirm it for LibO 32-Bit, Windows 10
Comment 3 Xisco Faulí 2018-03-02 09:00:31 UTC
Thank you for reporting the bug. Please attach a sample document, as this makes it easier for us to verify the bug. 
(Please note that the attachment will be public, remove any sensitive information before attaching it. 
See https://wiki.documentfoundation.org/QA/FAQ#How_can_I_eliminate_confidential_data_from_a_sample_document.3F for help on how to do so.)
Comment 4 Volker Lenhardt 2018-03-02 13:04:43 UTC
Created attachment 140291 [details]
Macros to display bugs using Calc cell range method clearContents with some CellFlags

This attachment shows a set of formatted cells, numbers, date/time, strings, B3 being formatted with a cell style, as well as two cells (B4 and C4) with text portion formatting.

You can try the effect on B3 (in fact no effect at all) by calling the macro
Sub ClearContentsByCellFlagsSTYLES

If you call the macro
Sub ClearContentsByCellFlagsHARDATTROrSTYLES
then not only all cell formatting is set to default, but B3 loses the cell style, too.

The file comes with an additional macro to serve as an example for bug 116127 as well:
Sub ClearContentsByCellFlagsEDITATTR
Comment 5 Oliver Brinzing 2018-03-02 16:34:56 UTC Comment hidden (obsolete)
Comment 6 himajin100000 2019-09-20 22:43:53 UTC

What would happen if nDelFlag has STYLES only when (ATTRIB == (HARDATTR | STYLES))?


I first thought it could be ok if I rewrite

(nDelFlag & InsertDeleteFlags::ATTRIB) != InsertDeleteFlags::NONE

instead of 

(nDelFlag & InsertDeleteFlags::ATTRIB) == InsertDeleteFlags::ATTRIB

, but in that case it seems, at least to me , that we would not at all need else-if section.
Comment 7 QA Administrators 2021-09-21 04:52:35 UTC Comment hidden (obsolete)
Comment 8 Volker Lenhardt 2021-09-25 12:17:12 UTC
As with LO and both on macOS Big Sur (11.6) and with LO on openSUSE Leap Tumbleweed there is no different behaviour. The bug persists as specified before.
With regards, Volker
Comment 9 Volker Lenhardt 2021-09-25 13:45:34 UTC
In addition: With LO 3.3.0 on Linux openSUSE Tumbleweed (Leap 15.2) the macro removes all hard attributes, but leaves the cell styles untouched. Weird. It should have done the other way round. But this is history.
Greetings, Volker