You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by allelopath <al...@hotmail.com> on 2010/07/18 23:03:54 UTC

Implement cell forumula border feature

Excel has a feature in which when you dbl-clk on a cell with a formula, the
cells referred to by that formula become correspondingly colored. E.g. if
the cell formula is =B2+C3, when you dbl-clk the "B2" in the formula is blue
and the border of B2 is blue and the "C3" in the formula is green and the
border of C3 is green. Demonstrated here:
http://spreadsheets.about.com/od/excelformulas/qt/show_formulas.htm

I need to implement this in Java with POI.

Is this already implemented?
If not, can you suggest how to go about this, e.g. what POI classes and
methods I should be using?

Thanks

-- 
View this message in context: http://old.nabble.com/Implement-cell-forumula-border-feature-tp29199590p29199590.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: Re: Implement cell forumula border feature

Posted by 史虎杰 <sh...@gbicc.net>.
user,你好
i have tried the example you give,But appear the same error ,when i create the word 2007 by using the POI 3.7 version .
this is the error picture :  

p.s: the picture say that ,can not open the Offie Open XML file of simple.docx,because the content have mistakes.
    details:
          text/xml Statement can only appear in the beginning of the input.
         position: part: /word/footer1.xml,row:2,column:310

I use the following code modify with the code that you gived:


 try {
   // Open a document
   XWPFDocument sampleDoc = new XWPFDocument(new FileInputStream(
     new File("E:\\SampleDoc.docx")));
   // Obtain the XWPFHeaderFooterPolicy object
   XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
   // Next create the Paragraphs that are to be added into the header or
   // footer. It is possible to add more that one run - the CTR object
   // to each Paragraph.
   CTP ctP1 = CTP.Factory.newInstance();
   CTR ctR1 = ctP1.addNewR();
   CTText t = ctR1.addNewT();
   t.setStringValue("First Paragraph in footer.");
   // Create the second paragraph
   CTP ctP2 = CTP.Factory.newInstance();
   CTR ctR2 = ctP2.addNewR();
   CTText t2 = ctR2.addNewT();
   t2.setStringValue("Second paragraph for the footer");
   // And the third.
   CTP ctP3 = CTP.Factory.newInstance();
   CTR ctR3 = ctP3.addNewR();
   CTText t3 = ctR3.addNewT();
   t3.setStringValue("Third paragraph for the footer");
   XWPFParagraph p1 = new XWPFParagraph(ctP1);
   XWPFParagraph p2 = new XWPFParagraph(ctP2);
   XWPFParagraph p3 = new XWPFParagraph(ctP3);
   XWPFParagraph[] pars = new XWPFParagraph[3];
   pars[0] = p1;
   pars[1] = p2;
   pars[2] = p3;
   // Now, create the default footer for the document and add the
   // Paragraphs just created to it.
   XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars);
   //write doc to the fileoutputstream
   FileOutputStream out = new FileOutputStream("e:\\simple.docx");
   sampleDoc.write(out);
   out.close();
  } catch (Exception e) {
   e.printStackTrace();
  } 



史虎杰,shihujie@gbicc.net
2010-07-20 
----- Original Message ----- 
From: Nick Burch 
To: POI Users List 
Sent: 2010-07-19, 19:18:38
Subject: Re: Implement cell forumula border feature


On Sun, 18 Jul 2010, allelopath wrote:
> Excel has a feature in which when you dbl-clk on a cell with a formula, 
> the cells referred to by that formula become correspondingly colored.
>
> I need to implement this in Java with POI.

The formula parser is where you'll want to be looking. You probably want 
to look at the reference based Ptgs in the formula (generating the ptgs 
from the text for xssf), then ask the reference ptgs nicely for the cells 
they reference

Nick

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

Re: Re: Implement cell forumula border feature

Posted by 史虎杰 <sh...@gbicc.net>.
user,你好
i have tried the example you give,But appear the same error ,when i create the word 2007 by using the POI 3.7 version .
this is the error picture :  

p.s: the picture say that ,can not open the Offie Open XML file of simple.docx,because the content have mistakes.
    details:
          text/xml Statement can only appear in the beginning of the input.
         position: part: /word/footer1.xml,row:2,column:310

I use the following code modify with the code that you gived:


 try {
   // Open a document
   XWPFDocument sampleDoc = new XWPFDocument(new FileInputStream(
     new File("E:\\SampleDoc.docx")));
   // Obtain the XWPFHeaderFooterPolicy object
   XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
   // Next create the Paragraphs that are to be added into the header or
   // footer. It is possible to add more that one run - the CTR object
   // to each Paragraph.
   CTP ctP1 = CTP.Factory.newInstance();
   CTR ctR1 = ctP1.addNewR();
   CTText t = ctR1.addNewT();
   t.setStringValue("First Paragraph in footer.");
   // Create the second paragraph
   CTP ctP2 = CTP.Factory.newInstance();
   CTR ctR2 = ctP2.addNewR();
   CTText t2 = ctR2.addNewT();
   t2.setStringValue("Second paragraph for the footer");
   // And the third.
   CTP ctP3 = CTP.Factory.newInstance();
   CTR ctR3 = ctP3.addNewR();
   CTText t3 = ctR3.addNewT();
   t3.setStringValue("Third paragraph for the footer");
   XWPFParagraph p1 = new XWPFParagraph(ctP1);
   XWPFParagraph p2 = new XWPFParagraph(ctP2);
   XWPFParagraph p3 = new XWPFParagraph(ctP3);
   XWPFParagraph[] pars = new XWPFParagraph[3];
   pars[0] = p1;
   pars[1] = p2;
   pars[2] = p3;
   // Now, create the default footer for the document and add the
   // Paragraphs just created to it.
   XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars);
   //write doc to the fileoutputstream
   FileOutputStream out = new FileOutputStream("e:\\simple.docx");
   sampleDoc.write(out);
   out.close();
  } catch (Exception e) {
   e.printStackTrace();
  } 



史虎杰,shihujie@gbicc.net
2010-07-20 
----- Original Message ----- 
From: Nick Burch 
To: POI Users List 
Sent: 2010-07-19, 19:18:38
Subject: Re: Implement cell forumula border feature


On Sun, 18 Jul 2010, allelopath wrote:
> Excel has a feature in which when you dbl-clk on a cell with a formula, 
> the cells referred to by that formula become correspondingly colored.
>
> I need to implement this in Java with POI.

The formula parser is where you'll want to be looking. You probably want 
to look at the reference based Ptgs in the formula (generating the ptgs 
from the text for xssf), then ask the reference ptgs nicely for the cells 
they reference

Nick

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

Re: Implement cell forumula border feature

Posted by Nick Burch <ni...@alfresco.com>.
On Sun, 18 Jul 2010, allelopath wrote:
> Excel has a feature in which when you dbl-clk on a cell with a formula, 
> the cells referred to by that formula become correspondingly colored.
>
> I need to implement this in Java with POI.

The formula parser is where you'll want to be looking. You probably want 
to look at the reference based Ptgs in the formula (generating the ptgs 
from the text for xssf), then ask the reference ptgs nicely for the cells 
they reference

Nick

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