Save files with fields

Writing a book, Automating Document Production - Discuss your special needs here

Save files with fields

Postby SBC » Sun Mar 04, 2018 6:22 pm

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.
Attachments
SAVE FUNCTION.jpg
Generated save function with fields
OpenOffice 4.5.1 on Windows 10
SBC
 
Posts: 2
Joined: Sun Mar 04, 2018 5:22 pm

Save with field function

Postby SBC » Sun Mar 04, 2018 6:43 pm

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
Attachments
ID 04032018170155 - MEMORADIUM - GET MACROS TO OPENOFFICE TO WORK.doc
The file
(11.5 KiB) Downloaded 65 times
GET MACROS TO WORK IN OPENOFFICE.jpg
The fields I would like to have in the save function
SAVE FUNCTION.jpg
Save fuction
OpenOffice 4.5.1 on Windows 10
SBC
 
Posts: 2
Joined: Sun Mar 04, 2018 5:22 pm

Re: Save files with fields

Postby YODA » Sat Sep 22, 2018 2:49 am

Well for one thing try saving in .odt because .doc is an undocumented binary format so there can never be 100% compatibility
Openoffice4.16 on windows 10 Libreoffice Version: 6.1.3.2 (x64)
YODA
 
Posts: 57
Joined: Fri Aug 10, 2018 4:06 am

Re: Save files with fields

Postby Zizi64 » Sat Sep 22, 2018 7:49 am

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...Ö
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8062
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Save files with fields

Postby keme » Sat Sep 22, 2018 8:44 am

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!
User avatar
keme
Volunteer
 
Posts: 3175
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Save files with fields

Postby Zizi64 » Sat Sep 22, 2018 9:22 am

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.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8062
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Advanced Uses

Who is online

Users browsing this forum: No registered users and 1 guest