除了使用条件格式之外,LibreOffice Calc(或 OpenOffice Calc)中是否有其他方法可以突出显示每隔一行,以使电子表格更易于阅读?
LibreOffice 有一个严重的错误,当使用典型的条件格式技术ISEVEN(ROW())
尝试执行此任务,然后复制或移动行时,会导致多个错误。我找到了有关此问题的 LibreOffice 错误报告,但错误仍然存在。
答案1
早在 2004 年,我就用 StarBasic 编写了一个宏,它可以将交替颜色应用于已使用的单元格(至今仍在使用 LO 5.2.2.2)。如果您想更改颜色定义,我希望源代码有详尽的文档记录,以便您找到它们 ;-)
将代码复制到 Basic 代码的标准库中的模块中,以便所有 CALC 文档都可以使用。HTH
'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
答案2
从菜单:格式→自动套用格式样式..。您可以添加自己的。
另一种选择是使用宏(如 ngulam 的回答中所述)。
颜色2行是一个在工具栏中添加按钮的扩展,用于快速生成三色表(头部颜色加上其他行上的 2 种交替颜色)。来源询问网站,经测试仍可在版本 5.1.4.2 中运行
同一网站上还有另一篇文章,标题为如何制作一个按钮来应用表格自动套用格式?但我不知道如何设置它才能工作。