
現在の日付を挿入するためのCTRL+ショートカットと、現在の時刻を挿入するための+ +ショートカットがあることは知っています。;CTRLSHIFT;
しかし、これには 2 つの問題があります。
1) 両方に1つのショートカットが欲しい
2) カスタムの日付時刻形式を使用できるようにしたい ( YYYY-MM-DD HH:MM:SS
)
私の言語のデフォルト形式はMM/DD/YY HH:MM:SS pm/am
- 私はないこれを変更したいです。できれば、xdotool
外部マクロ ソフトウェアやシステム全体のグローバル ショートカットを介したソリューションを使用せずに、そのショートカット専用のカスタム フォーマットを使用したいと思います。
内部の関数はTools -> Customize -> Keyboard
何の助けにもならないようです。
(xdotoolを使いたくない理由; LibreOffice 内で直接ソリューションを提供するのが最適です。
私は次のOpenOfficeマクロコードを見つけましたここしかし、Writer ドキュメントでのみ機能すると書かれています。このマクロを変更して、Calc で現在選択されているセルにフォーマットされた DATE-TIME を挿入するにはどうすればよいでしょうか?
'Author: Andrew Pitonyak
'email: [email protected]
'uses: FindCreateNumberFormatStyle
Sub InsertDateField
Dim oDoc
Dim oText
Dim oVCurs
Dim oTCurs
Dim oDateTime
Dim s$
oDoc = ThisComponent
If oDoc.SupportsService("com.sun.star.text.TextDocument") Then
oText = oDoc.Text
oVCurs = oDoc.CurrentController.getViewCursor()
oTCurs = oText.createTextCursorByRange(oVCurs.getStart())
oText.insertString(oTCurs, "Today is ", FALSE)
' Create the DateTime type.
s = "com.sun.star.text.TextField.DateTime"
ODateTime = oDoc.createInstance(s)
oDateTime.IsFixed = TRUE
oDateTime.NumberFormat = FindCreateNumberFormatStyle(_
"DD. MMMM YYYY", oDoc)
oText.insertTextContent(oTCurs,oDateTime,FALSE)
oText.insertString(oTCurs," ",FALSE)
Else
MsgBox "Sorry, this macro requires a TextDocument"
End If
End Sub
答え1
ショートカットの前にセルの書式を変更するのが最も簡単な解決策でしょうか?
ショートカット後のセルのフォーマットが機能しません。
マクロ的な方法...
Sub Main
Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object
Dim NumberFormats As Object
Dim NumberFormatString As String
Dim NumberFormatId As Long
Dim LocalSettings As New com.sun.star.lang.Locale
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Cell = Doc.getCurrentSelection
Column = Cell.CellAddress.Column
Row = Cell.CellAddress.Row
Cell.Value = Now()
LocalSettings.Language = "en"
LocalSettings.Country = "us"
NumberFormats = Doc.NumberFormats
NumberFormatString = "YYYY-MM-DD HH:MM:SS"
NumberFormatId = NumberFormats.queryKey(NumberFormatString, LocalSettings, True)
If NumberFormatId = -1 Then
NumberFormatId = NumberFormats.addNew(NumberFormatString, LocalSettings)
End If
MsgBox NumberFormatId
Cell.NumberFormat = NumberFormatId
End Sub
答え2
Excel の場合 (Windows 版 MS Excel 2010 でテスト済み): マクロや追加のソフトウェアを使用せずに 1 つのセルに挿入する場合、唯一の解決策は 3 つのショートカットを次々に使用することです。
- CTRL+;
- space
- CTRL+ SHIFT+;
少なくともこれでDD-MM-YYYY HH:MM
そこから、ユーザー定義の形式を好みに合わせて変更するだけです。YYYY-MM-DD HH:MM:SS