Tech Tip: Custom Quick Reports and Character Sets
PRODUCT: 4D | VERSION: 11.6 | PLATFORM: Mac OS X
Published On: June 24, 2010
The default character set for exporting text in 4D v11 SQL is UTF-8 with Byte-Order-Mark (BOM). This is true for Quick Reports as well as other means of exporting data. It can cause problems for specific applications which do not yet support that character set. An example of this is Microsoft Excel or Word for Mac OS. They cannot correctly interpret UTF-8 text.
The following process can be used to generate MacRoman Quick Reports to get around this problem.
First create a form with a Report area on it. In the sample code this area is named "MyArea". Once the form has been created insert the following code into the Form method:
Case of :(Form event=On load) C_BLOB($doc) C_LONGINT(MyArea) QR ON COMMAND(MyArea;"runcommand") DOCUMENT TO BLOB("quick_report_document.4qr";$doc) QR BLOB TO REPORT(MyArea;$doc) End case |
A method named runcommand is called in the case of a call to a Quick Report command. The only command that needs to be changed is the generation command. By using Convert to text and CONVERT FROM TEXT the character set of the newly created document can be changed from UTF-8 to MacRoman. Here is the runcommand method:
C_LONGINT($1;$2) If ($2=qr cmd generate ) C_BLOB($myblob) C_TEXT($path;$text) QR EXECUTE COMMAND($1;$2) QR GET DESTINATION($1;$type;$path) DOCUMENT TO BLOB($path;$myblob) $text:=Convert to text($myblob;"UTF-8") CONVERT FROM TEXT($text;"MacRoman";$myblob) BLOB TO DOCUMENT($path;$myblob) Else QR EXECUTE COMMAND($1;$2) End if |