Ir al contenido principal

Sage X3 convert RTF to plain text


Here a function to convert a Clob rtf text to plain text
Example of function that return the converted text into a Char variable
Good only for short text, less than 250 chars
  1. Funprog F_RTF2TEXT(CLOB)
  2. Variable Clbfile CLOB
  3. Local Integer LENTXMT : LENTXMT = 250
  4. Local Integer NRIGHE : NRIGHE = 4 # 4 = 250x4 char
  5. Local Char XOUT(LENTXMT)(NRIGHE)
  6. Call S_RTF2TEXT(LENTXMT,CLOB,XOUT,NRIGHE)
  7. #Concatenate the row with plain text, by removing the empty space
  8. Local Char XRET(250) : Raz XRET
  9. For XI = 0 To NRIGHE
  10. XRET += vireblc(XOUT(XI),2)
  11. Next
  12. End XRET
Example,
Convert the header text of a sales order
  1. $MYTEST
  2. If !clalev ([F:SOH]) : Local File SORDER [F:SOH] : Endif
  3. If !clalev ([F:TXC]) : Local File TEXCLOB [F:TXC] : Endif
  4. Filter [F:SOH]
  5. Filter [F:TXC]
  6. For [F:SOH] Where SOHNUM = "000000001"
  7. For [F:TXC] Where CODE = [F:SOH]SOHTEX1
  8. local char MYTEXT(250)
  9. MYTEXT = func F_RTF2TEXT([F:TXC]TEXTE)
  10. Infbox "MYTEXT= "+ MYTEXT
  11. Next
  12. Next
  13. Return

