Corretta esportazione in Exel degli spreadsheet

git-svn-id: svn://10.65.10.50/branches/R_10_00@22670 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2012-06-07 15:59:36 +00:00
parent 4937ec8dda
commit 7598c0bf5e

View File

@ -13,6 +13,7 @@ extern "C"
#include <diction.h>
#include <msksheet.h>
#include <recarray.h>
#include <recset.h>
#include <relation.h>
#include <urldefid.h>
#include <utility.h>
@ -190,7 +191,7 @@ class TSpreadsheet : public TControl
// @cmember:(INTERNAL) Dimensioni delle colonne
int _default_width[MAX_COL];
// @cmember:(INTERNAL) Bisogna salvare l'ordien delle colonne
// @cmember:(INTERNAL) Bisogna salvare l'ordine delle colonne
byte _save_columns_order;
// @cmember:(INTERNAL) Campo corrente che si sta editando
@ -3625,13 +3626,97 @@ static TString& clean_white_space(TString& str)
return str;
}
///////////////////////////////////////////////////////////
// TSheet_recordset
///////////////////////////////////////////////////////////
class TSheet_recordset : public TRecordset
{
const TSpreadsheet* _sheet;
TRecnotype _curr;
public:
virtual unsigned int columns() const { return _sheet->columns(); }
virtual const TRecordset_column_info& column_info(unsigned int i) const;
virtual TRecnotype items() const { return _sheet->items(); }
virtual bool move_to(TRecnotype pos);
virtual TRecnotype current_row() const { return _curr; }
virtual void requery() {}
virtual const TVariant& get(unsigned int column) const;
public:
virtual const TString& query_text() const { return EMPTY_STRING; }
TSheet_recordset(const TSpreadsheet* s) : _sheet(s), _curr(-1) {}
};
bool TSheet_recordset::move_to(TRecnotype pos)
{
const bool ok = pos >= 0 && pos < items();
if (ok)
_curr = pos;
return ok;
}
const TRecordset_column_info& TSheet_recordset::column_info(unsigned int i) const
{
static TRecordset_column_info _info;
_info._pos = i;
if (i >= 0 && i < columns())
{
int columns = 0;
XI_OBJ** pcols = xi_get_member_list(((TSpreadsheet*)_sheet)->xi_object(), &columns);
xi_get_text(pcols[i+1], _info._name.get_buffer(), _info._name.size());
_info._name.trim();
const TMask_field& fld = _sheet->sheet_mask().field(short(101+i));
switch (fld.class_id())
{
case CLASS_BOOLEAN_FIELD : _info._type = _boolfld; break;
case CLASS_DATE_FIELD : _info._type = _datefld; break;
case CLASS_CURRENCY_FIELD:
case CLASS_REAL_FIELD : _info._type = _realfld; break;
default : _info._type = _alfafld; break;
}
_info._width = fld.size();
}
else
{
_info._name.cut(0);
_info._type = _nullfld;
_info._width = 0;
}
return _info;
}
const TVariant& TSheet_recordset::get(unsigned int column) const
{
TVariant& var = get_tmp_var();
if (_curr >= 0 && _curr < items() && column < columns())
{
TToken_string& row = ((TSpreadsheet*)_sheet)->row(_curr);
var = row.get(column);
}
return var;
}
///////////////////////////////////////////////////////////
// Esportazione
///////////////////////////////////////////////////////////
bool TSheet_field::esporta() const
{
TFilename name;
name.tempdir();
name.add(mask().source_file().name_only());
name.ext("xls");
TSheet_recordset sr((TSpreadsheet*)_ctl);
sr.save_as(name);
/*
ofstream xls(name);
const char sep = '\t';
TToken_string tab(128, sep);
@ -3675,6 +3760,8 @@ bool TSheet_field::esporta() const
xls << tab << endl;
}
xls.close();
*/
xvt_sys_goto_url(name, "open");
return true;