I welcome!
There is in API of Vaadin (or relevant add-ons) ways to export in MS Excell (…pdf, … or other) tables, for example, as shown in the figure below -
I welcome!
There is in API of Vaadin (or relevant add-ons) ways to export in MS Excell (…pdf, … or other) tables, for example, as shown in the figure below -
Or have to use JasperReports/ DynamicJasper, Apache POI and other?
I welcome you, Alexander V Pchelintsev!, I welcome you, Philippe Lhoste!
Whew! That’s it! Thank you very much! Sasha, Philippe- for your health!
Excellent add- on! Eliminating the routine, typical Apache Poi.
Faced with this problem, if my table is defined as -
...
final Table t = outerSystemQuery.executeQuery();
t.setSizeFull();
t.setStyleName("iso3166");
t.setSelectable(true);
t.setImmediate(true);
t.setColumnReorderingAllowed(true);
t.setColumnCollapsingAllowed(true);
t.setColumnHeaderMode(Table.ROW_HEADER_MODE_INDEX);
...
And the listener -
...
Button excelBtn = new Button("MS Excel");
excelBtn.setIcon(new ThemeResource(EXCELBTN));
excelBtn.addListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
ExcelExport excelExport = new ExcelExport(t);
excelExport.excludeCollapsedColumns();
excelExport.setDisplayTotals(false);
excelExport.setRowHeaders(true);
CellStyle cs = excelExport.getTitleStyle();
cs.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
excelExport.setTitleStyle(cs);
excelExport.setDoubleDataFormat("0.00");
excelExport.setExcelFormatOfProperty("konto", "0");
excelExport.export();
}
});
...
I get a stack of exceptions -
[color=#f60101]
SEVERE: Terminal error:
com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.NoSuchMethodError: com.vaadin.ui.Table.getColumnGenerator(Ljava/lang/Object;)Lcom/vaadin/ui/Table$ColumnGenerator;
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:162)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1166)
at com.vaadin.ui.Button.fireClick(Button.java:380)
at com.vaadin.ui.Button.changeVariables(Button.java:196)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1297)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1217)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:733)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:483)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodError: com.vaadin.ui.Table.getColumnGenerator(Ljava/lang/Object;)Lcom/vaadin/ui/Table$ColumnGenerator;
at com.vaadin.addon.tableexport.ExcelExport.getProperty(ExcelExport.java:527)
at com.vaadin.addon.tableexport.ExcelExport.addDataRow(ExcelExport.java:493)
at com.vaadin.addon.tableexport.ExcelExport.addDataRows(ExcelExport.java:438)
at com.vaadin.addon.tableexport.ExcelExport.convertTable(ExcelExport.java:243)
at com.vaadin.addon.tableexport.TableExport.export(TableExport.java:38)
at com.intellex.marksist.dashboard.windows.ResultCodeQueryWin$3.buttonClick(ResultCodeQueryWin.java:200)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)
… 26 more
[/color]
In what may be the reason? I would be very grateful for your help!
Under the debugger, find the line on which an exception -
ExcelExport.class -
...
public void export() {
[b]
convertTable();
[/b]
sendConverted();
}
/**
* Creates the workbook containing the exported table data, without exporting it to the user.
*/
@Override
public void convertTable() {
final int startRow;
// initial setup
initialSheetSetup();
// add title row
startRow = addTitleRow();
int row = startRow;
// add header row
addHeaderRow(row);
row++;
// add data rows
if (hierarchical) {
row = addHierarchicalDataRows(sheet, row);
} else {
[color=#f70808]
[b]
row = addDataRows(sheet, row);
[/b]
[/color]
}
...
And then -
...
/**
* this method adds row items for non-HierarchicalContainers. Override this method to make any
* changes. To change the CellStyle used for all Table data use setDataStyle(). For different
* data cells to have different CellStyles, override getDataStyle().
*
* @param row
* the row
*
* @return the int
*/
protected int addDataRows(final Sheet sheetToAddTo, final int row) {
final Collection<?> itemIds = container.getItemIds();
int localRow = row;
int count = 0;
for (final Object itemId : itemIds) {
[color=#fa0d0d]
[b]
addDataRow(sheetToAddTo, itemId, localRow);
[/b]
[/color]
count = 1;
if (count > 1) {
...
Although the instruction work out well -
...
final Collection<?> itemIds = container.getItemIds();
...
…and i can see the number of entries in the table.
Does anyone know what causes this behavior?
And then -
...
/**
* This method is ultimately used by either addDataRows() or addHierarchicalDataRows() to
* actually add the data to the Sheet.
*
* @param rootItemId
* the root item id
* @param row
* the row
*/
protected void addDataRow(final Sheet sheetToAddTo, final Object rootItemId, final int row) {
final Row sheetRow = sheetToAddTo.createRow(row);
Property prop;
Object propId;
Object value;
Cell sheetCell;
for (int col = 0; col < propIds.size(); col++) {
propId = propIds.get(col);
[color=#ee0606]
prop = getProperty(rootItemId, propId);
[/color]
...
propId
in my case == “OWNER_TYPE”
Does anyone know?
The
executeQuery
method as follows -
...
public Table executeQuery() {
String sql = getQuery();
HashMap hashConnect = markXMLParser.getConnectParam();
StringParser stringParser = new StringParser();
String login = hashConnect.get("login").toString();
String password = hashConnect.get("password").toString();
String connStr = hashConnect.get("connStr").toString();
SimpleJDBCConnectionPool connPool = null;
try {
connPool = new SimpleJDBCConnectionPool("oracle.jdbc.OracleDriver",
connStr, login, password, 2, 5);
} catch(SQLException e1) {
e1.printStackTrace();
}
FreeformQuery query = null;
String s = stringParser.getIdField(sql);
query = new FreeformQuery(sql, connPool);
SQLContainer container = null;
try {
container = new SQLContainer(query);
}
catch (SQLException e) {
e.printStackTrace();
}
final Table t = new Table(null, container);
t.setSelectable(true);
t.setImmediate(true);
t.setWidth("300px");
return t;
}
...
Are you using an old version of Vaadin? I see getColumnGenerator is absent of 6.5 sources of Table, while I find it in v.6.6.
I welcome you, Philippe Lhoste!
Yes, you’re absolutely right! I updated the library to Vaadin 6.6.6 and exports works fine!
Thank you very much!
I am glad it was that simple…
Too bad that the @since tag is sometime forgotten in the JavaDoc, it is a useful information.
Yes, it’s really easy! The author wrote TableExport add- on, and I forgot about the difficulties with Apache POI:D On the tag I have not looked, sorry :glare:.
Thanks to author!
Thank you so much!
Cheers, Philippe Lhoste!