[Calc, Basic] Format imported database data

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Villeroy
Volunteer
Posts: 31323
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

[Calc, Basic] Format imported database data

Post by Villeroy »

The demo document contains some unformatted demo data, a set of cell styles, two named ranges and a Basic macro triggered by a push button. If you click any cell in the data list and push the button, the macro will detect the current region of used cells around the current selection as the list range to be formatted and will apply cell styles as follows:
The first row gets the cell style whose name is entered into named cell "HeaderStyle" (A1).
The data rows get the cell styles defined in named range "ColumnStyles" (A2:D2).
You can copy the Basic module into your own template. It can also be copied to the public libraries under "My Macros" since the macro applies to any spreadsheet document having the required names and styles.

P.S. The push button in the sample sheet has property "Take focus on click" = OFF because the macro depends on the current cell selection. This fails when the push button takes the focus away from the sheet. This is not a problem when you call the macro from Tools>Macros or from a user defined UI element.
Attachments
Format_List.ods
Demo document with dummy data, names, styles, push button
(43.34 KiB) Downloaded 330 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply