使用单个快捷方式将当前日期和时间(DATETIME函数)插入LibreOffice Calc中的单元格

五彩纸屑

我知道有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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

B列中的单元格值是否在A列中?(LibreOffice-Calc)

LibreOffice Calc:如何将当前ods文档的文件路径获取到单元格中?

如果Libreoffice Calc中的两个先前的单元格相同,如何将单元格设置为1?

LibreOffice Calc:检查单元格是否为公式

根据当前日期在单元格中输入

全时间写在单元格中

LibreOffice Calc在单元格中显示公式而不是结果

如何在LibreOffice Calc电子表格中查找引用当前单元格的单元格?

如何从LibreOffice Calc中的所有选定单元格中删除保护单引号的纯文本?

如何在LibreOffice Calc中的单元格中换行

根据Libreoffice Calc中的列表突出显示多个单元格

在单元格中插入VLOOKUP公式

更新DataGrid中的单个单元格

搜索特定的关键字并将整个单元格内容替换为LibreOffice Calc中的其他内容

在LibreOffice Calc中,是否有一个热键可以编辑当前单元格?

识别LibreOffice Calc中包含给定文本的单元格

LibreOffice calc在单元格中查找字符串(如果它是对另一个单元格的公式引用)

从Excell复制后无法将所有文本粘贴到LibreOffice Calc的单元格中

将百分比添加到LibreOffice calc列中的每个单元格

Openpyxl在单个单元格中写入

LibreOffice Calc:基于列/单元格值的条件格式

Excel-自动将当前日期/时间插入单元格

遍历LibreOffice Calc中的单元格时出现运行时错误

如何在单元格中粘贴文本时禁用 LibreOffice Calc 中的导入选项?

如何在 libreoffice calc 中定期更改单元格值?

Libreoffice calc 单元格刷新

如何在 LibreOffice Calc 中自动忽略空单元格(并在以后的函数中调整它们的角色)?

在 Calc 宏中使用由突出显示的单元格确定的范围,而不是绝对单元格引用

LibreOffice Calc:逐步遍历给定单元格中限制之间的一系列值