From my interpretation, all Andy wants to do is use the template, set some values and write the workbook. Siddharth outlined the approach to do so, you do not need to call clone unless you want to duplicate things in the current workbook (ie. copy a sheet).

Sharma, Siddharth wrote:
That is similar to what I am doing.
Only difference is my workbook has only one sheet.

You can still use the mechanism that I have outlined (or something similar)
to achieve what you are trying to do. Unless, of course, I have not understood your problem.



-----Original Message-----
From: Andy Pahne [mailto:[EMAIL PROTECTED] Sent: Monday, November 29, 2004 12:32 PM
To: POI Users List
Subject: Re: excel and diagrams again





Thanks for that one, it might be useful sometimes.

Unfortunatly I was a bit unnclear in my first mail. I wasn't trying to clone a whole workbook, but only one sheet in an existing template file. I need to clone it, because it contains a diagram that I can't create using POI. And after cloning this sheet I want to set a few values in the new sheet, that directly affect the diagram.

Andy




Sharma, Siddharth wrote:

You cannot clone a template xls file by invoking the clone() method.
I tried the same first but later realized that it has not been overridden.

This is what I have done to 'clone'.

1. Create a static variable of type POIFSFileSystem (say poifs).


2. Load the template and cache it as a POIFSFileSystem (in a static block

or

in a singleton (or however) to load it once and once only)
   is=

this.getClass().getClassLoader().getResourceAsStream(nameTemplate);

this.setCachedTemplate(new POIFSFileSystem(is));

// setCachedTemplate initializes the class variable (poifs) of type // POIFSFileSystem.


3. Create a 'clone' whenever needed return new HSSFWorkbook(Myclass.poifs, true));






-----Original Message-----
From: Andy Pahne [mailto:[EMAIL PROTECTED] Sent: Friday, November 26, 2004 9:12 AM
To: [EMAIL PROTECTED]
Subject: excel and diagrams again



hello,

after some resarch and some help by this mailing list I found out that it is currently not suppported to create diagrams in Excel files with POI.

Then I tried to create a "template Excel" workbook that contains a sample sheet with just enough dummy data to generate the diagram (and the diagram, of course). I thought that was a clever idea, but obviously I was wrong.

Has anybody tried the same and was more succesfull?

I have no idea how to implement this missing clone() method. Has anybody?

Bye,
Andy



I read in my template.xls like this:


______________________________________________________________________

// read in the workbook with the template worksheet
// create a POIFSFileSystem object to read the data
POIFSFileSystem fs = new POIFSFileSystem(
    new FileInputStream( configurationService.getXLSTemplateFile()));

// create a bew workbook based on the POIFSFileSystem object
HSSFWorkbook workbook = new HSSFWorkbook(fs);

______________________________________________________________________


No problem so far. But when I try to clone my template sheet like this:

______________________________________________________________________

HSSFSheet anotherSheet = workbook.cloneSheet(0);
______________________________________________________________________


I get A RuntimeException "The class org.apache.poi.hssf.record.DrawingRecord needs to define a clone method"


With the stack trace:
Stack Trace:

* org.apache.poi.hssf.record.Record.clone(Record.java:194)
* org.apache.poi.hssf.model.Sheet.cloneSheet(Sheet.java:320)
* org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet(HSSFSheet.java:114)
*



org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:337)

* itoskop.web.ExcelReportService.service(ExcelReportService.java:220)
* org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:872)
*



org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197

)
* org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:158)
* javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
* javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
*



org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application

FilterChain.java:237)
*



org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh

ain.java:157)
*



org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja

va:214)
*



org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)
*



org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

*


org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContext

Valve.java:198)
*



org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja

va:152)
*



org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)
*



org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

*


org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137

)
*



org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)
*



org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118

)
*



org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:102)
*



org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

*


org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java

:109)
*



org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)
*



org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

*

org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

* org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
* org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
*



org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne

ction(Http11Protocol.java:705)
* org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
*



org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav

a:683)
    * java.lang.Thread.run(Thread.java:534)




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to