Core procedures:

  1. ###############################################################################
  2. # CORE PROCEDURES
  3. #
  4. # Author: Matteo Carminati (mcarminati@ma-tica.it)
  5. #
  6. # This program is free software; you can redistribute it and/or modify it
  7. # under the terms version 3 of the GNU General Public License as published
  8. # by the Free Software Foundation. This program is distributed in the hope
  9. # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  10. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. # See the GNU General Public License for more details.
  12. #
  13. ###############################################################################
  14. Subprog S_RTF2TEXT(PLENRIGAOUT,CLOB,PTXTOUT,PNRIGEOUT)
  15. Value Integer PLENRIGAOUT
  16. Variable Clbfile CLOB
  17. Variable Char PTXTOUT
  18. Variable Integer PNRIGEOUT
  19. Local Integer XRIGHE
  20. Local Integer XNOL
  21. Local Integer XNCH
  22. Local Char XCH(1)
  23. Local Char XCHPREV(1)
  24. Local Integer XSTRTAG1 : XSTRTAG1 = 0
  25. Local Integer XSTRTAG2 : XSTRTAG2 = 0
  26. Local Integer LENGHT : LENGHT = len(CLOB)
  27. Local Integer CLOTAI : CLOTAI = int(LENGHT/GCLOLNG)+1
  28. Local Char PRTFIN (GCLOLNG)(CLOTAI)
  29. Setlob PRTFIN With CLOB
  30. XRIGHE = dim(PRTFIN,1)
  31. Local Char XOUT(250)(XRIGHE)
  32. Local Integer XOUTRLEN(XRIGHE)
  33. Local Char RIGA(250)
  34. Local Integer XESCAPE
  35. #Toglie i tag RTF
  36. For XNOL = 0 To XRIGHE - 1
  37. Raz RIGA
  38. RIGA = PRTFIN(XNOL)
  39. XOUTRLEN(XNOL) = 0
  40. For XNCH = 1 To len(RIGA)
  41. XCHPREV = XCH
  42. XCH = mid$(RIGA,XNCH,1)
  43. If XCH = "\" Then
  44. XESCAPE = -1
  45. If func F_GETNEXTCHR(PRTFIN,1,XNCH,XNOL,XRIGHE)= "}" Then
  46. XCHPREV = XCH
  47. XNCH = XNCH + 1
  48. XCH = "}"
  49. XESCAPE = 1
  50. Endif
  51. If func F_GETNEXTCHR(PRTFIN,1,XNCH,XNOL,XRIGHE)= "{" Then
  52. XCHPREV = XCH
  53. XNCH = XNCH + 1
  54. XCH = "{"
  55. XESCAPE = 1
  56. Endif
  57. If func F_GETNEXTCHR(PRTFIN,4,XNCH,XNOL,XRIGHE)= "pard" Then
  58. XNCH = XNCH + 4
  59. XCH = " "
  60. XESCAPE = 1
  61. Endif
  62. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "par" Then
  63. XNCH = XNCH + 3
  64. XCH = " "
  65. XESCAPE = 1
  66. Endif
  67. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'e0" Then
  68. XNCH = XNCH + 3
  69. XCH = "a"
  70. XESCAPE = 1
  71. Endif
  72. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'e9" Then
  73. XNCH = XNCH + 3
  74. XCH = "e"
  75. XESCAPE = 1
  76. Endif
  77. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'e8" Then
  78. XNCH = XNCH + 3
  79. XCH = "e"
  80. XESCAPE = 1
  81. Endif
  82. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'b0" Then
  83. XNCH = XNCH + 3
  84. XCH = "°"
  85. XESCAPE = 1
  86. Endif
  87. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'ec" Then
  88. XNCH = XNCH + 3
  89. XCH = "i"
  90. XESCAPE = 1
  91. Endif
  92. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'f2" Then
  93. XNCH = XNCH + 3
  94. XCH = "o"
  95. XESCAPE = 1
  96. Endif
  97. If func F_GETNEXTCHR(PRTFIN,3,XNCH,XNOL,XRIGHE)= "'f9" Then
  98. XNCH = XNCH + 3
  99. XCH = "u"
  100. XESCAPE = 1
  101. Endif
  102. If func F_GETNEXTCHR(PRTFIN,2,XNCH,XNOL,XRIGHE)= "fs" Then #Font size
  103. XNCH = XNCH + 2
  104. XCH = ""
  105. XESCAPE = -1
  106. Endif
  107. If XESCAPE = -1 Then
  108. XSTRTAG1 = 1
  109. XNCH = XNCH + 1
  110. Endif
  111. Endif
  112. If XCH = "{" and XCHPREV <> "\" Then XSTRTAG2 = XSTRTAG2 + 1 : Endif
  113. If XSTRTAG1 = 0 and XSTRTAG2 <= 1 Then
  114. XOUT(XNOL) += XCH
  115. XOUTRLEN(XNOL) += 1
  116. Endif
  117. If XCH = " " or find(func F_GETNEXTCHR(PRTFIN,2,XNCH-1,XNOL,XRIGHE) ,'\}','\{','\\') > 0 Then XSTRTAG1 = 0 : Endif
  118. If XCH = "}" and XCHPREV <> "\" Then XSTRTAG2 = XSTRTAG2 - 1 : Endif
  119. Next
  120. Next
  121. Local Integer XNOL2
  122. Local Integer XCONTA2
  123. XNOL2 = 0
  124. XCONTA2 = PLENRIGAOUT
  125. For XNOL = 0 To XRIGHE - 1
  126. Raz RIGA
  127. RIGA = XOUT(XNOL)
  128. If XNOL = XRIGHE : RIGA = vireblc(RIGA,1) : Endif
  129. If len(RIGA) > 0 Then
  130. For XNCH = 1 To len(RIGA)
  131. XCH = mid$(RIGA,XNCH,1)
  132. If XCH = chr$(13) Then
  133. XCH = " "
  134. If func F_GETNEXTCHR(XOUT,1,XNCH,XNOL,XRIGHE)= chr$(10) Then
  135. XNCH = XNCH + 1
  136. Endif
  137. Endif
  138. If XCH = chr$(10) Then
  139. XCH = " "
  140. If func F_GETNEXTCHR(XOUT,1,XNCH,XNOL,XRIGHE)= chr$(13) Then
  141. XNCH = XNCH + 1
  142. Endif
  143. Endif
  144. If XNCH = 1 and XNOL = 0 and XCH = "{" Then XCH = "" : Endif
  145. PNRIGEOUT = XNOL2 + 1
  146. PTXTOUT(XNOL2) += XCH
  147. XCONTA2 = XCONTA2 - 1
  148. If XCONTA2 = 0 Then
  149. XNOL2 = XNOL2 + 1
  150. XCONTA2 = PLENRIGAOUT
  151. Endif
  152. Next
  153. Endif
  154. Next
  155. #tolgo la graffa finale
  156. RIGA = vireblc(PTXTOUT(XNOL2),1)
  157. If mid$(RIGA,len(RIGA),1) = "}" Then
  158. PTXTOUT(XNOL2) = mid$(RIGA,1,len(RIGA)-1)
  159. Endif
  160. End
  161. ############################
  162. Funprog F_GETNEXTCHR(PARRIN,NCHNEXT,NCURPOS,NCURNOL,NTOTRIGHE)
  163. Value Char PARRIN
  164. Value Integer NCHNEXT
  165. Value Integer NCURPOS
  166. Value Integer NCURNOL
  167. Value Integer NTOTRIGHE
  168. Local Char XRET(NCHNEXT) : XRET = ""
  169. Local Integer XNCH
  170. Local Char RIGA(250)
  171. Local Integer XCONTA
  172. For XNOL = NCURNOL To NTOTRIGHE - 1
  173. RIGA = PARRIN(NCURNOL)
  174. For XNCH = NCURPOS + 1 To len(RIGA) - 1
  175. XRET += mid$(RIGA,XNCH,1)
  176. XCONTA += 1
  177. If XCONTA = NCHNEXT Then
  178. Break
  179. Endif
  180. Next
  181. If XCONTA = NCHNEXT Then
  182. Break
  183. Endif
  184. NCURPOS = 0
  185. Next
  186. End XRET

