Page 1 of 1

Save files with fields

PostPosted: Sun Mar 04, 2018 6:22 pm
by SBC
Hi

My name is Steffen, and I hoping I can get some help here in this forum. In the last 4 days I have tried to save a text document with fields.

I have studying the article and the codes on https://forum.openoffice.org/en/forum/v ... p?t=20046#

I cannot get it to works as I would like to have it.

I have this code

Sub SaveWithFieldNames
On error goto EH
oDoc = ThisComponent
oTFS = oDoc.getTextFields
enum = oTFS.createEnumeration
While enum.hasMoreElements
oTF = enum.nextElement
Select Case oTF.Content
Case "ID" : N = oTF.Anchor.String
Case "SUBJECT" : A = oTF.Anchor.String
End Select
Wend
U = "-"
aray = Split(D,"/") 'convert slashes to dashes.
D = Join(aray,"-")
filename = N & "MEMORADIUM" & U & A & U ".odt"
url = ConvertToURL("C:\users\cat\documents\" & filename) 'Insert Your Desired Directory Path.
oDoc.StoreAsURL(url,Array())
oDoc.Modified = false 'avoid Save being called if doc closed without further edits.
End 'end normal execution.
EH: 'error handler.
MsgBox "You may have illegal file name character." & Chr(13)_
& Chr(13) & filename,,"AN ERROR OCCURRED"
End Sub

What I would like to have is follwing, pleace see the uploaded picture.

Save with field function

PostPosted: Sun Mar 04, 2018 6:43 pm
by SBC
Hi:)

My name is Steffen, and I am realy hoping I can get some help here in this forum. I am working on a template in openoffice, and In the last 4 days I have tried to save a text document with fields.

I have studying the article and the codes on https://forum.openoffice.org/en/forum/v ... p?t=20046#

I cannot get it to works as I would like to have it.

I have this code, and furthere more I have uploaded some picture and the file itself.

Sub SaveWithFieldNames
On error goto EH
oDoc = ThisComponent
oTFS = oDoc.getTextFields
enum = oTFS.createEnumeration
While enum.hasMoreElements
oTF = enum.nextElement
Select Case oTF.Content
Case "ID" : N = oTF.Anchor.String
Case "SUBJECT" : A = oTF.Anchor.String

End Select
Wend
U = "-"
aray = Split(D,"/") 'convert slashes to dashes.
D = Join(aray,"-")
filename = N & "MEMORADIUM" & U & A & U ".odt"
url = ConvertToURL("C:\users\cat\documents\" & filename) 'Insert Your Desired Directory Path.
oDoc.StoreAsURL(url,Array())
oDoc.Modified = false 'avoid Save being called if doc closed without further edits.
End 'end normal execution.
EH: 'error handler.
MsgBox "You may have illegal file name character." & Chr(13)_
& Chr(13) & filename,,"AN ERROR OCCURRED"
End Sub

I have uploaded some picture and the file.

One the code url = ConvertToURL("C:\users\cat\documents\" & filename) 'Insert Your Desired Directory Path. I would not have the file to save in desired Directory path.

I thank you you very much from your time. It would be grat if can get this to work.

Sincerly

Steffen

Re: Save files with fields

PostPosted: Sat Sep 22, 2018 2:49 am
by YODA
Well for one thing try saving in .odt because .doc is an undocumented binary format so there can never be 100% compatibility

Re: Save files with fields

PostPosted: Sat Sep 22, 2018 7:49 am
by Zizi64
Well for one thing try saving in .odt because .doc is an undocumented binary format so there can never be 100% compatibility


+1


SBC,

Always use the native, international standard ODF fileformats - especially if you want to control them with StarBasic/API macros

Please upload the .odt format version of your sample file.
(Yes, we can convert it, but the result of the conversion never will be 100% quality.
Maybe you have an original .odt version of the sample file...Ö

Re: Save files with fields

PostPosted: Sat Sep 22, 2018 8:44 am
by keme
As a side note: it is too bad that this problem report has been left unanswered for six months. Contributing cause: accidental double entry took the thread out of "unanswered posts". Still a "freak accident" that all of us missed it at the time.

The poster has not logged in again after, so he may have given up on us. If you are still around: Sorry about the delay, Steffen!

Re: Save files with fields

PostPosted: Sat Sep 22, 2018 9:22 am
by Zizi64
There are "Document properties" values in the ODF fileformat.
You can see and handle (fill-in) them in the menu item:
File - Properties - ...

... Description.

Here you can type-in the Title, Subject, Keywords, Comments.



And there are Custom properties in same place but on the "Custom Properties" TAB.

You can handle them (read/write) by your macro, but you need use different procedures for the different types of the properties.



And you can insert these properties (as LABELs/FIELDs) into the document. Just insert them into relevant part of the text if you want visualize them in a document:
Insert - Field - More Fields - Document TAB/Docinformation TAB
They will refresh visually too, when you modify the property in the user interface described above.


How to get the String type Document properties by a macro (there are more types of the properties, like the Date, Boolean, Duration...):

Code: Select all   Expand viewCollapse view
oDoc = ThisComponent ) rem ...or you can get the actual document object by other way)

sTitleText = oDoc.getDocumentProperties().Title
sAuthorText = oDoc.getDocumentProperties().Author

sSomeUserDefpropText = oDoc.DocumentProperties.UserDefinedProperties.getPropertyValue("TheNameOfTheProperty") 


Tested in LibreOffice. This macros lines and the properties will work in the native ODF fileformats only.