Example usage for org.apache.poi.xssf.usermodel XSSFRelation NS_SPREADSHEETML

List of usage examples for org.apache.poi.xssf.usermodel XSSFRelation NS_SPREADSHEETML

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFRelation NS_SPREADSHEETML.

Prototype

String NS_SPREADSHEETML

To view the source code for org.apache.poi.xssf.usermodel XSSFRelation NS_SPREADSHEETML.

Click Source Link

Usage

From source file:com.vodafone.poms.ii.helpers.ExportManager.java

private static void addObjectToShape(XSSFSheet sh, XSSFClientAnchor imgAnchor, int shapeId, String objRelId,
        String imgRelId, String progId) {
    CTWorksheet cwb = sh.getCTWorksheet();
    CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();

    CTOleObject ole1 = oo.addNewOleObject();
    ole1.setProgId(progId);/*from  ww  w.  ja va  2s .  c  om*/
    ole1.setShapeId(shapeId);
    ole1.setId(objRelId);

    XmlCursor cur1 = ole1.newCursor();
    cur1.toEndToken();
    cur1.beginElement("objectPr", XSSFRelation.NS_SPREADSHEETML);
    cur1.insertAttributeWithValue("id", relationshipsNS, imgRelId);
    cur1.insertAttributeWithValue("defaultSize", "0");
    cur1.beginElement("anchor", XSSFRelation.NS_SPREADSHEETML);
    cur1.insertAttributeWithValue("moveWithCells", "1");

    CTTwoCellAnchor anchor = CTTwoCellAnchor.Factory.newInstance();
    anchor.setFrom(imgAnchor.getFrom());
    anchor.setTo(imgAnchor.getTo());

    XmlCursor cur2 = anchor.newCursor();
    cur2.copyXmlContents(cur1);
    cur2.dispose();

    cur1.toParent();
    cur1.toFirstChild();
    cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "from"));
    cur1.toNextSibling();
    cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "to"));

    cur1.dispose();
}