Entradas populares de este blog

Valores de fstat

Fstat fstat  is a numeric status that is returned upon execution of a database operation, a sequential file operation, or a lock instruction. Syntax fstat Examples # MYTABLE is a table with a key called KEY1, that has a unique component called KEYVAL # Create a record in the table MYTABLE with they key value 1 if it doesn't exist Local File MYTABLE [MYT] Read [MYT]KEY1=1 If fstat [MYT]KEYVAL=1 : Write [MYT] If fstat MSG="The key was created in the mean time" Else MSG="Key created" Endif Else MSG="Key already exists" Endif Details fstat  is always set to '0' if the operation is successfully completed, and has a non-null value if there is an error: In a sequential read ( Getseq  and  Rdseq ),  fstat  is set to '1' at the end of the file. On  Lock ,  fstat  is set to '1' if the lock could not be performed. For a database operation ( Read ,  Look ,  Readlock ,  For ,  Write ,  ...

3 ways to send a mail from code in Sage X3, with more attachments too

Origen Fuente:  https://en.sagedev.it/sagex3/send-mail-from-code-with-attachments-sage-x3/ Autor:  https://en.sagedev.it/category/sagex3/ In this post I’ll show you how to send a mail from adonix code in Sage X3. The points we will face are: 1) Meladx/Send introduction 2) Sending  through  meladx (the best way for me: at the end with just a single code line you send a mail!) 3) Sending  through  Workflow 4) Sending  through  ENVOI_MAIL(…) From AWRKMEL Sending mail from code in Sage X3: Send vs meladx Sage X3 has two native ways for sending mails. The first way is  meladx  executable file, that you can find in  runtime\bin  directory. The seconde one is Send instruction, that was used to send mail through an application of the client station (for more information on “Send GSERMES”  go here ). The Meladx executable Meladx send messages through SMTP/POP3 protocols by means of the mail  ...

How to Install and Manage Sage X3 Add-Ins in Microsoft Office

When you enable an add-in, it adds custom commands and new features to Microsoft Office programs that help increase your productivity. In this blog post, we’ll review how to install the Sage X3 Add-In for MS Excel and what to do if your Sage X3 Add-In is missing. Fuente original: https://www.netatwork.com/how-to-install-and-manage-sage-x3-add-ins-in-ms-office/ How to Install the Sage X3 Add-In in Microsoft Excel Go to Administration > Utilities > Installation > Install addins for Office V11 Image:   V12 Image:   It should begin downloading the exe, open the exe Next > Install   Open Excel > File > Options   Select Add–Ins > Manage: COM Add-ins > Go   Check the “Excel AddIn for Sage” > Ok   You are now ready to export Excel-based reports/grids from Sage X3. How to troubleshoot and fix a missing Sage X3 add-in in Microsoft Excel Open the Microsoft Office product where the  Sage X3  add-in is missing. Go to Options: Se...