Author: Frank Cazabon
Posted: 2019-05-15 at 17:57:40
LOCAL loWord AS WORD.APPLICATION
LOCAL loDoc AS WORD.DOCUMENT
loWord = CREATEOBJECT("Word.Application")
loWord.Documents.ADD(oAppInfo.GroupPlanTemplate) &&("GroupPlan.dot")
m.loDoc = m.loWord.ActiveDocument
* Retrieve the number of bookmarks defined in DOC
m.lnCountMarks = m.loDoc.Bookmarks.COUNT
* Store bookmarks in an array
DIMENSION laMark[m.lnCountMarks]
FOR lnCount = 1 TO m.lnCountMarks
laMark[lnCount] = m.loDoc.Bookmarks(lnCount).NAME
ENDFOR
* Loop through all the bookmarks in the document
FOR lnCount = 1 TO m.lnCountMarks
m.lcMarkName = UPPER(laMark[lnCount])
WITH m.loDoc.Bookmarks(m.lcMarkName).RANGE
DO CASE
* Claims expense breakdown
CASE m.lcMarkName == UPPER("ClaimsExpense")
oRange = m.loDoc.Bookmarks(m.lcMarkName).RANGE
oTable = m.loDoc.Tables.Add( oRange, 1, 2)
oTable.BORDERS.InsideLineStyle = .F.
oTable.BORDERS.OutsideLineStyle = .F.
oTable.Cell[1,1].Range.Font.Bold = .T.
oTable.Cell[1,1].RANGE.InsertAfter("Expense Type")
oTable.Cell[1,1].RANGE.ParagraphFormat.ALIGNMENT = wdAlignParagraphLeft
oTable.Cell[1,2].Range.Font.Bold = .T.
oTable.Cell[1,2].RANGE.InsertAfter("Total Expense")
oTable.Cell[1,2].RANGE.ParagraphFormat.ALIGNMENT = wdAlignParagraphLeft
m.lnRow = 1
m.lnTotalExpense = 0
SELECT c_ExpenseBreakdown
SCAN
oTable.ROWS.ADD()
m.lnRow = m.lnRow + 1
oTable.Cell[m.lnRow,1].Range.Font.Bold = .F.
oTable.Cell[m.lnRow,1].RANGE.InsertAfter(c_ExpenseBreakdown.typ_name)
oTable.Cell[m.lnRow,2].Range.Font.Bold = .F.
oTable.Cell[m.lnRow,2].RANGE.InsertAfter(ALLTRIM(TRANSFORM(NVL(c_ExpenseBreakdown.ExpenseAmount, 0), "@R $$$,$$$,$$9.99")))
m.lnTotalExpense = m.lnTotalExpense + NVL(c_ExpenseBreakdown.ExpenseAmount, 0)
ENDSCAN
oTable.ROWS.ADD()
m.lnRow = m.lnRow + 1
oTable.Cell[m.lnRow,1].Range.Font.Bold = .T.
oTable.Cell[m.lnRow,1].RANGE.InsertAfter("TOTAL")
oTable.Cell[m.lnRow,2].Range.Font.Bold = .T.
oTable.Cell[m.lnRow,2].RANGE.InsertAfter(ALLTRIM(TRANSFORM(NVL(m.lnTotalExpense, 0), "@R $,$$$,$$9.99")))
ENDCASE
ENDWITH
ENDFOR
Frank.
Frank Cazabon
On 15/05/2019 05:04 PM, MB Software Solutions, LLC wrote:
> How do you dynamically add the rows? Via Office Automation code? If
> so, care to share?
>
>
> On 5/15/2019 4:54 PM, Frank Cazabon wrote:
>> I do stuff like that using Bookmarks in a Word template and
>> automating their replacement.
>>
>> Frank.
>>
>> Frank Cazabon
>>
>> On 15/05/2019 03:05 PM, MB Software Solutions, LLC wrote:
>>> Screenshot of Word document in question (with notations for where
>>> content is dynamic; some parts blurred just to protect the players):
>>> https://www.screencast.com/t/vOJd9eBwPaX
>>>
>>> Currently, my colleague did so many of these documents MANUALLY in
>>> Word. I'd pull my hair out if I had to do that, especially since
>>> I've got VFP. The trick here is to dynamically enter the names for
>>> each letter to an organization. Each organization can have 1:M
>>> names in this report.
>>>
>>> The quick thought is a VFP FRX Report, using XFRX (or something
>>> else) to save the output to a Word document. And given that the
>>> text above the dynamic organization name and user names/emails part
>>> is static, I could do it. But like you've probably encountered
>>> before, I don't like to force the Line-breaks in the VFP Report
>>> Writer if I can avoid it (PITA).
>>>
>>> So how would you produce these dynamic Word documents easily?
>>>
>>> Flattened cursor for this would have this structure:
>>>
>>> * OrgName
>>> * OrgID (e.g., P0135)
>>> * Name
>>> * AcctType
>>>
>>> That's it. User would select the Yes/No values and return to us.
>>> Task here is generated these 100 reports without having to manually
>>> do it (and obviously avoid the human error factor).
>>>
>>> tia,
>>> --Mike
>>>
>>>
>>>
>>>
>>> ---
>>> This email has been checked for viruses by Avast antivirus software.
>>> https://www.avast.com/antivirus
>>>
>>>
>>> --- StripMime Report -- processed MIME parts ---
>>> multipart/alternative
>>> text/plain (text body -- kept)
>>> text/html
>>> ---
>>>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: https://leafe.com/archives/byMID/e9f36cc0-6b57-9a3e-ddf1-0afcf62dc582@gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.