summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-09-21 20:51:51 +0100
committerCaolán McNamara <caolanm@redhat.com>2021-09-22 09:57:41 +0200
commit7f5af8272d8b10bf56b82cbe9d898e8ed0a347ca (patch)
tree25ec214eeab3d41e0a05ed6c4a9116aa4cf9db48 /sc
parentba0851926a9def7577dcf7b29919de0632ac31a9 (diff)
add a TestImportDBF
Change-Id: Iddb0d69d2ffaafd81076cd52a8424c32fe3c4114 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122408 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/docshell/docsh.cxx42
-rw-r--r--sc/source/ui/inc/docsh.hxx4
2 files changed, 46 insertions, 0 deletions
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index d6bb0d9f5f6f..baf0903ca855 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -121,6 +121,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <unotools/configmgr.hxx>
+#include <unotools/tempfile.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <uiitems.hxx>
#include <dpobject.hxx>
@@ -3404,4 +3405,45 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportSLK(SvStream &rStream)
return aImpEx.ImportStream(rStream, OUString(), SotClipboardFormatId::SYLK);
}
+extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDBF(SvStream &rStream)
+{
+ ScDLL::Init();
+
+ utl::TempFile aTempInput;
+ aTempInput.EnableKillingFile();
+
+ // need a real file for this filter
+ SvStream* pInputStream = aTempInput.GetStream(StreamMode::WRITE);
+ sal_uInt8 aBuffer[8192];
+ while (auto nRead = rStream.ReadBytes(aBuffer, SAL_N_ELEMENTS(aBuffer)))
+ pInputStream->WriteBytes(aBuffer, nRead);
+ aTempInput.CloseStream();
+
+ SfxMedium aMedium(aTempInput.GetURL(), StreamMode::STD_READWRITE);
+
+ ScDocShellRef xDocShell = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT |
+ SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
+ SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+
+ xDocShell->DoInitNew();
+
+ ScDocument& rDoc = xDocShell->GetDocument();
+
+ ScDocOptions aDocOpt = rDoc.GetDocOptions();
+ aDocOpt.SetLookUpColRowNames(false);
+ rDoc.SetDocOptions(aDocOpt);
+ rDoc.MakeTable(0);
+ rDoc.EnableExecuteLink(false);
+ rDoc.SetInsertingFromOtherDoc(true);
+
+ ScDocRowHeightUpdater::TabRanges aRecalcRanges(0, rDoc.MaxRow());
+ std::map<SCCOL, ScColWidthParam> aColWidthParam;
+ ErrCode eError = xDocShell->DBaseImport(aMedium.GetPhysicalName(), RTL_TEXTENCODING_IBM_850, aColWidthParam, aRecalcRanges.maRanges);
+
+ xDocShell->DoClose();
+ xDocShell.clear();
+
+ return eError == ERRCODE_NONE;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 8c353d0087c7..635db201ac97 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -70,6 +70,8 @@ typedef std::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
enum class LOKCommentNotificationType { Add, Modify, Remove };
+extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDBF(SvStream &rStream);
+
// Extra flags for Repaint
#define SC_PF_LINES 1
#define SC_PF_TESTMERGE 2
@@ -133,6 +135,8 @@ class SC_DLLPUBLIC ScDocShell final: public SfxObjectShell, public SfxListener
SAL_DLLPRIVATE bool SaveXML( SfxMedium* pMedium, const css::uno::Reference< css::embed::XStorage >& );
SAL_DLLPRIVATE SCTAB GetSaveTab();
+ friend bool TestImportDBF(SvStream &rStream);
+
SAL_DLLPRIVATE ErrCode DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
std::map<SCCOL, ScColWidthParam>& aColWidthParam, ScFlatBoolRowSegments& rRowHeightsRecalc );
SAL_DLLPRIVATE ErrCode DBaseExport(