Date: prev next · Thread: first prev next last
2020 Archives by date, by thread · List index


Den lör 2 maj 2020 kl 10:07 skrev Johnny Rosenberg <gurus.knugum@gmail.com>:

I accidentally replied to you directly, I'm sorry for that. Here's another
one, this time sent to the right destination, see below.

Den lör 2 maj 2020 kl 07:49 skrev Ken Heard <kenslists@teksavvy.com>:

On 01/05/20 11:31 PM, Johnny Rosenberg wrote:
Den fre 1 maj 2020 kl 18:11 skrev Ken Heard <kenslists@teksavvy.com>:

On 01/05/20 06:21 PM, Johnny Rosenberg wrote:
Den fre 1 maj 2020 kl 12:27 skrev Ken Heard <kenslists@teksavvy.com>:

How does one make the default time format for the 'time' field HH:MM
instead of HH:MM:SS?


In Writer?

Yes

Right click the field and click ”Edit Fields…”.
Select the format you want, I believe the first one is the one you are
looking for. If it's not in the list, click ”Additional Formats…” and
in
the new dialogue that opens you can set your field to whatever format
you
like.

I followed your instructions, but as far as I can see they will only
change the format of the time field for that use of the field, What I
want to do is to change the *default* of the time field to HH:MM from
HH:MM:SS.

Regards, Ken Heard


Have a look here then:

https://ask.libreoffice.org/en/question/158048/how-do-i-change-the-default-datetime-format/

I'll quote the important part, in case that page is removed at some
point:
”*The default formats (date/time, currency, fixed/scientific/percent; in
long/medium/short variants where applicable) depend on cell/field/...
language, and are hardcoded in the corresponding locale data (see
i18npool/source/localedata/data
<
https://opengrok.libreoffice.org/xref/core/i18npool/source/localedata/data/

for the locale data definitions). They are not configurable (unless you
rebuild LibreOffice).*

*You may want to create a macro to automate insertion of fields with
desired format; please see this question
<
https://ask.libreoffice.org/en/question/136467/how-to-create-a-macro-to-insert-the-current-date-in-the-current-language/

for details.*”

Thank you Johnny for this information.  So I now have really two
options,  One is to learn all about LibreOffice macros and create a
macro to give the result I want, OR simply type in the time wherever I
want it.  While I do want sometime to learn all about macros, for the
time being I will choose the second option!

Regards, Ken Heard



   1. If you click the link in the macro paragraph above, you will at
   least see a few macro examples that are claimed to work (I didn't test them
   though, so I don't know) and they don't seem to be very hard to edit to
   suit the needs of this specific situation.
   2. If you instead are going to insert many time fields in the same
   document, or even in different documents that are all open at the same
   time, you can just insert the first one, change its format to HH:MM, then
   highlight the field, press Ctrl+c (copy) and then insert it with Ctrl+v
   (paste) wherever you want. That way you don't need to change it's format
   every time.
   3. What kind of time field do you want to insert? ”Time (fixed)” or
   ”Time”? If ”Time” (time is updated on field update), there's an easy way:
   Use Autocorrection! First create the field and edit it to your liking. Then
   highlight and copy (Ctrl+c) it, then click ”Tools” → ”AutoCorrect”
   →”AutoCorrect Options…” → enter your trigger text (let's try ”.tm” in the
   ”Replace” field, then hit ”OK”. Now, every time you type ”.tm” in your
   document (any document, actually, as long as they are opened with
   LibreOffice Writer), the ”.tm” text will be replaced by a time field with
   the current time. This can't be done if you want the field to be setup as
   ”Time (fixed)”, since there would always be the same time in that field,
   that is the time when you first created the AutoCorrect record.
   4. Do you really need to insert time as a field? If not, you could use
   an external program for it, such as AutoKey (on Linux) or AutoHotKey (on
   Windows). I use AutoKey for that and all I have to do to insert current
   time is to type ”ti”. When I do that, the text ”ti” is replaced with the
   current time as soon as I hit a space, ⇥ or ↵.

5. The macro approach:
I had a look at Andrew Pitonyak's macro document and I was fiddling with it
a bit. This seems to work for inserting a fixed time field:





































































*REM  *****  BASIC  *****Option Explicit'
———————————————————————————————————————————————————————————————————————————————————————————————'Original
author: Andrew Pitonyak'Email: andrew@pitonyak.org
<andrew@pitonyak.org>'Uses: FindCreateNumberFormatStyle'Edits: Johnny
RosenbergSub InsertTimeField  Dim oDoc As Object   Dim oText As Object  Dim
oVCurs As Object  Dim oTCurs As Object  Dim oDateTime As Object  oDoc =
ThisComponent  If oDoc.SupportsService("com.sun.star.text.TextDocument")
Then    oText = oDoc.Text    oVCurs =
oDoc.CurrentController.getViewCursor()    oTCurs =
oText.createTextCursorByRange(oVCurs.getStart())    ' Create the DateTime
type.    ODateTime =
oDoc.createInstance("com.sun.star.text.TextField.DateTime")
oDateTime.IsFixed = TRUE    oDateTime.NumberFormat =
FindCreateNumberFormatStyle("HH:MM", oDoc)
oText.insertTextContent(oTCurs,oDateTime,FALSE)
oText.insertString(oTCurs," ",FALSE)  Else    MsgBox "Sorry, this macro
requires a TextDocument"  End IfEnd Sub'
———————————————————————————————————————————————————————————————————————————————————————————————'Original
author: Andrew Pitonyak'Email: andrew@pitonyak.org
<andrew@pitonyak.org>'Edits: Johnny RosenbergFunction
FindCreateNumberFormatStyle(sFormat As String, Optional doc As object,
Optional locale)   Dim oDoc As Object  Dim aLocale As New
com.sun.star.lang.Locale  Dim oFormats As Object  Dim formatNum As Integer
oDoc = IIf(IsMissing(doc), ThisComponent, doc)  oFormats =
oDoc.getNumberFormats()  'If you choose to query on types, you need to use
the type    'com.sun.star.util.NumberFormat.DATE    'I could set the locale
from values stored at
'http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
<http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt>
'http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
<http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html>    'I use a NULL
locale and let it use what ever it likes.    'First, see if the number
format exists    If (IsMissing(locale)) Then      With aLocale
.Language="en"        .Country="US"      End With    Else      aLocale =
locale    End If  formatNum = oFormats.queryKey (sFormat, aLocale, TRUE)
'If the number format does not exist then add it  If (formatNum = -1) Then
  formatNum = oFormats.addNew(sFormat, aLocale)    If (formatNum = -1) Then
formatNum = 0  End If  FindCreateNumberFormatStyle = formatNumEnd Function*

Now you only have to associate this macro with a keyboard shortcut, menu
option or toolbar button. I prefer keyboard shortcuts and I associated mine
with Ctrl+t, which was free. Here's the whole process:

   1. Highlight the code above, all of it.
   2. Ctrl+c
   3. In LibreOffice Writer, click Tools → Macros → Edit Macros
   4. A new window pops up. Click Tools in the new window, then Organize
   Macros → Basic…
   5. Click  Organizer…
   6. In the Modules tab, click the ▸ in front of ”My Macros”, making it a
   ▾.
   7. Click Standard to highlight it.
   8. Click New…
   9. You will now create a new module, so give it a name. I'll name it
   ”Insert”.
   10. Click Edit.
   11. The big field to the right now has some text in it, such as ”Sub
   Main” and ”End Sub”. Click somewhere in there, and hit Ctrl+a Ctrl+v to
   insert the code you copied in step 2.
   12. Now, let's associate InsertTimeField with a the keyboard shortcut
   Ctrl+t. Here's how:
   13. In the same window, click Tools → Customize…
   14. Click the Keyboard tab if it's not already selected.
   15. In the Category field, scroll down and click the ▸ in front of
   ”LibreOffice Macros”.
   16. Do the same for ”My Macros” and ”Standard”.
   17. Click ”Insert”.
   18. In the Function field, click InsertTimeField.
   19. In the Shortcut Keys field, look for Ctrl+t and click it.
   20. Click Modify. In Keys field, Ctrl+T should now be displayed.
   21. Click OK.
   22. In your main window, place the cursor somewhere and hit Ctrl+t. A
   new field with the current time in HH:MM format should now appear at the
   cursor.
   23. Done.
   24. This should now work in any document as long as LibreOffice Writer
   is used.
   25. If there is a problem, make sure you inserted ALL of the code above.
   I tested the code myself and it works perfectly on my system, so there
   should not be any problems, if these instructions are followed in detail,
   but we are only human…


Kind regards

Johnny Rosenberg



Kind regards

Johnny Rosenberg


--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems?
https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy



-- 
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.