List Info

Thread: Insert Creation Date of Document




Insert Creation Date of Document
user name
2006-05-20 16:58:33
Hi,

I'm trying to obtain the creation date  of the currently
open document. 
(an exception will probably be needed if the document has
not been saved 
yet).

I can't seem to find how to do it. This is based on code
where the 
document was loaded from a file.

Can somebody tell me where I went wrong?

Many thanks,

Jo

Sub InsertEurDate()

  dim odoc as object
  dim sCreationDate as string
  dim oDocCreationDate

  oDoc =
createUnoService("com.sun.star.document.StandaloneDocu
mentInfo")
  oDoc=ThisComponent
 
  Xray oDoc

  oDocCreationDate = CreateUnoStruct
("com.sun.star.util.DateTime")
  oDocCreationDate = oDoc.CreationDate() 
'                                                  <- It
tells me 
property or method not found

  sCreationDate = oDocCreationDate.Day & "/"
& oDocCreationDate.Month & 
"/" & oDocCreationDate.Year

  InsertDate(sCreationDate)
End Sub

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

Insert Creation Date of Document
user name
2006-05-20 17:44:42
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Jo,

> I'm trying to obtain the creation date  of the
currently open document.
> (an exception will probably be needed if the document
has not been saved yet).

try ...

OPTION EXPLICIT

Sub Main

	Dim oDocument as Object
	Dim oInfo as Object
	Dim oDate as Object
	Dim nDate as Long
	Dim vTime as Variant

	oDocument = ThisComponent
	oInfo = oDocument.DocumentInfo

	' get ...
	oDate = oInfo.CreationDate
	MsgBox oDate.Day & "." & oDate.Month
& "." & oDate.Year & " "
& oDate.Hours & ":" & oDate.Minutes

	' set ...
	nDate = DateValue(Date)
	oDate.Day = Day(nDate)
	oDate.Month = Month(nDate)
	oDate.Year = Year(nDate)
	vTime = TimeValue(Time)
	oDate.Hours = Hour(vTime)
	oDate.Minutes = Minute(vTime)
	oDate.Seconds = Second(vTime)
	oInfo.CreationDate = oDate

	MsgBox oDate.Day & "." & oDate.Month
& "." & oDate.Year & " "
& oDate.Hours & ":" & oDate.Minutes

End Sub

Oliver
- --

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C
AB40 CFD0 4A45
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


iD4DBQFEb1WKTiyrQM/QSkURApN7AKC8QKgtKHG2MwHsrZUJhKxmrKy85ACU
Dmt2
wo6P00ZQjQd3/qNcqb+Hig==
=0zNX
-----END PGP SIGNATURE-----

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

Insert Creation Date of Document
user name
2006-05-20 19:42:18
Oliver Brinzing wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Jo,
>
>   
>> I'm trying to obtain the creation date  of the
currently open document.
>> (an exception will probably be needed if the
document has not been saved yet).
>>     
>
> try ...
>
> OPTION EXPLICIT
>
> Sub Main
>
> 	Dim oDocument as Object
> 	Dim oInfo as Object
> 	Dim oDate as Object
> 	Dim nDate as Long
> 	Dim vTime as Variant
>
> 	oDocument = ThisComponent
> 	oInfo = oDocument.DocumentInfo
>
> 	' get ...
> 	oDate = oInfo.CreationDate
> 	MsgBox oDate.Day & "." &
oDate.Month & "." & oDate.Year &
" " & oDate.Hours & ":"
& oDate.Minutes
>
> 	' set ...
> 	nDate = DateValue(Date)
> 	oDate.Day = Day(nDate)
> 	oDate.Month = Month(nDate)
> 	oDate.Year = Year(nDate)
> 	vTime = TimeValue(Time)
> 	oDate.Hours = Hour(vTime)
> 	oDate.Minutes = Minute(vTime)
> 	oDate.Seconds = Second(vTime)
> 	oInfo.CreationDate = oDate
>
> 	MsgBox oDate.Day & "." &
oDate.Month & "." & oDate.Year &
" " & oDate.Hours & ":"
& oDate.Minutes
>
> End Sub
>
> Oliver
>   
Hi Oliver,

Your code has the kind of simplicity that I admire. Many
thanks for 
helping me out! I hope one day I will also be able to see
through the 
API and produce code like that.

This is what it became:

Sub GetDocCreationDate(oDoc) As Object
  ' Many thanks to Oliver Brinzing for helping me out on
this
  Dim oInfo as Object

  oInfo = oDoc.DocumentInfo

  GetDocCreationDate = oInfo.CreationDate
End Sub

Sub InsertEurDate()
  Dim oDate as Object

  oDate = GetDocCreationDate(ThisComponent)
  InsertDate(oDate.Day & "/" &
oDate.Month & "/" & oDate.Year)
End Sub

Sub InsertUSDate()
  Dim oDate as Object

  oDate = GetDocCreationDate(ThisComponent)

  InsertDate(oDate.Month & "/" &
oDate.Day & "/" & oDate.Year)
End Sub

Sub InsertDate(sDate)
  ' Based on GPLd code from Winfried Rohr. I tore it to
pieces but being 
able
  ' to reuse his code saved me a good deal of time.
  Dim oDesktop
  Dim oController
  Dim oDocument
  Dim oTextCursor
  Dim oCell
  Dim sCursorPosition
  Dim oFrame
  Dim oPageStyle

  oDesktop = createUnoService(
"com.sun.star.frame.Desktop" )
  oController = oDesktop.CurrentFrame.Controller
  oDocument = oController.Model
  oViewCursor = oController.ViewCursor

  if
oDocument.supportsService("com.sun.star.text.TextDocum
ent" ) then
   
    sCursorPosition = WhereIsCursor( oController.ViewCursor
)
       
    if sCursorPosition = "InText" then
      oTextCursor =
oDocument.getText().createTextCursorByRange( 
oViewCursor )
      oTextCursor.String = sDate
    elseif sCursorPosition = "InTable" then
      oCell = oViewCursor.Cell
      oTextCursor = oCell.getText().createTextCursorByRange(
oViewCursor )
      oCell.insertString( oTextCursor, sDate , FALSE )
    elseif sCursorPosition = "InFrame" then
      oFrame = oViewCursor.TextFrame()
      oFrame.getText().insertText( oViewCursor, sDate, False
)           
    elseif sCursorPosition = "InHeaderOrFooter"
then
      oPageStyle = 
oDocument.StyleFamilies().getByName("PageStyles"
).getByName( 
oViewCursor.PageStyleName )
      if not IsEmpty( oPageStyle.HeaderText ) then
        oText = oPageStyle.HeaderText
      else
        oText = oPageStyle.FooterText
      end if
      oTextCursor = oText.createTextCursorByRange(
oViewCursor )
      oText.insertString( oTextCursor, sDate , FALSE )
    end if
  end if
End Sub

Sub    WhereIsCursor( oViewCursor ) As String
  ' Based on GPLd code from Winfried Rohr. I tore it to
pieces but being 
able
  ' to reuse his code saved me a good deal of time.

  ' Test if cursor is in Header or Footer
  if oViewCursor.getText().ImplementationName =
"SwXHeadFootText" then
    WhereIsCursor = "InHeaderFooter"
    exit sub
  elseif Not IsEmpty( oViewCursor.TextTable ) then
    WhereIsCursor = "InTable"
    exit sub
  elseif Not IsEmpty( oViewCursor.TextFrame ) then
    WhereIsCursor = "InFrame"
    exit sub
  elseif Not IsEmpty( oViewCursor.Text ) then
    WhereIsCursor = "InText"
  endif
End Sub

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )