Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将GWT CellTable导出到excel_Gwt - Fatal编程技术网

将GWT CellTable导出到excel

将GWT CellTable导出到excel,gwt,Gwt,我使用一个单元格表,我支持客户端的过滤操作。我正在寻找一种直接从gwt客户端下载表格到excel的方法。有没有一个简单的方法可以做到这一点 我找到了。但是我正在寻找一种不使用上述内容的方法。如果要下载Excel文件,必须从服务器编写创建内容。 您必须将筛选操作发送到服务器,以告知hime生成文件 projet gwt表到excell使用了一个来自Excel的黑客,它可以尝试读取html表来构建Excel文件。但这在新版本中可能不起作用。如果要下载Excel文件,必须从服务器写入创建内容。 您必须

我使用一个单元格表,我支持客户端的过滤操作。我正在寻找一种直接从gwt客户端下载表格到excel的方法。有没有一个简单的方法可以做到这一点


我找到了。但是我正在寻找一种不使用上述内容的方法。

如果要下载Excel文件,必须从服务器编写创建内容。 您必须将筛选操作发送到服务器,以告知hime生成文件


projet gwt表到excell使用了一个来自Excel的黑客,它可以尝试读取html表来构建Excel文件。但这在新版本中可能不起作用。

如果要下载Excel文件,必须从服务器写入创建内容。 您必须将筛选操作发送到服务器,以告知hime生成文件


projet gwt表到excell使用了一个来自Excel的黑客,它可以尝试读取html表来构建Excel文件。但这在新版本中可能不起作用。

我使用

我不想回到服务器,因为我拥有客户端上的一切

这样就可以快速下载生成的单元格表


(它不会扩展到某一点,但这对于我的用例来说是可以接受的。下载速度优先。)

我使用

我不想回到服务器,因为我拥有客户端上的一切

这样就可以快速下载生成的单元格表


(它不会扩展到某个特定的点,但这对于我的用例来说是可以接受的。下载速度优先。)

下面的类在没有服务器端的情况下可以做到这一点

public class TableToExcel {
    public static final <T> void save(final CellTable<T> table, String filename) {
        final AnchorElement a = Document.get().createAnchorElement();
        a.setHref("data:application/vnd.ms-excel;base64," + base64(table.getElement().getString()));
        a.setPropertyString("download", (filename.endsWith(".xls") || filename.endsWith(".xlsx")) ? filename : filename + ".xls");

        Document.get().getBody().appendChild(a);
        Scheduler.get().scheduleEntry(new ScheduledCommand() {
            @Override
            public void execute() {
                click(a);
                a.removeFromParent();
            }
        });
    }

    private static native void click(Element elem) /*-{
        elem.click();
    }-*/;

    public static native String base64(String data) /*-{
        return btoa(data);
    }-*/;
}
公共类TableToExcel{
公共静态最终作废保存(最终单元格表,字符串文件名){
final AnchoreElement a=Document.get().CreateAnchoreElement();
a、 setHref(“数据:application/vnd.ms excel;base64,”+base64(table.getElement().getString());
a、 setPropertyString(“下载”;(filename.endsWith(“.xls”)| | filename.endsWith(“.xlsx”))?filename:filename+“.xls”);
Document.get().getBody().appendChild(a);
Scheduler.get().scheduleEntry(新的ScheduledCommand()){
@凌驾
public void execute(){
点击(a);
a、 removeFromParent();
}
});
}
私有静态本机void单击(元素元素元素)/*-{
元素单击();
}-*/;
公共静态本机字符串base64(字符串数据)/*-{
返回btoa(数据);
}-*/;
}

下面的类在没有服务器端的情况下执行此操作

public class TableToExcel {
    public static final <T> void save(final CellTable<T> table, String filename) {
        final AnchorElement a = Document.get().createAnchorElement();
        a.setHref("data:application/vnd.ms-excel;base64," + base64(table.getElement().getString()));
        a.setPropertyString("download", (filename.endsWith(".xls") || filename.endsWith(".xlsx")) ? filename : filename + ".xls");

        Document.get().getBody().appendChild(a);
        Scheduler.get().scheduleEntry(new ScheduledCommand() {
            @Override
            public void execute() {
                click(a);
                a.removeFromParent();
            }
        });
    }

    private static native void click(Element elem) /*-{
        elem.click();
    }-*/;

    public static native String base64(String data) /*-{
        return btoa(data);
    }-*/;
}
公共类TableToExcel{
公共静态最终作废保存(最终单元格表,字符串文件名){
final AnchoreElement a=Document.get().CreateAnchoreElement();
a、 setHref(“数据:application/vnd.ms excel;base64,”+base64(table.getElement().getString());
a、 setPropertyString(“下载”;(filename.endsWith(“.xls”)| | filename.endsWith(“.xlsx”))?filename:filename+“.xls”);
Document.get().getBody().appendChild(a);
Scheduler.get().scheduleEntry(新的ScheduledCommand()){
@凌驾
public void execute(){
点击(a);
a、 removeFromParent();
}
});
}
私有静态本机void单击(元素元素元素)/*-{
元素单击();
}-*/;
公共静态本机字符串base64(字符串数据)/*-{
返回btoa(数据);
}-*/;
}

假设您正在生成2014年1月1日至2014年12月31日的报告 您需要通过客户端将参数传递给服务器,例如:

                String parameters = "mode=" + report  + "&frmDate=" + from + "&toDate="+ upto ;
                String url = URL.encode(GWT.getHostPageBaseURL() + "something/something?" + parameters);
                // window for download process Excel shown to user
                String features = "menubar=no,location=no,status=no,width=200,height=100,toolbar=no,scrollbars=no,resizable=no";
                //pass the feature parameter to Window.open...
                // since GWT has provided this method -        public static native void open(String url, String name, String features)
                com.google.gwt.user.client.Window.open(url, "_blank", features); 

假设您正在生成2014年1月1日至2014年12月31日的报告 您需要通过客户端将参数传递给服务器,例如:

                String parameters = "mode=" + report  + "&frmDate=" + from + "&toDate="+ upto ;
                String url = URL.encode(GWT.getHostPageBaseURL() + "something/something?" + parameters);
                // window for download process Excel shown to user
                String features = "menubar=no,location=no,status=no,width=200,height=100,toolbar=no,scrollbars=no,resizable=no";
                //pass the feature parameter to Window.open...
                // since GWT has provided this method -        public static native void open(String url, String name, String features)
                com.google.gwt.user.client.Window.open(url, "_blank", features);