Re: [libreoffice-users] [LibreOffice Writer] Table with alternat[]e row color

2015-04-19 Thread Brian Barker

At 14:10 15/04/2015 +0200, Alain Ronly wrote:
I'm looking for a simple and automatic way how to tell to my tables 
in a writer document, to be formatted with alternat[]e rows color 
for example even rows will be blue in the background and odd rows 
will have a light blue as background color. I did not find any easy 
way to do it. Is there someone who has already solved this topic ?


Not me.

o Once you have set the background colour for one row, you can use 
the Format Paintbrush to paint the same colour on other rows. If you 
double-click the button, you can drag the "paint bucket" across 
alternate rows to achieve one colour and then repeat the process for 
the other colour.


o For large numbers of rows, you can copy an entire existing table 
and paste it immediately following - and you can repeat that process. 
You'll end up with multiple tables, but that may suffice, providing 
you delete the empty paragraph between them. If you need to, you can 
put the cursor into the second table and go to Table | Merge Tables 
(or right-click | Merge Tables) to merge the two tables into one.


o It is somewhat easier to set up such background colouring in a 
spreadsheet than in a Writer table. If you colour two rows you can 
easily copy them to two more. Then you can copy four rows to create 
eight in total. With this binary multiplication, you can very quickly 
achieve the desired size. If you then copy an appropriately-sized 
section of the spreadsheet and paste it into your text document using 
Paste Special... and "HTML (HyperText Markup Language)" you will get 
a table with the same background formatting. The table properties can 
be adjusted as necessary.


o The automatic way to colour spreadsheet rows alternately is to use 
Conditional Formatting and create a formula using the ROW() function 
to determine the oddness or evenness of the row number and control 
the background colouring using cell styles. But unfortunately - and 
as you might expect - the effect of such formatting is lost if you 
paste a copy into a text document as a table. So that's a dead duck.


o It's probably much easier to set up formatting such as this before 
you insert your data. If necessary, you should be able to copy any 
existing material and paste it into a new, formatted table.


I trust this helps.

Brian Barker


--
To unsubscribe e-mail to: users+unsubscr...@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted



Re: [libreoffice-users] [LibreOffice Writer] Table with alternat[]e row color

2015-04-20 Thread Andrew Douglas Pitonyak



On 04/19/2015 07:22 PM, Brian Barker wrote:

At 14:10 15/04/2015 +0200, Alain Ronly wrote:
I'm looking for a simple and automatic way how to tell to my tables 
in a writer document, to be formatted with alternat[]e rows color for 
example even rows will be blue in the background and odd rows will 
have a light blue as background color. I did not find any easy way to 
do it. Is there someone who has already solved this topic ?


Not me.

o Once you have set the background colour for one row, you can use the 
Format Paintbrush to paint the same colour on other rows. If you 
double-click the button, you can drag the "paint bucket" across 
alternate rows to achieve one colour and then repeat the process for 
the other colour.


o For large numbers of rows, you can copy an entire existing table and 
paste it immediately following - and you can repeat that process. 
You'll end up with multiple tables, but that may suffice, providing 
you delete the empty paragraph between them. If you need to, you can 
put the cursor into the second table and go to Table | Merge Tables 
(or right-click | Merge Tables) to merge the two tables into one.


o It is somewhat easier to set up such background colouring in a 
spreadsheet than in a Writer table. If you colour two rows you can 
easily copy them to two more. Then you can copy four rows to create 
eight in total. With this binary multiplication, you can very quickly 
achieve the desired size. If you then copy an appropriately-sized 
section of the spreadsheet and paste it into your text document using 
Paste Special... and "HTML (HyperText Markup Language)" you will get a 
table with the same background formatting. The table properties can be 
adjusted as necessary.


o The automatic way to colour spreadsheet rows alternately is to use 
Conditional Formatting and create a formula using the ROW() function 
to determine the oddness or evenness of the row number and control the 
background colouring using cell styles. But unfortunately - and as you 
might expect - the effect of such formatting is lost if you paste a 
copy into a text document as a table. So that's a dead duck.


o It's probably much easier to set up formatting such as this before 
you insert your data. If necessary, you should be able to copy any 
existing material and paste it into a new, formatted table.


I trust this helps.

Brian Barker


I wrote a macro some years back and I still use it today. You probably 
have no interest in the part that sets the borders...


Sub FormatTable(Optional oUseTable)
  Dim oTable
  Dim oCell
  Dim nRow As Long
  Dim nCol As Long

  If IsMissing(oUseTable) Then
