Page 1 of 1

Shape changes for rot > "18900000"

PostPosted: Fri Dec 13, 2019 5:00 pm
by ashanaik
AddImageXlsx4j_9.xlsx
File_45
(73.57 KiB) Downloaded 6 times
AddImageXlsx4j_9.xlsx
File_45
(73.57 KiB) Downloaded 6 times
Hi

When i set <a:xfrm rot="18900000"> (45 /315 degree) the image is tilted properly.
When i am changing the angle to 46/314 degree the image gets titled properly but the height and width gets interchanged.

For 0-45 and 150-180 degree the image transform works fine, not for other angles.

Is there a problem with my code or its a XLSX4J bug ??


Code :

package com;

import java.io.File;

import javax.xml.bind.JAXBException;

import org.apache.commons.io.FileUtils;
import org.docx4j.XmlUtils;
import org.docx4j.dml.CTBlip;
import org.docx4j.dml.CTBlipFillProperties;
import org.docx4j.dml.CTGeomGuideList;
import org.docx4j.dml.CTNonVisualDrawingProps;
import org.docx4j.dml.CTNonVisualPictureProperties;
import org.docx4j.dml.CTOfficeArtExtension;
import org.docx4j.dml.CTOfficeArtExtensionList;
import org.docx4j.dml.CTPictureLocking;
import org.docx4j.dml.CTPoint2D;
import org.docx4j.dml.CTPositiveSize2D;
import org.docx4j.dml.CTPresetGeometry2D;
import org.docx4j.dml.CTRelativeRect;
import org.docx4j.dml.CTShapeProperties;
import org.docx4j.dml.CTStretchInfoProperties;
import org.docx4j.dml.CTTransform2D;
import org.docx4j.dml.chartDrawing.CTPicture;
import org.docx4j.dml.spreadsheetdrawing.CTAnchorClientData;
import org.docx4j.dml.spreadsheetdrawing.CTMarker;
import org.docx4j.dml.spreadsheetdrawing.CTPictureNonVisual;
import org.docx4j.dml.spreadsheetdrawing.CTTwoCellAnchor;
import org.docx4j.openpackaging.io.SaveToZipFile;
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage;
import org.docx4j.openpackaging.parts.PartName;
import org.docx4j.openpackaging.parts.DrawingML.Drawing;
import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart;
import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
import org.docx4j.relationships.Relationship;
import org.xlsx4j.sml.CTDrawing;

public class ImageTest {


public static void main(String[] args) throws Exception {

String outputfilepath = "D:\\AddImageXlsx4j_10.xlsx";
String imagefilePath = "D:\\Checkout_Refactoring\\Images\\apricot_weiss.png";

SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
WorksheetPart worksheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);

Drawing drawingPart = new Drawing();
Relationship drawingRel = worksheet.addTargetPart(drawingPart);

org.xlsx4j.sml.CTDrawing drawing = org.xlsx4j.jaxb.Context.getsmlObjectFactory().createCTDrawing();
worksheet.getJaxbElement().setDrawing(drawing);
drawing.setId(drawingRel.getId());

BinaryPartAbstractImage imagePart =
BinaryPartAbstractImage.createImagePart(pkg, drawingPart, FileUtils.readFileToByteArray(new File(imagefilePath)));
String imageRelID = imagePart.getSourceRelationship().getId();

drawingPart.setJaxbElement(buildDrawingPartContentFromXmlString(imageRelID));

SaveToZipFile saver = new SaveToZipFile(pkg);
saver.save(outputfilepath);
System.out.println("\n\n done .. " + outputfilepath);
}

public static org.docx4j.dml.spreadsheetdrawing.CTDrawing buildDrawingPartContentFromXmlString(String imageRelID) throws JAXBException {

String openXML = "<xdr:wsDr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
+ "<xdr:twoCellAnchor editAs=\"oneCell\">"
+ "<xdr:from>"
+ "<xdr:col>3</xdr:col>"
+ "<xdr:colOff>0</xdr:colOff>"
+ "<xdr:row>3</xdr:row>"
+ "<xdr:rowOff>0</xdr:rowOff>"
+"</xdr:from>"
+ "<xdr:to>"
+ "<xdr:col>5</xdr:col>"
+ "<xdr:colOff>104775</xdr:colOff>"
+ "<xdr:row>7</xdr:row>"
+ "<xdr:rowOff>142875</xdr:rowOff>"
+"</xdr:to>"
+ "<xdr:pic>"
+ "<xdr:nvPicPr>"
+ "<xdr:cNvPr id=\"2\" name=\"Picture 1\"/>"
+ "<xdr:cNvPicPr>"
+ "<a:picLocks noChangeAspect=\"1\"/>"
+"</xdr:cNvPicPr>"
+"</xdr:nvPicPr>"
+ "<xdr:blipFill>"
+ "<a:blip r:embed=\"" + imageRelID + "\">"
+ "<a:extLst>"
+ "<a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">"
+ "<a14:useLocalDpi val=\"0\"/>"
+"</a:ext>"
+"</a:extLst>"
+"</a:blip>"
+ "<a:stretch>"
+ "<a:fillRect/>"
+"</a:stretch>"
+"</xdr:blipFill>"
+ "<xdr:spPr>"
+ "<a:xfrm rot=\"18839999\">"
+ "<a:off x=\"0\" y=\"0\"/>"
+ "<a:ext cx=\"714375\" cy=\"714375\"/>"
+"</a:xfrm>"
+ "<a:prstGeom prst=\"rect\">"
+ "<a:avLst/>"
+"</a:prstGeom>"
+"</xdr:spPr>"
+"</xdr:pic>"
+ "<xdr:clientData/>"
+"</xdr:twoCellAnchor>"
+"</xdr:wsDr>";

return (org.docx4j.dml.spreadsheetdrawing.CTDrawing)XmlUtils.unwrap(
XmlUtils.unmarshalString(openXML));
}
}

Re: Shape changes for rot > "18900000"

PostPosted: Sat Dec 14, 2019 6:29 am
by jason
Please unzip your xlsx, then look at the contents of /xl/worksheets/sheet1.xml

If it contains the values you wrote, its not a problem with xlsx4j

Re: Shape changes for rot > "18900000"

PostPosted: Tue Dec 17, 2019 12:18 am
by ashanaik
i get the same value set in rot in xfrm jaxb element in drawing.xml.

But height and width gets interchanged after i increase rotation value more than 18900000.

This behaviour is odd and wrong.