28#include <osl/diagnose.h>
31#include <com/sun/star/sdb/CommandType.hpp>
32#include <com/sun/star/sdb/XCompletedExecution.hpp>
33#include <com/sun/star/sdbc/SQLException.hpp>
34#include <com/sun/star/sdbc/XRow.hpp>
35#include <com/sun/star/sdbc/XRowSet.hpp>
36#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
37#include <com/sun/star/sdbcx/XRowLocate.hpp>
38#include <com/sun/star/task/InteractionHandler.hpp>
39#include <com/sun/star/lang/XMultiServiceFactory.hpp>
40#include <com/sun/star/beans/XPropertySet.hpp>
41#include <com/sun/star/frame/FrameSearchFlag.hpp>
42#include <com/sun/star/view/XSelectionSupplier.hpp>
52#include <progress.hxx>
76 if ( !pFrame || !rParam.
bImport )
81 uno::Reference<frame::XFrame> xBeamerFrame =
xFrame->findFrame(
83 frame::FrameSearchFlag::CHILDREN);
84 if (!xBeamerFrame.is())
87 uno::Reference<frame::XController>
xController = xBeamerFrame->getController();
88 uno::Reference<view::XSelectionSupplier> xControllerSelection(
xController, uno::UNO_QUERY);
89 if (xControllerSelection.is())
91 sal_Int32
nType = rParam.
bSql ? sdb::CommandType::COMMAND :
104 OSL_FAIL(
"no selection supplier in the beamer!");
109 const uno::Sequence<beans::PropertyValue>& aArgs )
116 OUString sTarget = pDBData->
GetName();
136 OSL_FAIL(
"DoImport: no DBData" );
143 bool bSuccess =
false;
144 bool bTruncated =
false;
146 OUString aErrorMessage;
150 SCCOL nEndCol = nCol;
151 SCROW nEndRow = nRow;
153 bool bDoSelection =
false;
154 bool bRealSelection =
false;
155 bool bBookmarkSelection =
false;
156 sal_Int32 nListPos = 0;
157 sal_Int32 nRowsRead = 0;
158 sal_Int32 nListCount = 0;
160 uno::Sequence<uno::Any> aSelection;
164 nListCount = aSelection.getLength();
165 if ( nListCount > 0 )
170 if ( bBookmarkSelection )
174 bRealSelection =
true;
179 uno::Reference<sdbc::XResultSet> xResultSet;
185 pImportDoc->InitUndo( rDoc, nTab, nTab );
195 uno::Reference<sdbc::XRowSet> xRowSet( xResultSet, uno::UNO_QUERY );
196 bool bDispose =
false;
203 uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY );
204 OSL_ENSURE( xRowProp.is(),
"can't get RowSet" );
210 sal_Int32
nType = rParam.
bSql ? sdb::CommandType::COMMAND :
220 uno::Reference<sdb::XCompletedExecution> xExecute( xRowSet, uno::UNO_QUERY );
223 uno::Reference<task::XInteractionHandler> xHandler(
225 uno::UNO_QUERY_THROW);
226 xExecute->executeWithCompletion( xHandler );
237 sal_Int32 nColCount = 0;
238 uno::Reference<sdbc::XResultSetMetaData> xMeta;
239 uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY );
240 if ( xMetaSupp.is() )
241 xMeta = xMetaSupp->getMetaData();
243 nColCount = xMeta->getColumnCount();
245 if ( rParam.
nCol1 + nColCount - 1 > rDoc.
MaxCol() )
251 uno::Reference<sdbcx::XRowLocate> xLocate;
252 if ( bBookmarkSelection )
254 xLocate.set( xRowSet, uno::UNO_QUERY );
257 SAL_WARN(
"sc.ui",
"can't get XRowLocate");
258 bDoSelection = bRealSelection = bBookmarkSelection =
false;
262 uno::Reference<sdbc::XRow> xRow( xRowSet, uno::UNO_QUERY );
263 if ( nColCount > 0 && xRow.is() )
265 nEndCol =
static_cast<SCCOL>( rParam.
nCol1 + nColCount - 1 );
267 uno::Sequence<sal_Int32> aColTypes( nColCount );
268 uno::Sequence<sal_Bool> aColCurr( nColCount );
269 sal_Int32* pTypeArr = aColTypes.getArray();
270 sal_Bool* pCurrArr = aColCurr.getArray();
273 pTypeArr[
i] = xMeta->getColumnType(
i+1 );
274 pCurrArr[
i] = xMeta->isCurrency(
i+1 );
281 pImportDoc->SetString( nCol, nRow, nTab,
282 xMeta->getColumnLabel(
i+1 ) );
289 xRowSet->beforeFirst();
290 sal_uInt16 nInserted = 0;
296 bEnd = !xRowSet->next();
302 if (nListPos < nListCount)
304 if ( bBookmarkSelection )
306 bEnd = !xLocate->moveToBookmark(aSelection[nListPos]);
310 sal_Int32 nNextRow = 0;
311 aSelection[nListPos] >>= nNextRow;
312 if ( nRowsRead+1 < nNextRow )
313 bRealSelection =
true;
314 nRowsRead = nNextRow;
315 bEnd = !xRowSet->absolute(nRowsRead);
321 if ( !bBookmarkSelection && xRowSet->next() )
322 bRealSelection =
true;
335 xRow,
i+1, pTypeArr[
i], pCurrArr[
i] );
344 if (!(nInserted & 15))
361 ::comphelper::disposeComponent( xRowSet );
364 catch (
const sdbc::SQLException& rError )
366 aErrorMessage = rError.Message;
368 catch ( uno::Exception& )
376 bool bMoveCells = pDBData->
IsDoSize();
377 SCCOL nFormulaCols = 0;
378 if (bMoveCells && nEndCol == rParam.
nCol2)
385 while ( nTestCol <= rDoc.
MaxCol() &&
406 nEndCol+nFormulaCols, nEndRow, nTab );
409 if ( bSuccess && bMoveCells )
412 rParam.
nCol2+nFormulaCols, rParam.
nRow2, nTab );
414 nEndCol+nFormulaCols, nEndRow, nTab );
417 pErrStringId = STR_MSSG_DOSUBTOTALS_2;
431 SCCOL nMinEndCol = std::min( rParam.
nCol2, nEndCol );
432 nMinEndCol = sal::static_int_cast<SCCOL>( nMinEndCol + nFormulaCols );
435 nMinEndCol, rParam.
nRow1, nTab,
439 for (
SCCOL nCopyCol=rParam.
nCol1; nCopyCol<=nMinEndCol; nCopyCol++)
442 nCopyCol, nDataStartRow, nTab );
443 pImportDoc->ApplyPatternAreaTab( nCopyCol, nDataStartRow, nCopyCol, nEndRow,
444 nTab, *pSrcPattern );
447 pImportDoc->ApplyStyleAreaTab( nCopyCol, nDataStartRow, nCopyCol, nEndRow,
457 pImportDoc->ApplyPatternAreaTab( 0,0,rDoc.
MaxCol(),rDoc.
MaxRow(), nTab, aPattern );
462 SCCOL nUndoEndCol = std::max( nEndCol, rParam.
nCol2 );
463 SCROW nUndoEndRow = std::max( nEndRow, rParam.
nRow2 );
466 std::unique_ptr<ScDBData> pUndoDBData;
470 pUndoDoc->InitUndo( rDoc, nTab, nTab );
472 pUndoDBData.reset(
new ScDBData( *pDBData ));
485 nEndCol+nFormulaCols, nEndRow, nTab,
486 nCopyFlags,
false, *pUndoDoc);
487 if ( rParam.
nCol2 > nEndCol )
489 nUndoEndCol, nUndoEndRow, nTab,
490 nCopyFlags,
false, *pUndoDoc);
491 if ( rParam.
nRow2 > nEndRow )
493 nUndoEndCol+nFormulaCols, nUndoEndRow, nTab,
494 nCopyFlags,
false, *pUndoDoc);
509 rParam.
nCol2+nFormulaCols, rParam.
nRow2, nTab );
511 nEndCol+nFormulaCols, nEndRow, nTab );
514 else if ( nEndCol < rParam.
nCol2 )
524 for (
SCCOL nCopyCol = rParam.
nCol1; nCopyCol <= nEndCol; nCopyCol++)
526 pImportDoc->CopyToDocument(nCopyCol, rParam.
nRow1, nTab, nCopyCol, nEndRow, nTab,
532 if (nFormulaCols > 0)
535 pImportDoc->CopyToDocument(nEndCol+1, rParam.
nRow1, nTab,
536 nEndCol+nFormulaCols, nEndRow, nTab,
543 nProgCount *= nEndRow-rParam.
nRow1-1;
545 ScResId(STR_FILL_SERIES_PROGRESS), nProgCount,
true );
547 rDoc.
Fill( nEndCol+1, rParam.
nRow1+1, nEndCol+nFormulaCols, rParam.
nRow1+1,
555 if ( rParam.
nCol2 > nEndCol )
558 if ( rParam.
nRow2 > nEndRow )
575 if (nFormulaCols > 0)
577 nEndCol+nFormulaCols, nEndRow, nTab,
580 std::unique_ptr<ScDBData> pRedoDBData(
new ScDBData(*pDBData));
583 std::make_unique<ScUndoImportData>( &
rDocShell, nTab,
584 rParam, nUndoEndCol, nUndoEndRow,
586 std::move(pUndoDoc), std::move(pRedoDoc),
587 std::move(pUndoDBData), std::move(pRedoDBData) ) );
607 if (aErrorMessage.isEmpty())
610 pErrStringId = STR_MSSG_IMPORTDATA_0;
611 aErrorMessage =
ScResId(pErrStringId);
615 VclMessageType::Info, VclButtonsType::Ok,
622 if (bSuccess && pChangeTrack)
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
SC_DLLPUBLIC void AppendInsert(const ScRange &rRange, bool bEndOfList=false)
const OUString & GetName() const
void SetImportParam(const ScImportParam &rImportParam)
void SetHeader(bool bHasH)
void SetImportSelection(bool bSet)
void SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
static void ShowInBeamer(const ScImportParam &rParam, const SfxViewFrame *pFrame)
void UpdateImport(const OUString &rTarget, const svx::ODataAccessDescriptor &rDescriptor)
void DoImportUno(const ScAddress &rPos, const css::uno::Sequence< css::beans::PropertyValue > &aArgs)
bool DoImport(SCTAB nTab, const ScImportParam &rParam, const svx::ODataAccessDescriptor *pDescriptor)
static void PutData(ScDocument &rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const css::uno::Reference< css::sdbc::XRow > &xRow, sal_Int32 nRowPos, tools::Long nType, bool bCurrency, StrData *pStrData=nullptr)
Create before modifications of the document and destroy thereafter.
void SetDocumentModified()
static weld::Window * GetActiveDialogParent()
const ScDocument & GetDocument() const
ScDBData * GetDBData(const ScRange &rMarked, ScGetDBMode eMode, ScGetDBSelection eSel)
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
virtual SfxUndoManager * GetUndoManager() override
ScSheetLimits & GetSheetLimits() const
bool ValidRow(SCROW nRow) const
SC_DLLPUBLIC void Fill(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScProgress *pProgress, const ScMarkData &rMark, sal_uInt64 nFillCount, FillDir eFillDir=FILL_TO_BOTTOM, FillCmd eFillCmd=FILL_LINEAR, FillDateCmd eFillDateCmd=FILL_DAY, double nStepValue=1.0, double nMaxValue=1E307)
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
SC_DLLPUBLIC SCCOL MaxCol() const
SC_DLLPUBLIC SCROW MaxRow() const
SC_DLLPUBLIC const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
SC_DLLPUBLIC bool GetAutoCalc() const
SC_DLLPUBLIC void DeleteArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const ScMarkData &rMark, InsertDeleteFlags nDelFlag, bool bBroadcast=true, sc::ColumnSpanSet *pBroadcastSpans=nullptr)
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
void FitBlock(const ScRange &rOld, const ScRange &rNew, bool bClear=true)
SfxObjectShell * GetDocumentShell() const
SC_DLLPUBLIC void SetAutoCalc(bool bNewAutoCalc)
SC_DLLPUBLIC void DeleteAreaTab(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, InsertDeleteFlags nDelFlag)
ScChangeTrack * GetChangeTrack() const
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
bool IsUndoEnabled() const
bool CanFitBlock(const ScRange &rOld, const ScRange &rNew)
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
void BroadcastUno(const SfxHint &rHint)
TranslateId GetMessageId() const
void TestBlock(const ScDocument &rDoc, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll=false)
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
void SelectOneTable(SCTAB nTab)
const ScStyleSheet * GetStyleSheet() const
SfxItemSet & GetItemSet()
void SetState(sal_uInt64 nVal, sal_uInt64 nNewRange=0)
static bool GetBoolFromAny(const css::uno::Any &aAny)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
SfxFrame & GetFrame() const
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
bool has(DataAccessDescriptorProperty _eWhich) const
void setDataSource(const OUString &_sDataSourceNameOrLocation)
constexpr OUStringLiteral SC_DBPROP_DATASOURCENAME
move to a header file?
constexpr OUStringLiteral SC_DBPROP_COMMAND
constexpr OUStringLiteral SC_SERVICE_ROWSET
constexpr OUStringLiteral SC_DBPROP_COMMANDTYPE
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
@ NOTE
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
@ ATTRIB
Internal use only (d&d undo): do not delete caption objects of cell notes.
@ Keep
Keep selection as is, expand to used data area if no selection.
@ SC_DB_IMPORT
create "Importx" (if necessary)
#define SAL_WARN(area, stream)
Reference< XMultiServiceFactory > getProcessServiceFactory()
Reference< XComponentContext > getProcessComponentContext()
OUString ScResId(TranslateId aId)
#define SCWARN_IMPORT_RANGE_OVERFLOW
Reference< XController > xController
Reference< XFrame > xFrame