diff --git a/include/recset.cpp b/include/recset.cpp index 5e571be06..4b5e5638d 100755 --- a/include/recset.cpp +++ b/include/recset.cpp @@ -122,11 +122,23 @@ bool TRecordset::save_as_html(const char* path) for (unsigned int c = 0; c < cols; c++) { const TRecordset_column_info& ci = column_info(c); - out << " " << endl; + out << " " << endl; } - out << " " << endl; + + TXmlItem tr; tr.SetTag("tr"); + tr.SetColorAttr("bgcolor", BTN_BACK_COLOR); + tr.Write(out, 2); + out << endl; + for (unsigned int c = 0; c < cols; c++) { const TRecordset_column_info& ci = column_info(c); @@ -150,21 +162,36 @@ bool TRecordset::save_as_html(const char* path) { if (!pi.addstatus(1)) break; + out << " " << endl; for (unsigned int c = 0; c < cols; c++) { const TRecordset_column_info& ci = column_info(c); out << " "; - if (ci._type == _longfld || ci._type == _realfld) + switch (ci._type) { - const real r = get(c).as_real(); - if (r.is_zero()) + case _intfld: + case _longfld: + { + const long r = get(c).as_int(); val.cut(0); - else - val = r.stringe(); + if (r != 0) + val << r; + } + break; + case _realfld: + { + const real r = get(c).as_real(); + if (r.is_zero()) + val.cut(0); + else + val = r.stringe(); + } + break; + default: + get(c).as_string(val); + break; } - else - get(c).as_string(val); if (val.full()) { val.rtrim(); @@ -182,82 +209,6 @@ bool TRecordset::save_as_html(const char* path) return !pi.iscancelled(); } -bool TRecordset::save_as_silk(const char* path) -{ - TProgind pi(items(), TR("Esportazione in corso..."), true, true); - - ofstream out(path); - out << "ID;PWXL;N;E" << endl; - - const unsigned int cols = columns(); - - int header = 1; - if (cols > 0) - { - // Larghezza colonne - for (unsigned int h = 0; h < cols; h++) - { - const TRecordset_column_info& ci = column_info(h); - const int w = max(ci._width, ci._name.len()); - out << "F;W" << (h+1) << ' ' << (h+1) << ' ' << w << endl; - } - - // Intestazioni colonne - for (unsigned int c = 0; c < cols; c++) - { - const TRecordset_column_info& ci = column_info(c); - out << 'C'; - if (c == 0) out << ";Y1"; - out << ";X" << (c+1) << ";K\"" << ci._name << '"' << endl; - } - header++; - } - - TString val; - for (bool ok = move_first(); ok; ok = move_next()) - { - for (unsigned int c = 0; ; c++) - { - const TVariant& var = get(c); - if (var.is_null() && c >= cols) - break; - - out << 'C'; - if (c == 0) out << ";Y" << (current_row()+header); - if (!var.is_empty()) - { - out << ";X" << (c+1) << ";K"; - var.as_string(val); - switch (var.type()) - { - case _alfafld: - case _datefld: - if (cols == 0 && is_numeric(val)) - { - out << val; - } - else - { - val.rtrim(); - val.replace('"', '\''); - out << '"' << val << '"'; - } - break; - default: - out << val; - break; - } - } - out << endl; - } - if (!pi.addstatus(1)) - break; - } - out << "E" << endl; - - return !pi.iscancelled(); -} - bool TRecordset::save_as_text(const char* path) { TProgind pi(items(), TR("Esportazione in corso..."), true, true); @@ -459,16 +410,13 @@ bool TRecordset::save_as(const char* path, TRecordsetExportFormat fmt, int mode) TString ext; xvt_fsys_parse_pathname(path, NULL, NULL, NULL, ext.get_buffer(), NULL); ext.lower(); - if (ext == "htm" || ext == "html" || ext == "xml") - fmt = fmt_html; else - if (ext == "xls" || ext == "slk") - fmt = fmt_silk; + if (ext == "htm" || ext == "html" || ext == "xml" || ext == "xls") + fmt = fmt_html; } bool ok = false; switch (fmt) { case fmt_html : ok = save_as_html(path); break; - case fmt_silk : ok = save_as_silk(path); break; case fmt_campo: ok = save_as_campo(path); break; case fmt_dbf : ok = save_as_dbf(path, mode); break; default : ok = save_as_text(path); break; diff --git a/include/recset.h b/include/recset.h index dbacda7cf..7ed36e091 100755 --- a/include/recset.h +++ b/include/recset.h @@ -26,7 +26,7 @@ struct TRecordset_column_info : public TObject // TRecordset /////////////////////////////////////////////////////////// -enum TRecordsetExportFormat { fmt_unknown, fmt_html, fmt_text, fmt_silk, fmt_campo, fmt_dbf }; +enum TRecordsetExportFormat { fmt_unknown, fmt_html, fmt_text, fmt_campo, fmt_dbf }; class TRecordset : public TObject { diff --git a/include/sheet.cpp b/include/sheet.cpp index bbeb1165e..c9aa6a6ad 100755 --- a/include/sheet.cpp +++ b/include/sheet.cpp @@ -1386,11 +1386,24 @@ bool TSheet::export_handler(TMask_field& f, KEY k) { const int idx = pcols[c]->cid - 1101; const char ct = s._sheet->column_type(idx); - xls << " " << endl; + TXmlItem col; col.SetTag("col"); + switch (ct) + { + case 'C': col.SetAttr("align", "center"); break; + case 'P': + case 'R': + case 'V': col.SetAttr("align", "right"); break; + default : col.SetAttr("style", "mso-number-format:\\@"); break; + } + col.Write(xls, 3); + xls << endl; } - xls << " " << endl; - + TXmlItem tr; tr.SetTag("tr"); + tr.SetColorAttr("bgcolor", BTN_BACK_COLOR); + tr.Write(xls, 3); + xls << endl; + TString str; for (int c = 1; c < columns; c++) { diff --git a/include/xml.cpp b/include/xml.cpp index c0518e286..6406a5c8f 100755 --- a/include/xml.cpp +++ b/include/xml.cpp @@ -165,6 +165,13 @@ TXmlItem& TXmlItem::SetAttr(const char* strAttr, int n) return SetAttr(strAttr, str); } +TXmlItem& TXmlItem::SetColorAttr(const char* strAttr, COLOR rgb) +{ + TString8 str; + str.format("#%02X%02X%02X", XVT_COLOR_GET_RED(rgb), XVT_COLOR_GET_GREEN(rgb), XVT_COLOR_GET_BLUE(rgb)); + return SetAttr(strAttr, str); +} + int TXmlItem::GetIntAttr(const char* strAttr, int def) const { const TString& str = GetAttr(strAttr); @@ -587,9 +594,9 @@ void save_html_head(ostream& out, const char* title) { out << "" << endl; out << " " << title << "" << endl; - out << " " << endl; - out << " " << endl; - out << " " << endl; + out << " " << endl; + out << " " << endl; + out << " " << endl; out << " " << endl; diff --git a/include/xml.h b/include/xml.h index 0308ca069..ee016509b 100755 --- a/include/xml.h +++ b/include/xml.h @@ -47,6 +47,7 @@ public: TXmlItem& SetAttr(const char* strAttr, const char* strVal); const TString& GetAttr(const char* strAttr) const; TXmlItem& SetAttr(const char* strAttr, int n); + TXmlItem& SetColorAttr(const char* strAttr, COLOR rgb); int GetIntAttr(const char* strAttr, int def = 0) const; TXmlItem& SetAttr(const char* strAttr, bool yes); bool GetBoolAttr(const char* strAttr) const; @@ -78,6 +79,7 @@ public: TXmlItem& operator<<(TXmlItem& item, const char* str); void Spaces(ostream& outf, int nSpaces); void WriteXmlString(ostream& outf, const char* str); +void WriteXmlColor(ostream& outf, COLOR rgb); int hex2int(const char* str); void save_html_head(ostream& out, const char* title);