我知道有CTRL+;快捷方式可以插入当前日期,而CTRL+ SHIFT+;可以插入当前时间。
但是,我有两个问题:
1)我都想拥有一个shurtcut
2)我希望能够使用自定义的日期时间格式(YYYY-MM-DD HH:MM:SS
)
我的语言默认格式是MM/DD/YY HH:MM:SS pm/am
-我不希望改变这种情况。我想使用专门用于该快捷方式的自定义格式,最好不要使用涉及xdotool
或类似的外部宏软件或全局系统范围的快捷方式的解决方案。
其中的功能Tools -> Customize -> Keyboard
似乎没有提供任何帮助。
(为什么我不想使用xdotool;最好直接在LibreOffice中使用解决方案。)
我在这里找到了以下OpenOffice宏代码,但它说它仅适用于Writer文档。如何修改此宏以将格式化的DATE-TIME插入Calc中当前选定的单元格?
'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
快捷方式后格式化单元格不起作用。
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句