sc/source/core/data/column3.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
New commits: commit fec741b1902fd008a732ce0d8f57435cdfa65f57 Author: Andrzej Hunt <andr...@ahunt.org> Date: Sat Feb 7 11:33:39 2015 +0000 Implement actual unit extraction / format setting. This makes the unit verification automatic (modulo no UI), but is still very hacky. Change-Id: Iff6f97b2c070e1caf2911533339cb3f07b259ed4 diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 5170d14..329a1fd 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1672,6 +1672,33 @@ bool ScColumn::ParseString( { if (aParam.mbDetectNumberFormat) { +#ifdef ENABLE_CALC_UNITVERIFICATION + OUString sValue, sUnit; + boost::shared_ptr< sc::units::Units > pUnits = sc::units::Units::GetUnits(); + if (pUnits->splitUnitsFromInputString(rString, sValue, sUnit)) { + // TODO we should check whether a suitable format already exists. + // We also want to ideally preserve whatever format would be used + // for the actual numbers (e.g. 1E4 is preserved as 1E4 unless we + // now set the number format as #"foo" in which case the raw number is + // displayed i.e. 1000foo) + + // I.e. it may be more sensible to extract the unit here, continue processing as normal + // and then at the end add the unit to the format. In fact we should probably ALWAYS + // remove the unit whenever doing any format processing (i.e. everywhere), and reappend it after? + // But in that case it would make sense to actually store units independently of number format. + + // (This is all just a dirty hack for now...) + OUString sNewFormat = "#\"" + sUnit + "\""; + sal_uInt32 nFormatKey; + short nType = css::util::NumberFormat::DEFINED; + sal_Int32 nErrorPosition; // Unused, because we should be creating working number formats. + + aParam.mpNumFormatter->PutEntry(sNewFormat, nErrorPosition, nType, nFormatKey); + SetNumberFormat(nRow, nFormatKey); + + nIndex = nFormatKey; + } +#endif if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) break; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits