0

how to set the src for spreadsheet from java class [closed]

asked 2013-06-05 01:03:10 +0800

phasthal gravatar image phasthal
5 3

updated 2013-06-11 06:31:28 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I have tried setting the src using Spreadsheet.setSrc() from java class as below: but its not loading in UI (its a blank page).

private void importSpreadsheet(){
    String fileName="C:\\zk\\zss\\sample.xlsx";
    Spreadsheet spreadsheet = new Spreadsheet();
    Importer imp =Importers.getImporter("excel");
    Book b = imp.imports(fileName);
    spreadsheet.setBook(b);
    spreadsheet.setMaxcolumns(100);
    spreadsheet.setMaxrows(1000);
    spreadsheet.setWidth("500px");
    spreadsheet.setHeight("700px");

            //spreadsheet.setSrc(b.getBookName())

}

and my zul file is

<window width="100" height="100%" apply="org.zkoss.ExportToExcelComposer">
    <hbox> <button id="exportBtn" label="Export to Excel"></button>
    </hbox>
    <spreadsheet id="spreadsheet" showSheetbar="true"
        maxrows="200" maxcolumns="40" vflex="1" width="100%">
    </spreadsheet>
</window>
delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by sjoshi
close date 2013-07-18 05:29:21

Comments

Thanks Zknl, its working.

phasthal ( 2013-07-17 19:07:21 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2013-06-08 07:55:58 +0800

zknl gravatar image zknl
124 2

updated 2013-06-11 06:31:53 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

hey if you are using <spreadsheet/> component itself in zul then u can just give path of ur spreadsheet to the 'src' attribute as like <spreadsheet src="/WEB-INF/test.xls" width="100%" height="556px" id="test" > </spreadsheet>

or u can do like follows:

                Spreadsheet spreadsheet = new Spreadsheet();
                spreadsheet.setMaxcolumns(100);
                spreadsheet.setMaxrows(1000);
                spreadsheet.setWidth("500px");
                spreadsheet.setHeight("700px");

                spreadsheet.setSrc(Sessions.getCurrent().getWebApp().getRealPath(fileName));
                UR_WIDNOW_ID.appendChild(spreadsheet);

OR

                 String fileName="C:\\zk\\zss\\sample.xlsx";
                 Spreadsheet spreadsheet = new Spreadsheet();
                 Importer imp =Importers.getImporter("excel");
                 Book b =imp.imports(Sessions.getCurrent().getWebApp().getRealPath(fileName));
                spreadsheet.setBook(b);
                 spreadsheet.setMaxcolumns(100);
               spreadsheet.setMaxrows(1000);
                 spreadsheet.setWidth("500px");
               spreadsheet.setHeight("700px");


                 UR_WINDOW_ID.appendChild(spreadsheet);
link publish delete flag offensive edit
1

answered 2013-06-11 11:49:34 +0800

zknl gravatar image zknl
124 2

updated 2013-06-11 12:33:51 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

hi phanstahl, as i mentioned in above ans , both options worked well for me

see this is my zul:

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal" onCreate="createSpreadsheet()" id="wnd_new">

<zscript>
    <![CDATA[

            void createSpreadsheet()
            {
                String fileName="/WEB-INF/new.xls";
                    Spreadsheet spreadsheet = new Spreadsheet();
                Importer imp =Importers.getImporter("excel");
                spreadsheet.setMaxcolumns(100);
                spreadsheet.setMaxrows(1000);
                spreadsheet.setWidth("500px");
                spreadsheet.setHeight("700px");

          spreadsheet.setSrc(Sessions.getCurrent().getWebApp().getRealPath(fileName));
                 wnd_new.appendChild(spreadsheet);
            }
    ]]>
</zscript>
</window>
</zk>
link publish delete flag offensive edit
0

answered 2013-06-10 21:04:33 +0800

phasthal gravatar image phasthal
5 3

Thanks zknl for the response.

I would like to set the src from java class only, So tried 2nd and 3rd optons as you mentioned, but it didn't show up in the UI.

Actually, the path it returns for this Sessions.getCurrent().getWebApp().getRealPath() is workspace path and then appending the filename path to it and it could not locate the file. like this below: C:\workspace\ZK.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyZSS\C:\zk\zss\sample.xlsx

and the main problem looks like, it could not append to the window and it shows blank window.

link publish delete flag offensive edit

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-06-05 01:03:10 +0800

Seen: 33 times

Last updated: Jul 17 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More