Search in sources :

Example 1 with CTClientData

use of com.microsoft.schemas.office.excel.CTClientData in project poi by apache.

the class XSSFComment method setAddress.

@Override
public void setAddress(CellAddress address) {
    CellAddress oldRef = new CellAddress(_comment.getRef());
    if (address.equals(oldRef)) {
        // nothing to do
        return;
    }
    _comment.setRef(address.formatAsString());
    _comments.referenceUpdated(oldRef, _comment);
    if (_vmlShape != null) {
        CTClientData clientData = _vmlShape.getClientDataArray(0);
        clientData.setRowArray(0, new BigInteger(String.valueOf(address.getRow())));
        clientData.setColumnArray(0, new BigInteger(String.valueOf(address.getColumn())));
        avoidXmlbeansCorruptPointer(_vmlShape);
    }
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) BigInteger(java.math.BigInteger) CTClientData(com.microsoft.schemas.office.excel.CTClientData)

Example 2 with CTClientData

use of com.microsoft.schemas.office.excel.CTClientData in project poi by apache.

the class XSSFVMLDrawing method findCommentShape.

/**
     * Find a shape with ClientData of type "NOTE" and the specified row and column
     *
     * @return the comment shape or <code>null</code>
     */
protected CTShape findCommentShape(int row, int col) {
    for (XmlObject itm : _items) {
        if (itm instanceof CTShape) {
            CTShape sh = (CTShape) itm;
            if (sh.sizeOfClientDataArray() > 0) {
                CTClientData cldata = sh.getClientDataArray(0);
                if (cldata.getObjectType() == STObjectType.NOTE) {
                    int crow = cldata.getRowArray(0).intValue();
                    int ccol = cldata.getColumnArray(0).intValue();
                    if (crow == row && ccol == col) {
                        return sh;
                    }
                }
            }
        }
    }
    return null;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTShape(com.microsoft.schemas.vml.CTShape) CTClientData(com.microsoft.schemas.office.excel.CTClientData)

Example 3 with CTClientData

use of com.microsoft.schemas.office.excel.CTClientData in project poi by apache.

the class XSSFVMLDrawing method newCommentShape.

protected CTShape newCommentShape() {
    CTShape shape = CTShape.Factory.newInstance();
    shape.setId("_x0000_s" + (++_shapeId));
    shape.setType("#" + _shapeTypeId);
    shape.setStyle("position:absolute; visibility:hidden");
    shape.setFillcolor("#ffffe1");
    shape.setInsetmode(STInsetMode.AUTO);
    shape.addNewFill().setColor("#ffffe1");
    CTShadow shadow = shape.addNewShadow();
    shadow.setOn(STTrueFalse.T);
    shadow.setColor("black");
    shadow.setObscured(STTrueFalse.T);
    shape.addNewPath().setConnecttype(STConnectType.NONE);
    shape.addNewTextbox().setStyle("mso-direction-alt:auto");
    CTClientData cldata = shape.addNewClientData();
    cldata.setObjectType(STObjectType.NOTE);
    cldata.addNewMoveWithCells();
    cldata.addNewSizeWithCells();
    cldata.addNewAnchor().setStringValue("1, 15, 0, 2, 3, 15, 3, 16");
    cldata.addNewAutoFill().setStringValue("False");
    cldata.addNewRow().setBigIntegerValue(new BigInteger("0"));
    cldata.addNewColumn().setBigIntegerValue(new BigInteger("0"));
    _items.add(shape);
    _qnames.add(QNAME_SHAPE);
    return shape;
}
Also used : CTShadow(com.microsoft.schemas.vml.CTShadow) BigInteger(java.math.BigInteger) CTShape(com.microsoft.schemas.vml.CTShape) CTClientData(com.microsoft.schemas.office.excel.CTClientData)

Example 4 with CTClientData

use of com.microsoft.schemas.office.excel.CTClientData in project poi by apache.

the class TestXSSFVMLDrawing method testNew.

@Test
public void testNew() throws IOException, XmlException {
    XSSFVMLDrawing vml = new XSSFVMLDrawing();
    List<XmlObject> items = vml.getItems();
    assertEquals(2, items.size());
    assertTrue(items.get(0) instanceof CTShapeLayout);
    CTShapeLayout layout = (CTShapeLayout) items.get(0);
    assertEquals(STExt.EDIT, layout.getExt());
    assertEquals(STExt.EDIT, layout.getIdmap().getExt());
    assertEquals("1", layout.getIdmap().getData());
    assertTrue(items.get(1) instanceof CTShapetype);
    CTShapetype type = (CTShapetype) items.get(1);
    assertEquals("21600,21600", type.getCoordsize());
    assertEquals(202.0f, type.getSpt(), 0);
    assertEquals("m,l,21600r21600,l21600,xe", type.getPath2());
    assertEquals("_x0000_t202", type.getId());
    assertEquals(STTrueFalse.T, type.getPathArray(0).getGradientshapeok());
    assertEquals(STConnectType.RECT, type.getPathArray(0).getConnecttype());
    CTShape shape = vml.newCommentShape();
    assertEquals(3, items.size());
    assertSame(items.get(2), shape);
    assertEquals("#_x0000_t202", shape.getType());
    assertEquals("position:absolute; visibility:hidden", shape.getStyle());
    assertEquals("#ffffe1", shape.getFillcolor());
    assertEquals(STInsetMode.AUTO, shape.getInsetmode());
    assertEquals("#ffffe1", shape.getFillArray(0).getColor());
    CTShadow shadow = shape.getShadowArray(0);
    assertEquals(STTrueFalse.T, shadow.getOn());
    assertEquals("black", shadow.getColor());
    assertEquals(STTrueFalse.T, shadow.getObscured());
    assertEquals(STConnectType.NONE, shape.getPathArray(0).getConnecttype());
    assertEquals("mso-direction-alt:auto", shape.getTextboxArray(0).getStyle());
    CTClientData cldata = shape.getClientDataArray(0);
    assertEquals(STObjectType.NOTE, cldata.getObjectType());
    assertEquals(1, cldata.sizeOfMoveWithCellsArray());
    assertEquals(1, cldata.sizeOfSizeWithCellsArray());
    assertEquals("1, 15, 0, 2, 3, 15, 3, 16", cldata.getAnchorArray(0));
    assertEquals("False", cldata.getAutoFillArray(0).toString());
    assertEquals(0, cldata.getRowArray(0).intValue());
    assertEquals(0, cldata.getColumnArray(0).intValue());
    assertEquals("[]", cldata.getVisibleList().toString());
    cldata.setVisibleArray(new STTrueFalseBlank.Enum[] { STTrueFalseBlank.Enum.forString("True") });
    assertEquals("[True]", cldata.getVisibleList().toString());
    //serialize and read again
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    vml.write(out);
    XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
    vml2.read(new ByteArrayInputStream(out.toByteArray()));
    List<XmlObject> items2 = vml2.getItems();
    assertEquals(3, items2.size());
    assertTrue(items2.get(0) instanceof CTShapeLayout);
    assertTrue(items2.get(1) instanceof CTShapetype);
    assertTrue(items2.get(2) instanceof CTShape);
}
Also used : STTrueFalseBlank(com.microsoft.schemas.office.excel.STTrueFalseBlank) CTShadow(com.microsoft.schemas.vml.CTShadow) CTShapetype(com.microsoft.schemas.vml.CTShapetype) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(com.microsoft.schemas.vml.CTShape) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CTShapeLayout(com.microsoft.schemas.office.office.CTShapeLayout) CTClientData(com.microsoft.schemas.office.excel.CTClientData) Test(org.junit.Test)

Aggregations

CTClientData (com.microsoft.schemas.office.excel.CTClientData)4 CTShape (com.microsoft.schemas.vml.CTShape)3 CTShadow (com.microsoft.schemas.vml.CTShadow)2 BigInteger (java.math.BigInteger)2 XmlObject (org.apache.xmlbeans.XmlObject)2 STTrueFalseBlank (com.microsoft.schemas.office.excel.STTrueFalseBlank)1 CTShapeLayout (com.microsoft.schemas.office.office.CTShapeLayout)1 CTShapetype (com.microsoft.schemas.vml.CTShapetype)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CellAddress (org.apache.poi.ss.util.CellAddress)1 Test (org.junit.Test)1