poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 45001] Range.insertBefore() and Range.delete() fail with Unicode characters
Date Sat, 14 Jun 2008 05:49:19 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=45001


N. Hira <nhira@cognocys.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |ASSIGNED




--- Comment #4 from N. Hira <nhira@cognocys.com>  2008-06-13 22:49:19 PST ---
Sorry for the delay.  Also have a replaceText() that can be cleaned up and
would make a great addition to the API for mail-merge-type uses...

/**
 *      Replace (one instance of) a piece of text with another...
 *
 *      @param  pPlaceHolder            The text to be replaced (e.g.,
"${company}")
 *      @param  pValue                          The replacement text (e.g.,
"Cognocys, Inc.")
 *      @param  pDocument                       The <code>HWPFDocument</code>
in which the placeholder was found
 *      @param  pStartOffset            The offset or index where the
<code>CharacterRun</code> begins
 *      @param  pPlaceHolderIndex       The offset or index of the placeholder,
relative to the
 *                                                             
<code>CharacterRun</code> where <code>pPlaceHolder</code> was found
 *
 *      @throws DocumentFillerException
 */
protected void replaceText(String pPlaceHolder, String pValue, 
        int pStartOffset, int pPlaceHolderIndex, HWPFDocument pDocument) 
        throws DocumentFillerException {

        int absPlaceHolderIndex = pStartOffset + pPlaceHolderIndex;
        Range subRange = new Range(
                absPlaceHolderIndex, 
                (absPlaceHolderIndex + pPlaceHolder.length()), pDocument);
        if (subRange.usesUnicode()) {

                absPlaceHolderIndex = pStartOffset + (pPlaceHolderIndex * 2);
                subRange = new Range(
                        absPlaceHolderIndex, 
                        (absPlaceHolderIndex + (pPlaceHolder.length() * 2)), 
                        pDocument);
        }

        subRange.insertBefore(pValue);

        // re-create the sub-range so we can delete it
        subRange = new Range(
                (absPlaceHolderIndex + pValue.length()),
                (absPlaceHolderIndex + pPlaceHolder.length() +
pValue.length()), 
                        pDocument);
        if (subRange.usesUnicode())
                subRange = new Range(
                        (absPlaceHolderIndex + (pValue.length() * 2)),
                        (absPlaceHolderIndex + (pPlaceHolder.length() * 2) + 
                                (pValue.length() * 2)), pDocument);

        subRange.delete();
}


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message