在没有条件格式的情况下突出显示 LibreOffice(或 OpenOffice)中的每一行?

Roc*_*ket 5 spreadsheet openoffice-calc openoffice libreoffice libreoffice-calc

除了使用条件格式之外,LibreOffice Calc(或 OpenOffice Calc)中是否有任何方法可以突出显示每隔一行以使电​​子表格更易于阅读?

LibreOffice 有一个严重的错误,当使用典型的条件格式技术ISEVEN(ROW())尝试执行此任务然后复制或移动行时,会导致多个错误。我发现了一个关于这个问题的 LibreOffice 错误报告,但这些错误仍然存​​在。

use*_*.dz 6

  • 从菜单:格式自动套用格式样式..。你可以添加你自己的。

    LibreOffice:自动套用格式

  • 另一种选择是使用宏(如 ngulam 的回答)。

    Color2Rows是一个扩展,它在工具栏上添加了一个按钮,用于快速三种颜色表(头部颜色加上其他行上的 2 种交替颜色)。来源ask.libreoffice.org,经测试仍可在版本:5.1.4.2

    同一站点上还有另一篇文章,标题为如何制作按钮以应用表格自动套用格式?但我不知道如何设置它才能工作。


小智 2

我早在 2004 年就在 StarBasic 中编写了一个宏,它将交替颜色应用于使用的单元格(至今仍在使用我使用的 LO 5.2.2.2)。我希望源代码有详细记录,以便您可以找到颜色定义(如果您想更改它们);-)

将代码复制到 Basic 代码的 STANDARD 库中的模块中,以供所有 CALC 文档使用。华泰

'Copyright (c) 2004, 2016 Winfried Rohr, re-Solutions Software Test Engineering

'This program is free software; you can redistribute it and/or modify it under 
'the terms of the GNU General Public License as published by the Free Software
'Foundation; either version 2 of the License, or (at your option) any later 
'version.

'This program is distributed in the hope that it will be useful, but WITHOUT ANY 
'WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
'A PARTICULAR PURPOSE. See the GNU General Public License for more details.

'You should have received a copy of the GNU General Public License along with 
'this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
'Place, Suite 330, Boston, MA 02111-1307 USA
' ========================================================================
Dim oDoc
Dim lRows as Long
Dim lCols as Long
Dim lStartRow as Long
Dim i as Long
Dim lEvenColor, lOddColor as Long
Dim sModulName, sModulSubName, sModulVersion

' -------------------------------------------------------------------
Sub colorCalcTableRowsEnglish ' manual extension 2006-03-24
sModulName = "wr CALC Modul"
sModulSubName = "colorCalcTableRows"
sModulVersion = "20040810"

oDoc = ThisComponent

If Not oDoc.supportsService(_
    "com.sun.star.sheet.SpreadsheetDocument" ) Then
        MsgBox _
        "Macro not called from CALC Document." & CHR(10) _
        & CHR(10) & "Explanation:" _
        & CHR(10) & "This Macro applies alternating, pre-definied" _
& CHR(10) & "background colors to the rows of the used cell"_
& CHR(10) & "range in CALC Documents and will only work there."_
& CHR(10) & CHR(10) _
& "Macro " & sModulSubName & " will terminate now." _
, 48 , sModulName & " " & sModulVersion
Exit Sub
End If

' RGB: Red/Green/Blue portion of color
' values could range from 0 to 255
' see Tools > OpenOffice.org > Colors for values
' 0,0,0: Black
' 255,255,255: White
' 
' Even/Odd correspond to ROW number
lEvenColor = RGB(255,200,200) ' kinda red
lOddColor =RGB(188,188,188) ' grey


if oDoc.Sheets.Count > 1 then
    ' more than 1 sheet, ask if macro should work on all sheets
    sQuestion = _
        "Applying alternating background colors to used cell range."_
        & CHR(10) _
        & CHR(10) & "Should all sheets be affected?" _
        & CHR(10) & "YES: apply on all sheets" _
        & CHR(10) & "No: apply to actual sheet only"

    iButton = _
        MsgBox(sQuestion ,35, sModulSubName & " - " & sModulVersion)

    Select Case iButton
        Case 2 ' cancel
            exit sub
        Case 6 ' yes = all sheets
            PROC_AllSheets
        Case 7 ' no = actual sheet only
            actSheet = oDoc.currentController.ActiveSheet
            PROC_colorSheetRow(actSheet)
    End Select
else
    ' only one sheet present
    actSheet = oDoc.currentController.ActiveSheet
    PROC_colorSheetRow(actSheet)
end if

End Sub

' -------------------------------------------------------------------
Sub PROC_allSheets

enumS = oDoc.getSheets.createEnumeration

While enumS.hasMoreElements
    actSheet = enumS.nextElement()
    PROC_colorSheetRow(actSheet)
Wend

End Sub

' -------------------------------------------------------------------
Sub PROC_colorSheetRow(actSheet)

lStartRow = 0
' watch out on first 4 rows if they might be formatted as heading
for i = 0 to 3
    ' don't touch rows with heading style
    oCell = actSheet.getCellByPosition(0,i)
    if INSTR(oCell.CellStyle , "Heading") > 0 then
        ' style heading found: increase start row
        lStartRow = i + 1
    end if
next i

' obtain last cell in sheet
vLastPos = FUNC_LastUsedCell(actSheet)
lRows = vLastPos(0)
lCols = vLastPos(1)

' if no more cell used - then nothing
if lRows = 0 AND lCols = 0 then
    exit sub
end if

' not more than headings
if lStartRow > lRows then
    exit sub
end if

' set range to one color (performance issue)
actRange = actSheet.getCellRangeByPosition(0,lStartRow,lCols,lRows)
actRange.setPropertyValue("CellBackColor", lEvenColor)

' now set color to Odd (number) rows (are even indexes)
for i = lStartRow to lRows
    ' determine range
    actRange = actSheet.getCellRangeByPosition(0,i,lCols,i)
    ' only every second row
    if((i MOD 2) = 0) then
        ' even index is odd row number
        actRange.setPropertyValue("CellBackColor", lOddColor)
    end if
next i
End Sub

' -------------------------------------------------------------------
' function uses variant array to return more than one value
Function FUNC_LastUsedCell(oSheet as Object) as Variant

oCursor = oSheet.createCursor()

oCursor.gotoEndOfUsedArea(TRUE) 
oEndAdr = oCursor.getRangeAddress

Dim vLastUsedCell(1) as Variant
vLastUsedCell(0) = oEndAdr.EndRow
vLastUsedCell(1) = oEndAdr.EndColumn 
FUNC_LastUsedCell = vLastUsedCell()

End Function
Run Code Online (Sandbox Code Playgroud)