LibreOffice Calc의 셀에 단일 바로 가기를 사용하여 현재 날짜 및 시간(DATETIME 함수) 삽입

LibreOffice Calc의 셀에 단일 바로 가기를 사용하여 현재 날짜 및 시간(DATETIME 함수) 삽입

현재 날짜를 삽입하는 CTRL+ 단축키와 현재 시간을 삽입하는 + + 단축키 가 있다는 것을 알고 있습니다 .;CTRLSHIFT;

그러나 여기에는 두 가지 문제가 있습니다.

1) 두 가지 모두에 대해 하나의 단축키를 갖고 싶습니다.

2) 사용자 정의 날짜-시간 형식을 사용하고 싶습니다( YYYY-MM-DD HH:MM:SS)

내 언어 기본 형식은 MM/DD/YY HH:MM:SS pm/am- I do 입니다.~ 아니다이것을 바꾸고 싶습니다. 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에서 테스트됨): 매크로나 추가 소프트웨어 없이 하나의 셀에 삽입하는 유일한 해결책은 3개의 단축키를 차례로 사용하는 것입니다.

  • CTRL+;
  • space
  • CTRL+ SHIFT+;

적어도 이것은 당신에게 줄 것입니다DD-MM-YYYY HH:MM

여기에서 사용자 정의 형식을 원하는 대로 변경하면 됩니다.YYYY-MM-DD HH:MM:SS

관련 정보