follow tdf#154131 Treat also HMTL import
Add Detect numbers in scientific notation option to HTML paste
Still need some qa tests
Change-Id: I553404a01ab2a61566b861b3c01d14bdc0c46668
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152591
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/inc/filter.hxx b/sc/inc/filter.hxx
index 7a71b89..6bceb74 100644
--- a/sc/inc/filter.hxx
+++ b/sc/inc/filter.hxx
@@ -50,7 +50,8 @@ class ScEEAbsImport {
virtual ScRange GetRange() = 0;
virtual void WriteToDocument(
bool bSizeColsRows = false, double nOutputFactor = 1.0,
SvNumberFormatter* pFormatter = nullptr, bool bConvertDate = true ) = 0;
SvNumberFormatter* pFormatter = nullptr, bool bConvertDate = true,
bool bConvertScientific = true ) = 0;
};
class SAL_DLLPUBLIC_RTTI ScFormatFilterPlugin {
@@ -67,7 +68,8 @@ class SAL_DLLPUBLIC_RTTI ScFormatFilterPlugin {
const rtl_TextEncoding eSrc ) = 0;
virtual ErrCode ScImportRTF( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange ) = 0;
virtual ErrCode ScImportHTML( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange, double nOutputFactor,
bool bCalcWidthHeight, SvNumberFormatter* pFormatter, bool bConvertDate ) = 0;
bool bCalcWidthHeight, SvNumberFormatter* pFormatter, bool bConvertDate,
bool bConvertScientific ) = 0;
// various import helpers
virtual std::unique_ptr<ScEEAbsImport> CreateRTFImport( ScDocument* pDoc, const ScRange& rRange ) = 0;
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index a06a435..7a94af5 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -394,6 +394,7 @@ protected:
public:
virtual LanguageType GetLanguageType() const = 0;
virtual bool IsDateConversionSet() const = 0;
virtual bool IsScientificConversionSet() const = 0;
virtual bool IsKeepAskingSet() const = 0;
};
diff --git a/sc/source/filter/html/htmlimp.cxx b/sc/source/filter/html/htmlimp.cxx
index 12e98a9..3168a02 100644
--- a/sc/source/filter/html/htmlimp.cxx
+++ b/sc/source/filter/html/htmlimp.cxx
@@ -45,13 +45,13 @@
ErrCode ScFormatFilterPluginImpl::ScImportHTML( SvStream &rStream, const OUString& rBaseURL, ScDocument *pDoc,
ScRange& rRange, double nOutputFactor, bool bCalcWidthHeight, SvNumberFormatter* pFormatter,
bool bConvertDate )
bool bConvertDate, bool bConvertScientific )
{
ScHTMLImport aImp( pDoc, rBaseURL, rRange, bCalcWidthHeight );
ErrCode nErr = aImp.Read( rStream, rBaseURL );
ScRange aR = aImp.GetRange();
rRange.aEnd = aR.aEnd;
aImp.WriteToDocument( true, nOutputFactor, pFormatter, bConvertDate );
aImp.WriteToDocument( true, nOutputFactor, pFormatter, bConvertDate, bConvertScientific );
return nErr;
}
@@ -112,9 +112,10 @@ void ScHTMLImport::InsertRangeName( ScDocument& rDoc, const OUString& rName, con
}
void ScHTMLImport::WriteToDocument(
bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate,
bool bConvertScientific )
{
ScEEImport::WriteToDocument( bSizeColsRows, nOutputFactor, pFormatter, bConvertDate );
ScEEImport::WriteToDocument( bSizeColsRows, nOutputFactor, pFormatter, bConvertDate, bConvertScientific );
const ScHTMLParser* pParser = static_cast<ScHTMLParser*>(mpParser.get());
const ScHTMLTable* pGlobTable = pParser->GetGlobalTable();
diff --git a/sc/source/filter/inc/eeimport.hxx b/sc/source/filter/inc/eeimport.hxx
index d4ddc31..0d0466e 100644
--- a/sc/source/filter/inc/eeimport.hxx
+++ b/sc/source/filter/inc/eeimport.hxx
@@ -56,7 +56,8 @@ public:
virtual void WriteToDocument( bool bSizeColsRows = false,
double nOutputFactor = 1.0,
SvNumberFormatter* pFormatter = nullptr,
bool bConvertDate = true ) override;
bool bConvertDate = true,
bool bConvertScientific = true ) override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/ftools.hxx b/sc/source/filter/inc/ftools.hxx
index 1366a51..5e5b8dd 100644
--- a/sc/source/filter/inc/ftools.hxx
+++ b/sc/source/filter/inc/ftools.hxx
@@ -275,7 +275,7 @@ public:
virtual ErrCode ScImportRTF( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange ) override;
virtual ErrCode ScImportHTML( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange,
double nOutputFactor, bool bCalcWidthHeight,
SvNumberFormatter* pFormatter, bool bConvertDate ) override;
SvNumberFormatter* pFormatter, bool bConvertDate, bool bConvertScientific ) override;
virtual std::unique_ptr<ScEEAbsImport> CreateRTFImport( ScDocument* pDoc, const ScRange& rRange ) override;
virtual std::unique_ptr<ScEEAbsImport> CreateHTMLImport( ScDocument* pDocP, const OUString& rBaseURL, const ScRange& rRange ) override;
diff --git a/sc/source/filter/inc/htmlimp.hxx b/sc/source/filter/inc/htmlimp.hxx
index 76acc44..bff4b38 100644
--- a/sc/source/filter/inc/htmlimp.hxx
+++ b/sc/source/filter/inc/htmlimp.hxx
@@ -30,7 +30,8 @@ public:
ScHTMLImport( ScDocument* pDoc, const OUString& rBaseURL, const ScRange& rRange, bool bCalcWidthHeight );
virtual void WriteToDocument( bool bSizeColsRows = false, double nOutputFactor = 1.0,
SvNumberFormatter* pFormatter = nullptr, bool bConvertDate = true ) override;
SvNumberFormatter* pFormatter = nullptr, bool bConvertDate = true,
bool bConvertScientific = true ) override;
static OUString GetHTMLRangeNameList( const ScDocument& rDoc, std::u16string_view rOrigName );
};
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index e9ab917..c8e8199 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -112,7 +112,8 @@ namespace
}
}
void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate,
bool bConvertScientific )
{
std::unique_ptr<ScProgress> pProgress( new ScProgress( mpDoc->GetDocumentShell(),
ScResId( STR_LOAD_DOC ), mpParser->ListSize(), true ) );
@@ -395,10 +396,14 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu
if (bTextFormat)
{
aParam.mbDetectNumberFormat = false;
aParam.mbDetectScientificNumberFormat = bConvertScientific;
aParam.meSetTextNumFormat = ScSetStringParam::Always;
}
else
{
aParam.mbDetectNumberFormat = bConvertDate;
aParam.mbDetectScientificNumberFormat = bConvertScientific;
}
mpDoc->SetString(nCol, nRow, nTab, aStr, &aParam);
}
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index 26db05f..050b6d9 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -938,6 +938,11 @@ bool AbstractScTextImportOptionsDlg_Impl::IsDateConversionSet() const
return m_xDlg->isDateConversionSet();
}
bool AbstractScTextImportOptionsDlg_Impl::IsScientificConversionSet() const
{
return m_xDlg->isScientificConversionSet();
}
bool AbstractScTextImportOptionsDlg_Impl::IsKeepAskingSet() const
{
return m_xDlg->isKeepAskingSet();
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index 434b84d..5de1ca3 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -604,6 +604,7 @@ public:
virtual short Execute() override;
virtual LanguageType GetLanguageType() const override;
virtual bool IsDateConversionSet() const override;
virtual bool IsScientificConversionSet() const override;
virtual bool IsKeepAskingSet() const override;
// screenshotting
diff --git a/sc/source/ui/dbgui/textimportoptions.cxx b/sc/source/ui/dbgui/textimportoptions.cxx
index 99ddc42..e13bdfb 100644
--- a/sc/source/ui/dbgui/textimportoptions.cxx
+++ b/sc/source/ui/dbgui/textimportoptions.cxx
@@ -30,8 +30,9 @@ ScTextImportOptionsDlg::ScTextImportOptionsDlg(weld::Window* pParent)
, m_xBtnOk(m_xBuilder->weld_button("ok"))
, m_xRbAutomatic(m_xBuilder->weld_radio_button("automatic"))
, m_xRbCustom(m_xBuilder->weld_radio_button("custom"))
, m_xBtnConvertDate(m_xBuilder->weld_check_button("convertdata"))
, m_xBtnKeepAsking(m_xBuilder->weld_check_button("keepasking"))
, m_xCkbConvertDate(m_xBuilder->weld_check_button("convertdata"))
, m_xCkbConvertScientific(m_xBuilder->weld_check_button("convertscientificnotation"))
, m_xCkbKeepAsking(m_xBuilder->weld_check_button("keepasking"))
, m_xLbCustomLang(new SvxLanguageBox(m_xBuilder->weld_combo_box("lang")))
{
init();
@@ -51,20 +52,27 @@ LanguageType ScTextImportOptionsDlg::getLanguageType() const
bool ScTextImportOptionsDlg::isDateConversionSet() const
{
return m_xBtnConvertDate->get_active();
return m_xCkbConvertDate->get_active();
}
bool ScTextImportOptionsDlg::isScientificConversionSet() const
{
return m_xCkbConvertScientific->get_active();
}
bool ScTextImportOptionsDlg::isKeepAskingSet() const
{
return m_xBtnKeepAsking->get_active();
return m_xCkbKeepAsking->get_active();
}
void ScTextImportOptionsDlg::init()
{
m_xBtnOk->connect_clicked(LINK(this, ScTextImportOptionsDlg, OKHdl));
Link<weld::Toggleable&,void> aLink = LINK(this, ScTextImportOptionsDlg, RadioHdl);
Link<weld::Toggleable&,void> aLink = LINK(this, ScTextImportOptionsDlg, RadioCheckHdl);
m_xRbAutomatic->connect_toggled(aLink);
m_xRbCustom->connect_toggled(aLink);
m_xCkbConvertDate->connect_toggled(aLink);
m_xCkbConvertScientific->connect_toggled(aLink);
m_xRbAutomatic->set_active(true);
@@ -81,7 +89,7 @@ IMPL_LINK_NOARG(ScTextImportOptionsDlg, OKHdl, weld::Button&, void)
m_xDialog->response(RET_OK);
}
IMPL_LINK(ScTextImportOptionsDlg, RadioHdl, weld::Toggleable&, rBtn, void)
IMPL_LINK(ScTextImportOptionsDlg, RadioCheckHdl, weld::Toggleable&, rBtn, void)
{
if (&rBtn == m_xRbAutomatic.get())
{
@@ -91,6 +99,22 @@ IMPL_LINK(ScTextImportOptionsDlg, RadioHdl, weld::Toggleable&, rBtn, void)
{
m_xLbCustomLang->set_sensitive(true);
}
else if (&rBtn == m_xCkbConvertDate.get())
{
if (m_xCkbConvertDate->get_active())
{
m_xCkbConvertScientific->set_active(true);
m_xCkbConvertScientific->set_sensitive(false);
}
else
{
m_xCkbConvertScientific->set_sensitive(true);
}
}
else if (&rBtn == m_xCkbConvertScientific.get())
{
assert( !m_xCkbConvertDate->get_active() && "ScTextImportOptionsDlg::RadioCheckHdl - scientific option disabled if Detect numbers active" );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 8ff1b90..6df7652 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1137,7 +1137,7 @@ bool ScDocShell::LoadFrom( SfxMedium& rMedium )
return bRet;
}
static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLang, bool& rDateConvert)
static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLang, bool& rDateConvert, bool& rScientificConvert)
{
OUStringBuffer aBuf;
std::vector< OUString > aTokens;
@@ -1165,6 +1165,8 @@ static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLa
rLang = static_cast<LanguageType>(aTokens[0].toInt32());
if (aTokens.size() > 1)
rDateConvert = static_cast<bool>(aTokens[1].toInt32());
if (aTokens.size() > 2)
rScientificConvert = static_cast<bool>(aTokens[2].toInt32());
}
bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
@@ -1581,13 +1583,14 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
{
LanguageType eLang = LANGUAGE_SYSTEM;
bool bDateConvert = false;
bool bScientificConvert = true;
SfxItemSet* pSet = rMedium.GetItemSet();
const SfxStringItem* pOptionsItem;
if ( pSet &&
(pOptionsItem = pSet->GetItemIfSet( SID_FILE_FILTEROPTIONS )) )
{
OUString aFilterOption = pOptionsItem->GetValue();
lcl_parseHtmlFilterOption(aFilterOption, eLang, bDateConvert);
lcl_parseHtmlFilterOption(aFilterOption, eLang, bDateConvert, bScientificConvert);
}
pInStream->Seek( 0 );
@@ -1596,7 +1599,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
CalcOutputFactor();
SvNumberFormatter aNumFormatter( comphelper::getProcessComponentContext(), eLang);
eError = ScFormatFilter::Get().ScImportHTML( *pInStream, rMedium.GetBaseURL(), m_pDocument.get(), aRange,
GetOutputFactor(), !bWebQuery, &aNumFormatter, bDateConvert );
GetOutputFactor(), !bWebQuery, &aNumFormatter, bDateConvert, bScientificConvert );
if (eError != ERRCODE_NONE)
{
if (!GetError())
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 1c55296..1e62c33 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -2656,7 +2656,8 @@ bool ScImportExport::HTML2Doc( SvStream& rStrm, const OUString& rBaseURL )
LanguageType eLang = pExtOptions->GetLanguage();
SvNumberFormatter aNumFormatter( comphelper::getProcessComponentContext(), eLang);
bool bSpecialNumber = pExtOptions->IsDetectSpecialNumber();
pImp->WriteToDocument(false, 1.0, &aNumFormatter, bSpecialNumber);
bool bScientificNumber = pExtOptions->IsDetectScientificNumber();
pImp->WriteToDocument(false, 1.0, &aNumFormatter, bSpecialNumber, bScientificNumber);
}
else
// Regular import, with no options.
diff --git a/sc/source/ui/inc/textimportoptions.hxx b/sc/source/ui/inc/textimportoptions.hxx
index 35e2fff..7a2cfb6 100644
--- a/sc/source/ui/inc/textimportoptions.hxx
+++ b/sc/source/ui/inc/textimportoptions.hxx
@@ -32,6 +32,7 @@ public:
LanguageType getLanguageType() const;
bool isDateConversionSet() const;
bool isScientificConversionSet() const;
bool isKeepAskingSet() const;
private:
@@ -41,12 +42,13 @@ private:
std::unique_ptr<weld::Button> m_xBtnOk;
std::unique_ptr<weld::RadioButton> m_xRbAutomatic;
std::unique_ptr<weld::RadioButton> m_xRbCustom;
std::unique_ptr<weld::CheckButton> m_xBtnConvertDate;
std::unique_ptr<weld::CheckButton> m_xBtnKeepAsking;
std::unique_ptr<weld::CheckButton> m_xCkbConvertDate;
std::unique_ptr<weld::CheckButton> m_xCkbConvertScientific;
std::unique_ptr<weld::CheckButton> m_xCkbKeepAsking;
std::unique_ptr<SvxLanguageBox> m_xLbCustomLang;
DECL_LINK(OKHdl, weld::Button&, void);
DECL_LINK(RadioHdl, weld::Toggleable&, void);
DECL_LINK(RadioCheckHdl, weld::Toggleable&, void);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index 3831e96..f947496 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -215,6 +215,8 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
aBuf.append(static_cast<sal_Int32>(static_cast<sal_uInt16>(eLang)));
aBuf.append(' ');
aBuf.append(pDlg->IsDateConversionSet() ? u'1' : u'0');
aBuf.append(' ');
aBuf.append(pDlg->IsScientificConversionSet() ? u'1' : u'0');
aFilterOptions = aBuf.makeStringAndClear();
nRet = ui::dialogs::ExecutableDialogResults::OK;
}
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index f57eca0..7fb2bce 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -337,6 +337,7 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
static bool bHaveSavedPreferences = false;
static LanguageType eSavedLanguage;
static bool bSavedDateConversion;
static bool bSavedScientificConversion;
if (nFormatId == SotClipboardFormatId::HTML &&
!comphelper::LibreOfficeKit::isActive())
@@ -346,6 +347,7 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
ScAsciiOptions aOptions;
aOptions.SetLanguage(eSavedLanguage);
aOptions.SetDetectSpecialNumber(bSavedDateConversion);
aOptions.SetDetectScientificNumber(bSavedScientificConversion);
pObj->SetExtOptions(aOptions);
}
else
@@ -363,11 +365,13 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
ScAsciiOptions aOptions;
aOptions.SetLanguage(pDlg->GetLanguageType());
aOptions.SetDetectSpecialNumber(pDlg->IsDateConversionSet());
aOptions.SetDetectScientificNumber(pDlg->IsScientificConversionSet());
if (!pDlg->IsKeepAskingSet())
{
bHaveSavedPreferences = true;
eSavedLanguage = pDlg->GetLanguageType();
bSavedDateConversion = pDlg->IsDateConversionSet();
bSavedScientificConversion = pDlg->IsScientificConversionSet();
}
pObj->SetExtOptions(aOptions);
}
diff --git a/sc/uiconfig/scalc/ui/textimportoptions.ui b/sc/uiconfig/scalc/ui/textimportoptions.ui
index 9afab39..2ba1641 100644
--- a/sc/uiconfig/scalc/ui/textimportoptions.ui
+++ b/sc/uiconfig/scalc/ui/textimportoptions.ui
@@ -89,7 +89,7 @@
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<!-- n-columns=1 n-rows=1 -->
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -165,15 +165,44 @@
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkCheckButton" id="convertdata">
<property name="label" translatable="yes" context="textimportoptions|convertdata">Detect special numbers (such as dates)</property>
<!-- n-columns=1 n-rows=2 -->
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="margin-start">12</property>
<property name="margin-top">6</property>
<property name="can-focus">False</property>
<property name="row-spacing">6</property>
<property name="column-spacing">6</property>
<child>
<object class="GtkCheckButton" id="convertdata">
<property name="label" translatable="yes" context="textimportoptions|convertdata">Detect special numbers (such as dates)</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="margin-start">12</property>
<property name="margin-top">6</property>
<property name="use-underline">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="convertscientificnotation">
<property name="label" translatable="yes" context="textimportoptions|convertdata">Detect numbers with _scientific notation</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="margin-start">12</property>
<property name="margin-top">6</property>
<property name="use-underline">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
</child>
<child type="label">