oTable = ThisComponent.CurrentController.getViewCursor().TextTable
  Else
oTable = oUseTable
  End If
  If IsNull(oTable) OR IsEmpty(oTable) Then
Print "FormatTable: No table specified"
Exit Sub
  End If

  Dim v
  Dim x
  v = oTable.TableBorder
  x = v.TopLine
  x.OuterLineWidth = 2
  v.TopLine = x

  x = v.LeftLine
  x.OuterLineWidth = 2
  v.LeftLine = x

  x = v.RightLine
  x.OuterLineWidth = 2
  v.RightLine = x

  x = v.TopLine
  x.OuterLineWidth = 2
  v.TopLine = x

  x = v.VerticalLine
  x.OuterLineWidth = 2
  v.VerticalLine = x

  x = v.HorizontalLine
  x.OuterLineWidth = 0
  v.HorizontalLine = x

  x = v.BottomLine
  x.OuterLineWidth = 2
  v.BottomLine = x

  'v.Distance = 51

  oTable.TableBorder = v

  For nRow = 0 To oTable.getRows().getCount() - 1
For nCol = 0 To oTable.getColumns().getCount() - 1
  oCell = oTable.getCellByPosition(nCol, nRow)
  If nRow = 0 Then
oCell.BackColor = 128
SetParStyle(oCell.getText(), "OOoTableHeader")
  Else
SetParStyle(oCell.getText(), "OOoTableText")
If nRow MOD 2 = 1 Then
  oCell.BackColor = -1
Else
  REM color is (230, 230, 230)
  oCell.BackColor = 15132390
End If
  End If
Next
  Next
End Sub

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php


--
To unsubscribe e-mail to: users+unsubscr...@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted



Re: [libreoffice-users] [LibreOffice Writer] Table with alternat[]e row color

2015-04-20 Thread Piet van Oostrum
I din't remember if this has already been mentioned in this thread, but you can 
do this simply with an Autoformat.

Just take 3 rows of your table (or create a special table for this). Then color 
the rows alternatively. Or you can color the header row with a different color 
if so desired. Then select these 3 rows and click "Table -> AutoFormat". Click 
"Add"" and give your autoformat a name. 
Then select the table to be formatted and Autoformat it with the newly created 
AutoFormat. You can indicate if you want a header row.

You can also create the AutoFormat in a Calc spreadsheet, but there you need at 
least a 3x3 rectangle. In a Writer table you only need at least 3 rows.

It is also possible to do striped columns, then you would need at least 3 
columns.

Some Caveats:
1. In Calc If you give the new AutoFormat a name that lexicographically sorts 
before "Default", e.g. when it starts with A, B or C, then it just disappears. 
In Writer that is not the case.

2. If you later insert or delete an odd number of rows from the table, they 
will no longer be alternatively colored. You will have to re-apply the format.

3. An autoformat has a column header (the first row) that you can disable when 
applying the AutoFormat. It also has a totals row at the bottom, and a rows 
header column and a totals column at the right that you cannot disable (This is 
a design error). If you don't color your columns differently the row header and 
Totals columns are no problem. But the Totals row always gets the color of the 
last row in the AutoFormat, and so if your AutoFormat has an even number of 
rows (excluding a possible header row), and your table has an odd number of 
rows, or vice versa, then the last row will get the wrong color. You can 
correct this by creating the table with one row more, and then deleting the 
last row. If you would have striped columns, I guess the same will happen in 
the other direction, but I haven't tried.

-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]

-- 
To unsubscribe e-mail to: users+unsubscr...@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted



Re: [libreoffice-users] [LibreOffice Writer] Table with alternat[]e row color

2015-04-20 Thread Brian Barker

At 14:59 20/04/2015 +0200, Piet van Oostrum wrote:
I din't remember if this has already been mentioned in this thread, 
but you can do this simply with an Autoformat.


Just take 3 rows of your table (or create a special table for this). 
Then color the rows alternatively. Or you can color the header row 
with a different color if so desired. Then select these 3 rows and 
click "Table -> AutoFormat". Click "Add"" and give your autoformat a name.
Then select the table to be formatted and Autoformat it with the 
newly created AutoFormat. You can indicate if you want a header row.


Aha: the perfect answer!

Brian Barker 



--
To unsubscribe e-mail to: users+unsubscr...@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted



Re: [libreoffice-users] [LibreOffice Writer] Table with alternat[]e row color

