You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "stefan.chonov" <s....@arbix.eu> on 2012/10/15 15:45:16 UTC

How to add connector between two shapes in Excel?

Hi!

I would like to add a connector between two shapes. I tried to find an
example in the network but I can't find anything. Can someone give me a
simple example how can I do this? I using Microsoft Excel 2007.

Thank you in advance.

Regards,
Stefan chonov



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi, Yegor

This is my code: 

XSSFWorkbook workbook = new XSSFWorkbook();
		XSSFSheet sheet = workbook.createSheet("Connect two shapes");		
		XSSFDrawing patriarch = (XSSFDrawing) sheet.createDrawingPatriarch();
		
		// Initialize first shape
		XSSFClientAnchor a = new XSSFClientAnchor(152400, 123825, 542925, 57150,
1, 4, 3, 11);
		XSSFSimpleShape clould = patriarch.createSimpleShape(a);	
		clould.setShapeType(ShapeTypes.CLOUD);
		clould.getCTShape().getNvSpPr().getCNvPr().setId(2);
		
		// Initialize second shape
		XSSFClientAnchor a2 = new XSSFClientAnchor(104775, 9525, 190500, 28575, 8,
13, 11, 19);
		XSSFSimpleShape rect = patriarch.createSimpleShape(a2);
		rect.getCTShape().getNvSpPr().getCNvPr().setId(3);
		rect.setShapeType(ShapeTypes.RECT);
				
		// Initialize connector between shapes
		XSSFConnector shape1Connector = patriarch.createConnector(
				new XSSFClientAnchor(541584, 185738, 452438, 9525, 3, 7, 9, 13));

                *// When I set id of the connector everything works
correctly. Here is my problem.
		//shape1Connector.getCTConnector().getNvCxnSpPr().getCNvPr().setId(45);*
		
		CTConnector ctConnector = shape1Connector.getCTConnector();		
	
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.STRAIGHT_CONNECTOR_1);
		
		CTNonVisualConnectorProperties cx =
ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
		CTConnection stCxn = cx.addNewStCxn();		

		stCxn.setId(clould.getCTShape().getNvSpPr().getCNvPr().getId());
		stCxn.setIdx(0);
		
		CTConnection end = cx.addNewEndCxn();
		end.setId(rect.getCTShape().getNvSpPr().getCNvPr().getId());
		end.setIdx(3);
		
		FileOutputStream fileOut;
		try {
			fileOut = new FileOutputStream("xls/XLDrawingShape.xlsx");
			workbook.write(fileOut);	
			fileOut.flush();
			fileOut.close();
		} catch (IOException e) {
			e.printStackTrace();
		} 

I missed explanation about how the code is work. I hope you will understand
it. If you don't, please write me. Thank you in advance.

Regards,
Stefan



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711266.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by Yegor Kozlov <ye...@dinom.ru>.
It's hard to tell what is wrong without looking at your code.
Please post sample Java code and explain in details which ID is wrong.

Yegor

On Tue, Oct 23, 2012 at 11:26 AM, stefan.chonov <s....@arbix.eu> wrote:
> Hi, Yegor
>
> I found out why binding between two shapes does not work properly. The
> example in given link above it's work almost perfect. To make it perfect is
> need to change the *id* of the connector to be different from the other
> shapes. Why Poi gives *id* on the connector when is already given to another
> shape?
>
> Regards,
> Stefan
>
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711259.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi, Yegor

I found out why binding between two shapes does not work properly. The
example in given link above it's work almost perfect. To make it perfect is
need to change the *id* of the connector to be different from the other
shapes. Why Poi gives *id* on the connector when is already given to another
shape? 

Regards,
Stefan




--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711259.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi, 

I noticed there I missed a line from the example. I guess this is the reason
the method setIdx() to not work. The line where I missed is this:

*CTConnector ctConnector = (CTConnector)connector1.getXmlObject();*

Where I can find the getXmlObject() method of the XSSFConnector class?

Thanks in advance

Regards,
Chonov



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711235.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hello, Kozlov,

Thank you for the answer. I'm sorry about my insolence. Almost everything it
work perfect. I have only one last question.  I'll try to explain my problem
with a simple example and some explanation. You can find my source code 
here <http://pastebin.com/WqDJseNB>  . 

Explanation of my problem:
I almost copied the given example from the link which you give me before a
few posts. I configured the example to work for my needs. 

When I set the argument of the setIdx() method to be one the given numbers
(1,2,3 or 4) nothing happen. I tried to change the position of the connector
to be on left (1), bottom (2), right (3) or top (4) but the change isn't
visualize into the excel file. My English isn't very good if you don't
understand something I'll try to explain my issue in more details and more
simplified. 

If you don't have time to help my don't worry. Thank you for the previous
answers they was very good.

Regards,
Stefan Chonov



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711228.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by Yegor Kozlov <ye...@dinom.ru>.
        long shapeId = shape.getCTShape().getNvSpPr().getCNvPr().getId();


On Wed, Oct 17, 2012 at 4:46 PM, stefan.chonov <s....@arbix.eu> wrote:
> Hi
>
> I ran into another problem. Is there any way to take XSSFSimpleShape id? The
> HSLFAutoShape class contains a method called *getShapeId()*. Is there a
> similar method for the class XSSFSimpleShape?
>
> Regards,
> Stefan
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711212.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi

I ran into another problem. Is there any way to take XSSFSimpleShape id? The
HSLFAutoShape class contains a method called *getShapeId()*. Is there a
similar method for the class XSSFSimpleShape?

Regards,
Stefan



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711212.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi, Kozlov!

You are amazing man. Thank you very much for the support.

Best regards,
Stefan Chonov



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711210.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by Yegor Kozlov <ye...@dinom.ru>.
http://poi.apache.org/faq.html#faq-N10025

use the full ooxml-schemas-1.1.jar, you can download it from the
central maven repo:
http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22ooxml-schemas%22

Yegor

On Wed, Oct 17, 2012 at 2:40 PM, stefan.chonov <s....@arbix.eu> wrote:
> Hi, Kozlov!
>
> I'm making research about the information contained in the link from your
> last post. It had relation to my issue. I am sorry about the hasty response.
> Now I have other issue. I can't find the CTConnection class which I noticed
> in the link. Where I can find this class? In the current release of the POI
> v3.8 this class is missing.
>
> Regards,
> Stefan Chonov
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711207.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi, Kozlov!

I'm making research about the information contained in the link from your
last post. It had relation to my issue. I am sorry about the hasty response.
Now I have other issue. I can't find the CTConnection class which I noticed
in the link. Where I can find this class? In the current release of the POI
v3.8 this class is missing.

Regards, 
Stefan Chonov



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711207.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by "stefan.chonov" <s....@arbix.eu>.
Hi!

Thank you for the answer but this example is related with PowerPoint and is
not appropriate for me. I need to connect to shapes in *Microsoft Excel
2007*. 

Regards,
Stefan Chonov



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711198.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: How to add connector between two shapes in Excel?

Posted by Yegor Kozlov <ye...@dinom.ru>.
have a look at this thread: http://markmail.org/message/sy7s463cudtlc7i5

On Mon, Oct 15, 2012 at 5:45 PM, stefan.chonov <s....@arbix.eu> wrote:
> Hi!
>
> I would like to add a connector between two shapes. I tried to find an
> example in the network but I can't find anything. Can someone give me a
> simple example how can I do this? I using Microsoft Excel 2007.
>
> Thank you in advance.
>
> Regards,
> Stefan chonov
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

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