You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Eliot Kimber <ek...@contrext.com> on 2018/07/31 11:51:31 UTC

XWPFFieldRun Doesn't Work for Creating DOCX

When creating new DOCX the XWPFFieldRun class does not work to create paragraphs with CTSimpleFields.

The problem is that the field is not written out during commit. The current unit test only tests the read path but does not test the write path, which would fail.

I'm not sure what the right solution is (or I would have simply implemented it).

This code works:

CTSimpleField ctField = para.getCTP().addNewFldSimple();
		((XmlObject)ctField).newCursor()
			.setAttributeText(
					QNAME_INSTR_ATT, 
					fieldData);

So it's not a critical issue but it's definitely an annoyance in the API that you can't create simple fields directly.

I don't have time at the moment to puzzle through this so I was hoping somebody might have more cogent ideas about how best to address this in the API. 

But my fear is that addressing this would require serious adjustment or extension to the internals of XWPFParagraph.

Ideally I'd like something like:

XWPFSimpleField field = para.createSimpleField("PAGE");

I'd also like XWPF-level support for creating complex fields, but that's more involved due to the amorphous nature of complex fields, so I'm really not sure what design should be.

Thanks,

Eliot
--
Eliot Kimber
http://contrext.com
 



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


RE: XWPFFieldRun Doesn't Work for Creating DOCX

Posted by "Murphy, Mark" <mu...@metalexmfg.com>.
Yea, there are a lot of half finished classes in XWPF. Fields are one of those. If you look at Stack Overflow here https://stackoverflow.com/a/40264237/2296441 you will see how I add a table of contents as a simple field. This should be relatively easy to add as a method of a paragraph like this:

Public XWPFSimpleField createSimpleField(String instruction) {
	CTP ctP = p.getCTP();
	CTSimpleField field = ctP.addNewFldSimple();
	field.setInstr(instruction);
	return field;
}

Then you would add a table of contents like this: para.createSimpleField("TOC \\h");

-----Original Message-----
From: Eliot Kimber [mailto:ekimber@contrext.com] 
Sent: Tuesday, July 31, 2018 7:52 AM
To: POI Users List <us...@poi.apache.org>
Subject: XWPFFieldRun Doesn't Work for Creating DOCX

When creating new DOCX the XWPFFieldRun class does not work to create paragraphs with CTSimpleFields.

The problem is that the field is not written out during commit. The current unit test only tests the read path but does not test the write path, which would fail.

I'm not sure what the right solution is (or I would have simply implemented it).

This code works:

CTSimpleField ctField = para.getCTP().addNewFldSimple();
		((XmlObject)ctField).newCursor()
			.setAttributeText(
					QNAME_INSTR_ATT, 
					fieldData);

So it's not a critical issue but it's definitely an annoyance in the API that you can't create simple fields directly.

I don't have time at the moment to puzzle through this so I was hoping somebody might have more cogent ideas about how best to address this in the API. 

But my fear is that addressing this would require serious adjustment or extension to the internals of XWPFParagraph.

Ideally I'd like something like:

XWPFSimpleField field = para.createSimpleField("PAGE");

I'd also like XWPF-level support for creating complex fields, but that's more involved due to the amorphous nature of complex fields, so I'm really not sure what design should be.

Thanks,

Eliot
--
Eliot Kimber
http://contrext.com
 



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


Re: XWPFFieldRun Doesn't Work for Creating DOCX

Posted by "pj.fanning" <fa...@yahoo.com>.
Hi Eliot,
Could you log an issue in bugzilla to track this?



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html

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