Hi there,
I am downloading Excel File from Vaadin - using a StreamResource - this works fine - but it open a new browser tab.
Is there a possibilty to hva ethe Excel File diplay in a Vaadin Window object - so the user of my application will not have to
leave the appilcation Tab to see read Excel files?
I have wriiten my a small class ExcelViewer which looks lik this:
public class ExcelViewer extends Window {
VerticalLayout theLayout = null;
byte[] byteArrayExcelData = null;
String strArchiveID = null;
public ExcelViewer(byte[] pbyteArrayExcelData, String pstrArchiveID){
byteArrayExcelData = pbyteArrayExcelData;
strArchiveID = pstrArchiveID;
// set the size of the Vaadin Window that should contain the Excel data
this.setResizable(true);
this.setCaption("Excel Viewer");
this.setWidth("800");
this.setHeight("600");
this.center();
showExcelFile(pbyteArrayExcelData);
}
private void showExcelFile(byte[] pbyteExcelData) {
// take care of the excel file
StreamSource s = new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
return new ByteArrayInputStream(byteArrayExcelData);
}
};
StreamResource r = new StreamResource(s, "");
Embedded e = new Embedded();
e.setSizeFull();
e.setType(Embedded.TYPE_BROWSER);
e.setMimeType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
e.setSource(r);
VerticalLayout theLayout = new VerticalLayout();
theLayout.setSizeFull();
theLayout.addComponent(e);
this.setContent(theLayout);
}
I call it like this:
ExcelViewer theExcelViewer = new ExcelViewer(lbytearyFromArchiveIS, strArchiveID);
this.getUI().addWindow(theExcelViewer);
The window opens, but Excel is still downloaded by the Brwoser and then diplay in a new Tab.
Every hint will be appreciated.
Thanx
Peter