Bug 60454 - the XWPFRun object can not recognize its superscript
Summary: the XWPFRun object can not recognize its superscript
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.15-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-08 07:07 UTC by triblade
Modified: 2016-12-08 12:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description triblade 2016-12-08 07:07:48 UTC
I can not use getsubscript function to recognize a SuperScript Run.It will be regard as a normal run.

However, the subscript can be recognize successfully.

In another way, the javadoc content of the superscript and subscript is mixed with each other. Please check! thanks.
Comment 1 Mark Murphy 2016-12-08 12:26:50 UTC
This works for me:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

public class TestVerticalAlign {

	public static void main(String[] args) {
		XWPFDocument doc = new XWPFDocument();
		XWPFParagraph p = doc.createParagraph();
		XWPFRun r = p.createRun();
		r.setText("This is some Text");
		r = p.createRun();
		r.setSubscript(VerticalAlign.SUBSCRIPT);
		r.setText(" This is subscript text");
		r = p.createRun();
		r.setSubscript(VerticalAlign.SUPERSCRIPT);
		r.setText(" This is superscript text");
		
		XWPFParagraph p2 = doc.createParagraph();
		r = p2.createRun();
		for (XWPFRun r2 : p.getRuns()) {
			switch (r2.getSubscript()) {
			case BASELINE:
				r.addCarriageReturn();
				r.setText("Normal Text");
				break;
			case SUBSCRIPT:
				r.addCarriageReturn();
				r.setText("Subscript Text");
				break;
			case SUPERSCRIPT:
				r.addCarriageReturn();
				r.setText("Superscript Text");
				break;
			default:
				r.addCarriageReturn();
				r.setText("Unknown Text Alignment");
				break;
			}
		}

		// Write the Document in file system
		try {
			FileOutputStream out = new FileOutputStream(new File(
					"valigntest.docx"));
			doc.write(out);
			out.close();
			doc.close();
			System.out.println("valigntest.docx written successully");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
Comment 2 Mark Murphy 2016-12-08 12:32:18 UTC
My test was using POI 3.14. If you are using an older version of POI, please upgrade to the most recent release. If you still have issues, please reopen this issue and attach a document that exhibits the unexpected behavior.