Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 10.0   10.1   10.2   10.3   10.4   10.5   11.0   11.1   11.2   11.3    Statistic    FMM    Blog  

RichText.WriteFile

Writes current rich text to a file.

Component Version macOS Windows Linux Server iOS SDK
RichText 4.4 ✅ Yes ❌ No ❌ No ✅ Yes, on macOS ✅ Yes
MBS( "RichText.WriteFile"; Path; Format )   More

Parameters

Parameter Description Example
Path The native file path. "/Users/cs/Desktop/test.doc"
Format The file format to use. Can be DOC, DOCX or RTF. "DOC"

Result

Returns OK or error.

Description

Writes current rich text to a file.
Please pass format type:
  • doc: creates old style Word document
  • rtf: created rich text file.
  • docx: creates newer Word document.
  • html: creates html file.
  • webarchive: creates html and renders web archive.
  • opendocument: creates open office document.

Warning: The plugin can only read/write the styles/formats which Apple supports for their cocoa framework. If the styles don't come through to Word formats, maybe try RTF instead and let Word open that?

This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.

Examples

Read a file, apply replaces and save it:

# load from container
Set Variable [$r; Value:MBS("RichText.ReadContainer"; Replace Text in Word File::InputContainer)]
If [MBS("IsError")]
    Show Custom Dialog ["Error"; "Failed to read file."]
    Exit Script []
End If
# now loop through records to do replaces
Go to Record/Request/Page [First]
Loop
    Set Variable [$r; Value:MBS("RichText.ReplaceText"; Replace Text in Word File::Old Text; Replace Text in Word File::New Text)]
    Go to Record/Request/Page [Next; Exit after last]
End Loop
# write file
Set Variable [$r; MBS("RichText.WriteFile"; Replace Text in Word File::path; Replace Text in Word File::format)]
# cleanup
Set Variable [$r; Value:MBS("RichText.Release")]

Save as docx, the newer XML based Word file format:

# Word, new format
Set Variable [ $path ; Value: $folder & "/test.docx" ]
Set Variable [ $r ; Value: MBS( "RichText.WriteFile"; $path; "docx" ) ]

Save an old doc:

# Word, old format
Set Variable [ $path ; Value: $folder & "/test.doc" ]
Set Variable [ $r ; Value: MBS( "RichText.WriteFile"; $path; "doc" ) ]

Save as RTF:

# RTF
Set Variable [ $path ; Value: $folder & "/test.rtf" ]
Set Variable [ $r ; Value: MBS( "RichText.WriteFile"; $path; "rtf" ) ]

See also

Example Databases

Created 16th October 2014, last changed 3th May 2019


RichText.WriteDOC - RichText.WritePDF

Feedback: Report problem or ask question.




Links
MBS Xojo Plugins

Start Chat