hi, all
My contribution for exporting data from TableView to CSV if it is ok and
useful:)

 void ***::exportTableView(Wt::Ext::TableView *tv, bool includeHidden) {

    Wt::WAbstractItemModel *model = tv->model();
    int rows = model->rowCount();
    int cols = model->columnCount();

    string file_ = "/tmp/list" +
                   wApp->sessionId() +
                   servertime() +
                   ".csv";
    string _file = ReadConfig("RootDir") +
                   ReadConfig("AppDir") +
                   file_;
    ofstream csv(_file.c_str());

    // header
    for(unsigned j = 0; j < cols; ++j) {
        if(!includeHidden) {
            if(tv->isColumnHidden(j)) {
                if(j == cols-1) {
                    csv << "\n";
                    continue;
                }
                else
                    continue;
            }
        }
        // export
        WString str = Wt::asString(model->headerData(j));
        if(j == cols-1)
            csv << (str + "\n").toUTF8();
        else
            csv    << (str + ",").toUTF8();
    }
    // data row
    for(unsigned i = 0; i < rows; ++i) {

        // data col
        for(unsigned j = 0; j < cols; ++j) {
            if(!includeHidden) {
                if(tv->isColumnHidden(j)) {
                    if(j == cols-1) {
                        csv << "\n";
                        continue;
                    }
                    else
                        continue;
                }
            }
            // export
            WString str = Wt::asString(model->data(i, j));
            if(j == cols-1)
                csv << (str + "\n").toUTF8();
            else
                csv    << (str + ",").toUTF8();
        }
    }

    csv.close();

    Wt::Ext::MessageBox::show("Ok",
                              "Download:" + WString(href(file_, "The CSV
list")),
                              WFlags<StandardButton>(Ok));
    unlink(_file.c_str());
}
------------------------------------------------------------------------------
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to