You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Natesh Babu Lakshmanan <ln...@yahoo.com> on 2003/04/30 01:21:01 UTC

Giving excel imports in Tapestry

As part of giving excel import feature, I need to set
the following values so that when user clicks a link,
the results will be displayed in an excel sheet. This
is normally achieved by setting the following values:

response.setContentType("application/vnd.ms-excel");
	response.setHeader("Content-disposition","inline;
filename=" + "results.xls" ); 


Can anyone tell me how I can achieve this in Tapestry?

Thanks for all the help,
Natesh



__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

RE: Giving excel imports in Tapestry

Posted by tsvetelin <ts...@rushmore-digital.com>.
Hi Natesh,
We have implemented the same functionality but in a CSV format.

>response.setContentType("application/vnd.ms-excel");
You should implement a specific IMarkupWriter - CExcelMarkupWriter.java
which extends AbstractMarkupWriter and pass to him a specific content-type.
In the page where you want to send a excel file, you should to implements a
method :
	/**
     * @see net.sf.tapestry.html.BasePage#getResponseWriter(OutputStream)
     */
    public IMarkupWriter getResponseWriter(OutputStream outs) {
        return new CExcelMarkupWriter(outs);
    }
You can see AbstractEngine.renderResponse(IRequestCycle cycle,
ResponseOutputStream output) to see some of the background details of
response generating.

>response.setHeader("Content-disposition","inline;
>filename=" + "results.xls" );
I don't know where is a approproate place to set this header. May be it can
be in Page.renderComponent(IMarkupWriter writer, IRequestCycle cycle).

Test Page( you can pass a exel file name as a parameter to page if you have
more than one:
public class ExcelPage extends BasePage {

	/**
     * @see net.sf.tapestry.html.BasePage#getResponseWriter(OutputStream)
     */
    public IMarkupWriter getResponseWriter(OutputStream outs) {
        return new CExcelMarkupWriter(outs);
    }

    /**
	 * @see net.sf.tapestry.BaseComponent#renderComponent(IMarkupWriter,
IRequestCycle)
	 */
	protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
		throws RequestCycleException
	{
		super.renderComponent(writer, cycle);
		cycle.getRequestContext().getResponse().setHeader("Content-disposition",
"inline;filename=" + "/templates/template.xls");
	}

}

public class CExcelMarkupWriter extends AbstractMarkupWriter {

    private static final String[] entities = new String[64];
    private static final boolean[] safe = new boolean[128];

    private static final String SAFE_CHARACTERS =
        "01234567890"
            + "abcdefghijklmnopqrstuvwxyz"
            + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            + "\t\n\r !\"#$%'()*+,-./:;=?@[\\]^_`{|}~";

    static {
        int length = SAFE_CHARACTERS.length();
        for (int i = 0; i < length; i++)
            safe[SAFE_CHARACTERS.charAt(i)] = true;
    }

	public CExcelMarkupWriter(OutputStream objOuts)
	{
		super(safe, entities, "application/vnd.ms-excel", objOuts);
	}

    /**
     * @see net.sf.tapestry.IMarkupWriter#getNestedWriter()
     */
    public IMarkupWriter getNestedWriter() {
        return null;
    }

}



best regards
Tsvetelin Saykov
-----Original Message-----
From: Natesh Babu Lakshmanan [mailto:lnbabu@yahoo.com]
Sent: Wednesday, April 30, 2003 2:21 AM
To: tapestry-user@jakarta.apache.org
Subject: Giving excel imports in Tapestry



As part of giving excel import feature, I need to set
the following values so that when user clicks a link,
the results will be displayed in an excel sheet. This
is normally achieved by setting the following values:

response.setContentType("application/vnd.ms-excel");
	response.setHeader("Content-disposition","inline;
filename=" + "results.xls" );


Can anyone tell me how I can achieve this in Tapestry?

Thanks for all the help,
Natesh



__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

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