2015-04-20 Thread James E Lang
Thank you Andrew. That looks like it's a full answer to the question. I have 
learned something from this. I might not use it often but I now have it in my 
bag of tools and who knows 

-- 
Jim

-Original Message-
From: Andrew Pitonyak 
To: "James E. Lang" 
Sent: Mon, 20 Apr 2015 11:40
Subject: Re: [libreoffice-users] [LibreOffice Writer] Table with alternat[]e 
row color

On 20.04.2015 10:03, James E. Lang wrote:
> Hi Andrew,
>
> This message is off list for technical reasons.

No problem, especially for this type of question :-)

>
> As I stated in a message that I posted to the list yesterday, I don't
> do a lot of work with
> LibreOffice Writer. That said, I tried your macro and it choked
> (Sub-procedure or function
> procedure not defined) on this line:
>
> SetParStyle(oCell.getText(), "OOoTableHeader")


Yeah, sorry about that. What this is doing is setting the first row to 
use the paragraph style named "OOoTableHeader". I don't know if you have 
seen any of my documents, but it is how I format my text tables in 
general. You can comment out that line, or, change "OOoTableHeader" to 
be the paragraph style that you want to use.

There is another line below it

SetParStyle(oCell.getText(), "OOoTableText")

This sets all of the other lines to use the paragraph style 
"OOoTableText", which is probably a paragraph style that you do not have 
if you do not write documentation for LibreOffice.

Comment out these two lines by placing a single quote before them or 
the text REM as follows:

'SetParStyle(oCell.getText(), "OOoTableText")
REM SetParStyle(oCell.getText(), "OOoTableText")



>
> Is this because I don't have the jre installed or is there something
> else that is required
> (defining the UNO interface maybe?) beyond the Sub you posted?
>
> My Macros=>Standard=>Module1 contains only the empty Sub Main, three
> pure Basic (UNO
> free) functions that I wrote for a spreadsheet, and your Sub
> FormatTable which I copied from
> the eMail and pasted into the module.
>
> --
> Jim
>
> On 20 Apr 2015 at 8:03, Andrew Douglas Pitonyak wrote:
>
>> I wrote a macro some years back and I still use it today. You 
>> probably
>> have no interest in the part that sets the borders...
>>
>> Sub FormatTable(Optional oUseTable)
>>Dim oTable
>>Dim oCell
>>Dim nRow As Long
>>Dim nCol As Long
>>
>>If IsMissing(oUseTable) Then
>>  oTable = 
>> ThisComponent.CurrentController.getViewCursor().TextTable
>>Else
>>  oTable = oUseTable
>>End If
>>If IsNull(oTable) OR IsEmpty(oTable) Then
>>  Print "FormatTable: No table specified"
>>  Exit Sub
>>End If
>>
>>Dim v
>>Dim x
>>v = oTable.TableBorder
>>x = v.TopLine
>>x.OuterLineWidth = 2
>>v.TopLine = x
>>
>>x = v.LeftLine
>>x.OuterLineWidth = 2
>>v.LeftLine = x
>>
>>x = v.RightLine
>>x.OuterLineWidth = 2
>>v.RightLine = x
>>
>>x = v.TopLine
>>x.OuterLineWidth = 2
>>v.TopLine = x
>>
>>x = v.VerticalLine
>>x.OuterLineWidth = 2
>>v.VerticalLine = x
>>
>>x = v.HorizontalLine
>>x.OuterLineWidth = 0
>>v.HorizontalLine = x
>>
>>x = v.BottomLine
>>x.OuterLineWidth = 2
>>v.BottomLine = x
>>
>>'v.Distance = 51
>>
>>oTable.TableBorder = v
>>
>>For nRow = 0 To oTable.getRows().getCount() - 1
>>  For nCol = 0 To oTable.getColumns().getCount() - 1
>>oCell = oTable.getCellByPosition(nCol, nRow)
>>If nRow = 0 Then
>>  oCell.BackColor = 128
>>  SetParStyle(oCell.getText(), "OOoTableHeader")
>>Else
>>  SetParStyle(oCell.getText(), "OOoTableText")
>>  If nRow MOD 2 = 1 Then
>>oCell.BackColor = -1
>>  Else
>>REM color is (230, 230, 230)
>>oCell.BackColor = 15132390
>>  End If
>>End If
>>  Next
>>Next
>> End Sub
>>
>> --
>> Andrew Pitonyak

-- 
To unsubscribe e-mail to: users+unsubscr...@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted