I do not know if you are still looking for a solution to this problem, and I
am sory that work prevented me from playing with some code until today, but
I might have found one, a workaround at least. Take a look at this piece of
code;

public static final void colourTest(String filename) throws IOException {
        File file = null;
        FileOutputStream fos = null;
        XWPFDocument document = null;
        XWPFParagraph para = null;
        XWPFRun run = null;
        CTR ctr = null;
        CTRPr ctrPr = null;
        STThemeColor color = null;
        try {

        // Create a new blank document and add a paragraph to it.
            document = new XWPFDocument();
            para = document.createParagraph();

        // Add a run to the paragraph and set it's text.
            run = para.createRun();
            run.setText("Arial Rounded MT Bold. ");

        // From the run, get the CTR object. This may not be the best way to go
        // about the task, it might be best just to add a CTRPr object to the 
run
        // I was assuming that text read from an existing document may well have
        // an associated CTRPr object but I do not know this for a fact.
            ctr = run.getCTR();
            ctrPr = ctr.getRPr();

        // If there is no CTRPr objectm, tne create it here.
            if(ctrPr == null) {
                ctrPr = ctr.addNewRPr();
            }

        // Set the font for the text and it's colour here. Note that I have not 
yet
found
        // a way to specify the exact colour I want either by name of using the
familar
        // RGB notation. The search continues for this. There are quite a number
        // of pre-defined theme colours such as ACCENT_1, 2, 3, etc and one of
        // these may suit your requirements.
            ctrPr.addNewRFonts().setAscii("Arial Rounded MT Bold");
            ctrPr.addNewColor().setThemeColor(
                ctrPr.addNewColor().xgetThemeColor().ACCENT_2);

            run = para.createRun();
            run.setText("Times New Roman.");

            ctr = run.getCTR();
            ctrPr = ctr.getRPr();

            if(ctrPr == null) {
                ctrPr = ctr.addNewRPr();
            }

            ctrPr.addNewRFonts().setAscii("Times New Roman");

            file = new File(filename);
            fos = new FileOutputStream(file);

            document.write(fos);
        }
        finally {
            if(fos != null) {
                fos.close();
                fos = null;
            }
        }
    }

As you can see, the code creates a new document but the same approach should
be applicable to documents you are reading. The only change required should
be to get at the XWPFRun you wish to change. These objects can usually be
accessed from the XWPFParagraph object as a List by calling the getRuns()
method of the XWPFParagraph object. If you want to test this piece of code,
just add the method to class and then call it, passing the path to and name
of the document you wish to create.

There must be a way to set the colour explicitly using either a name or RGB
notation. If I find one, I will post again.

Yours

Mark B

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/how-to-modify-text-s-color-of-word-s-table-tp4285926p4290654.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to