[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/filters/kspread/csv
From: Stefan Nikolaus <nikolaus4 () googlemail ! com>
Date: 2007-08-01 5:09:00
Message-ID: 1185944940.026595.11306.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 694996 by nikolaus:
Filters CSV Import.
Adapt to the KoCsvImportDialog changes: The possible data types are now
Generic, Text, Date and None.
M +30 -90 csvimport.cc
--- trunk/koffice/filters/kspread/csv/csvimport.cc #694995:694996
@@ -147,103 +147,43 @@
if ( len > widths[col] )
widths[col] = len;
- switch (dialog->headerType(col))
+ cell = Cell( sheet, col + 1, row + 1 );
+
+ switch (dialog->dataType(col))
{
- case KoCsvImportDialog::TEXT:
+ case KoCsvImportDialog::Generic:
+ default:
{
- //see KoCsvImportDialog::accept(), Tomas introduced the Generic \
format between KOffice 1.3 and 1.4
- //the Insert->External Data-> ... dialog uses the generic format for \
everything (see mentioned method)
- //I will use this approach only for the TEXT format in the CSV import \
filter... (raphael)
- //### FIXME: long term solution is to allow to select Generic format \
("autodetect") in the dialog and make it the default
-
- cell = Cell( sheet, col + 1, row + 1 );
- cell.parseUserInput( text );
-
- /* old code
- cell = Cell( sheet, col + 1, row + 1, s );
- cell.setValue( Value( text ) );
- */
- break;
- // ### TODO: put the code for the different numbers together (at least \
partially) + cell.parseUserInput(text);
+ break;
}
- case KoCsvImportDialog::NUMBER:
- {
- bool ok = false;
- double d = ksdoc->locale()->readNumber( text, &ok );
- // If not, try with the '.' as decimal separator
- if ( !ok )
- d = text.toDouble( &ok );
- if ( !ok )
- {
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setValue( Value( text ) );
- }
- else
- {
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setValue(Value(d));
- }
- cell.setUserInput(text);
- break;
- }
- case KoCsvImportDialog::COMMANUMBER:
- {
- bool ok = false;
- QString tmp ( text );
- tmp.remove ( QRegExp( "[^0-9,Ee+-]" ) ); // Keep only 0 to 9, \
comma, E, e, plus, minus
- tmp.replace ( ',', '.' );
- kDebug(30501) <<"Comma:" << text <<" =>" << tmp;
- const double d = tmp.toDouble( &ok );
- if ( !ok )
- {
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setValue( Value( text ) );
- }
- else
- {
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setValue(Value(d));
- }
- cell.setUserInput(tmp);
- break;
- }
- case KoCsvImportDialog::POINTNUMBER:
- {
- bool ok = false;
- QString tmp ( text );
- tmp.remove ( QRegExp( "[^0-9\\.EeD+-]" ) ); // Keep only 0 to 9, \
dot, E, e, D, plus, minus
- tmp.replace ( 'D', 'E' ); // double from FORTRAN use D instead \
of E
- kDebug(30501) <<"Point:" << text <<" =>" << tmp;
- const double d = tmp.toDouble( &ok );
- if ( !ok )
- {
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setValue( Value( text ) );
- }
- else
- {
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setValue(Value(d));
- }
- cell.setUserInput(tmp);
- break;
- }
- case KoCsvImportDialog::DATE:
+ case KoCsvImportDialog::Text:
{
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setUserInput(text);
- cell.setValue(ksdoc->converter()->asDate(Value(text)));
- break;
+ Value value(text);
+ cell.setValue(value);
+ cell.setUserInput(ksdoc->converter()->asString(value).asString());
+ break;
}
- case KoCsvImportDialog::CURRENCY:
+ case KoCsvImportDialog::Date:
{
- cell = Cell( sheet, col + 1, row + 1 );
- cell.setUserInput(text);
- Value value(text);
- value.setFormat(Value::fmt_Money);
- cell.setValue(value);
- break;
+ Value value(text);
+ cell.setValue(ksdoc->converter()->asDate(value));
+ cell.setUserInput(ksdoc->converter()->asString(value).asString());
+ break;
}
+ case KoCsvImportDialog::Currency:
+ {
+ Value value(text);
+ value.setFormat(Value::fmt_Money);
+ cell.setValue(value);
+ cell.setUserInput(ksdoc->converter()->asString(value).asString());
+ break;
+ }
+ case KoCsvImportDialog::None:
+ {
+ // just skip the content
+ break;
+ }
}
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic