LibreOffice Module sc (master)  1
dbdocimp.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <vcl/errinf.hxx>
22 #include <comphelper/types.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weld.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <sal/log.hxx>
28 #include <osl/diagnose.h>
29 
30 #include <com/sun/star/sdb/CommandType.hpp>
31 #include <com/sun/star/sdb/XCompletedExecution.hpp>
32 #include <com/sun/star/sdbc/SQLException.hpp>
33 #include <com/sun/star/sdbc/XRow.hpp>
34 #include <com/sun/star/sdbc/XRowSet.hpp>
35 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
36 #include <com/sun/star/sdbcx/XRowLocate.hpp>
37 #include <com/sun/star/task/InteractionHandler.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/frame/FrameSearchFlag.hpp>
41 #include <com/sun/star/view/XSelectionSupplier.hpp>
42 
43 #include <dbdocfun.hxx>
44 #include <docsh.hxx>
45 #include <globstr.hrc>
46 #include <scresid.hxx>
47 #include <scerrors.hxx>
48 #include <dbdata.hxx>
49 #include <markdata.hxx>
50 #include <undodat.hxx>
51 #include <progress.hxx>
52 #include <patattr.hxx>
53 #include <docpool.hxx>
54 #include <attrib.hxx>
55 #include <dbdocutl.hxx>
56 #include <editable.hxx>
57 #include <hints.hxx>
58 #include <miscuno.hxx>
59 #include <chgtrack.hxx>
60 #include <refupdatecontext.hxx>
61 
62 using namespace com::sun::star;
63 
64 #define SC_SERVICE_ROWSET "com.sun.star.sdb.RowSet"
65 
67 #define SC_DBPROP_DATASOURCENAME "DataSourceName"
68 #define SC_DBPROP_COMMAND "Command"
69 #define SC_DBPROP_COMMANDTYPE "CommandType"
70 
71 void ScDBDocFunc::ShowInBeamer( const ScImportParam& rParam, const SfxViewFrame* pFrame )
72 {
73  // called after opening the database beamer
74 
75  if ( !pFrame || !rParam.bImport )
76  return;
77 
78  uno::Reference<frame::XFrame> xFrame = pFrame->GetFrame().GetFrameInterface();
79 
80  uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame(
81  "_beamer",
82  frame::FrameSearchFlag::CHILDREN);
83  if (!xBeamerFrame.is())
84  return;
85 
86  uno::Reference<frame::XController> xController = xBeamerFrame->getController();
87  uno::Reference<view::XSelectionSupplier> xControllerSelection(xController, uno::UNO_QUERY);
88  if (xControllerSelection.is())
89  {
90  sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND :
91  ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY :
93 
94  svx::ODataAccessDescriptor aSelection;
95  aSelection.setDataSource(rParam.aDBName);
98 
99  xControllerSelection->select(uno::makeAny(aSelection.createPropertyValueSequence()));
100  }
101  else
102  {
103  OSL_FAIL("no selection supplier in the beamer!");
104  }
105 }
106 
108  const uno::Sequence<beans::PropertyValue>& aArgs )
109 {
110  svx::ODataAccessDescriptor aDesc( aArgs ); // includes selection and result set
111 
112  // create database range
113  ScDBData* pDBData = rDocShell.GetDBData( ScRange(rPos), SC_DB_IMPORT, ScGetDBSelection::Keep );
114  DBG_ASSERT(pDBData, "can't create DB data");
115  OUString sTarget = pDBData->GetName();
116 
117  UpdateImport( sTarget, aDesc );
118 }
119 
120 bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam,
121  const svx::ODataAccessDescriptor* pDescriptor )
122 {
123  ScDocument& rDoc = rDocShell.GetDocument();
124  ScChangeTrack *pChangeTrack = nullptr;
125  ScRange aChangedRange;
126 
127  bool bRecord = true;
128  if (!rDoc.IsUndoEnabled())
129  bRecord = false;
130 
131  ScDBData* pDBData = rDoc.GetDBAtArea( nTab, rParam.nCol1, rParam.nRow1,
132  rParam.nCol2, rParam.nRow2 );
133  if (!pDBData)
134  {
135  OSL_FAIL( "DoImport: no DBData" );
136  return false;
137  }
138 
139  std::unique_ptr<weld::WaitObject> xWaitWin(new weld::WaitObject(ScDocShell::GetActiveDialogParent()));
140  ScDocShellModificator aModificator( rDocShell );
141 
142  bool bSuccess = false;
143  bool bTruncated = false; // for warning
144  const char* pErrStringId = nullptr;
145  OUString aErrorMessage;
146 
147  SCCOL nCol = rParam.nCol1;
148  SCROW nRow = rParam.nRow1;
149  SCCOL nEndCol = nCol; // end of resulting database area
150  SCROW nEndRow = nRow;
151 
152  bool bDoSelection = false;
153  bool bRealSelection = false; // sal_True if not everything is selected
154  bool bBookmarkSelection = false;
155  sal_Int32 nListPos = 0;
156  sal_Int32 nRowsRead = 0;
157  sal_Int32 nListCount = 0;
158 
159  uno::Sequence<uno::Any> aSelection;
160  if ( pDescriptor && pDescriptor->has(svx::DataAccessDescriptorProperty::Selection) )
161  {
162  (*pDescriptor)[svx::DataAccessDescriptorProperty::Selection] >>= aSelection;
163  nListCount = aSelection.getLength();
164  if ( nListCount > 0 )
165  {
166  bDoSelection = true;
169  if ( bBookmarkSelection )
170  {
171  // From bookmarks, there's no way to detect if all records are selected.
172  // Rely on base to pass no selection in that case.
173  bRealSelection = true;
174  }
175  }
176  }
177 
178  uno::Reference<sdbc::XResultSet> xResultSet;
179  if ( pDescriptor && pDescriptor->has(svx::DataAccessDescriptorProperty::Cursor) )
180  xResultSet.set((*pDescriptor)[svx::DataAccessDescriptorProperty::Cursor], uno::UNO_QUERY);
181 
182  // ImportDoc - also used for Redo
183  ScDocumentUniquePtr pImportDoc(new ScDocument( SCDOCMODE_UNDO ));
184  pImportDoc->InitUndo( &rDoc, nTab, nTab );
185 
186  // get data from database into import document
187 
188  try
189  {
190  // progress bar
191  // only text (title is still needed, for the cancel button)
192  ScProgress aProgress( &rDocShell, ScResId(STR_UNDO_IMPORTDATA), 0, true );
193 
194  uno::Reference<sdbc::XRowSet> xRowSet( xResultSet, uno::UNO_QUERY );
195  bool bDispose = false;
196  if ( !xRowSet.is() )
197  {
198  bDispose = true;
201  uno::UNO_QUERY);
202  uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY );
203  OSL_ENSURE( xRowProp.is(), "can't get RowSet" );
204  if ( xRowProp.is() )
205  {
206 
207  // set source parameters
208 
209  sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND :
210  ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY :
212 
213  xRowProp->setPropertyValue( SC_DBPROP_DATASOURCENAME, uno::Any(rParam.aDBName) );
214 
215  xRowProp->setPropertyValue( SC_DBPROP_COMMAND, uno::Any(rParam.aStatement) );
216 
217  xRowProp->setPropertyValue( SC_DBPROP_COMMANDTYPE, uno::Any(nType) );
218 
219  uno::Reference<sdb::XCompletedExecution> xExecute( xRowSet, uno::UNO_QUERY );
220  if ( xExecute.is() )
221  {
222  uno::Reference<task::XInteractionHandler> xHandler(
223  task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), nullptr),
224  uno::UNO_QUERY_THROW);
225  xExecute->executeWithCompletion( xHandler );
226  }
227  else
228  xRowSet->execute();
229  }
230  }
231  if ( xRowSet.is() )
232  {
233 
234  // get column descriptions
235 
236  long nColCount = 0;
237  uno::Reference<sdbc::XResultSetMetaData> xMeta;
238  uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY );
239  if ( xMetaSupp.is() )
240  xMeta = xMetaSupp->getMetaData();
241  if ( xMeta.is() )
242  nColCount = xMeta->getColumnCount(); // this is the number of real columns
243 
244  if ( rParam.nCol1 + nColCount - 1 > rDoc.MaxCol() )
245  {
246  nColCount = 0;
248  }
249 
250  uno::Reference<sdbcx::XRowLocate> xLocate;
251  if ( bBookmarkSelection )
252  {
253  xLocate.set( xRowSet, uno::UNO_QUERY );
254  if ( !xLocate.is() )
255  {
256  SAL_WARN( "sc.ui","can't get XRowLocate");
257  bDoSelection = bRealSelection = bBookmarkSelection = false;
258  }
259  }
260 
261  uno::Reference<sdbc::XRow> xRow( xRowSet, uno::UNO_QUERY );
262  if ( nColCount > 0 && xRow.is() )
263  {
264  nEndCol = static_cast<SCCOL>( rParam.nCol1 + nColCount - 1 );
265 
266  uno::Sequence<sal_Int32> aColTypes( nColCount ); // column types
267  uno::Sequence<sal_Bool> aColCurr( nColCount ); // currency flag is not in types
268  sal_Int32* pTypeArr = aColTypes.getArray();
269  sal_Bool* pCurrArr = aColCurr.getArray();
270  for (long i=0; i<nColCount; i++)
271  {
272  pTypeArr[i] = xMeta->getColumnType( i+1 );
273  pCurrArr[i] = xMeta->isCurrency( i+1 );
274  }
275 
276  // read column names
277  nCol = rParam.nCol1;
278  for (long i=0; i<nColCount; i++)
279  {
280  pImportDoc->SetString( nCol, nRow, nTab,
281  xMeta->getColumnLabel( i+1 ) );
282  ++nCol;
283  }
284  ++nRow;
285 
286  bool bEnd = false;
287  if ( !bDoSelection )
288  xRowSet->beforeFirst();
289  sal_uInt16 nInserted = 0;
290  while ( !bEnd )
291  {
292  // skip rows that are not selected
293  if ( !bDoSelection )
294  {
295  bEnd = !xRowSet->next();
296  if ( !bEnd )
297  ++nRowsRead;
298  }
299  else
300  {
301  if (nListPos < nListCount)
302  {
303  if ( bBookmarkSelection )
304  {
305  bEnd = !xLocate->moveToBookmark(aSelection[nListPos]);
306  }
307  else // use record numbers
308  {
309  sal_Int32 nNextRow = 0;
310  aSelection[nListPos] >>= nNextRow;
311  if ( nRowsRead+1 < nNextRow )
312  bRealSelection = true;
313  nRowsRead = nNextRow;
314  bEnd = !xRowSet->absolute(nRowsRead);
315  }
316  ++nListPos;
317  }
318  else
319  {
320  if ( !bBookmarkSelection && xRowSet->next() )
321  bRealSelection = true; // more data available but not used
322  bEnd = true;
323  }
324  }
325 
326  if ( !bEnd )
327  {
328  if ( rDoc.ValidRow(nRow) )
329  {
330  nCol = rParam.nCol1;
331  for (long i=0; i<nColCount; i++)
332  {
333  ScDatabaseDocUtil::PutData( pImportDoc.get(), nCol, nRow, nTab,
334  xRow, i+1, pTypeArr[i], pCurrArr[i] );
335  ++nCol;
336  }
337  nEndRow = nRow;
338  ++nRow;
339 
340  // progress bar
341 
342  ++nInserted;
343  if (!(nInserted & 15))
344  {
345  aProgress.SetState( 0 );
346  }
347  }
348  else // past the end of the spreadsheet
349  {
350  bEnd = true; // don't continue
351  bTruncated = true; // warning flag
352  }
353  }
354  }
355 
356  bSuccess = true;
357  }
358 
359  if ( bDispose )
360  ::comphelper::disposeComponent( xRowSet );
361  }
362  }
363  catch ( const sdbc::SQLException& rError )
364  {
365  aErrorMessage = rError.Message;
366  }
367  catch ( uno::Exception& )
368  {
369  OSL_FAIL("Unexpected exception in database");
370  }
371 
372  // test for cell protection
373 
374  bool bKeepFormat = pDBData->IsKeepFmt();
375  bool bMoveCells = pDBData->IsDoSize();
376  SCCOL nFormulaCols = 0; // columns to be filled with formulas
377  if (bMoveCells && nEndCol == rParam.nCol2)
378  {
379  // if column count changes, formulas would become invalid anyway
380  // -> only set nFormulaCols for unchanged column count
381 
382  SCCOL nTestCol = rParam.nCol2 + 1; // right of the data
383  SCROW nTestRow = rParam.nRow1 + 1; // below the title row
384  while ( nTestCol <= rDoc.MaxCol() &&
385  rDoc.GetCellType(ScAddress( nTestCol, nTestRow, nTab )) == CELLTYPE_FORMULA )
386  {
387  ++nTestCol;
388  ++nFormulaCols;
389  }
390  }
391 
392  if (bSuccess)
393  {
394  // old and new range editable?
395  ScEditableTester aTester;
396  aTester.TestBlock( &rDoc, nTab, rParam.nCol1,rParam.nRow1,rParam.nCol2,rParam.nRow2 );
397  aTester.TestBlock( &rDoc, nTab, rParam.nCol1,rParam.nRow1,nEndCol,nEndRow );
398  if ( !aTester.IsEditable() )
399  {
400  pErrStringId = aTester.GetMessageId();
401  bSuccess = false;
402  }
403  else if ( (pChangeTrack = rDoc.GetChangeTrack()) != nullptr )
404  aChangedRange = ScRange(rParam.nCol1, rParam.nRow1, nTab,
405  nEndCol+nFormulaCols, nEndRow, nTab );
406  }
407 
408  if ( bSuccess && bMoveCells )
409  {
410  ScRange aOld( rParam.nCol1, rParam.nRow1, nTab,
411  rParam.nCol2+nFormulaCols, rParam.nRow2, nTab );
412  ScRange aNew( rParam.nCol1, rParam.nRow1, nTab,
413  nEndCol+nFormulaCols, nEndRow, nTab );
414  if (!rDoc.CanFitBlock( aOld, aNew ))
415  {
416  pErrStringId = STR_MSSG_DOSUBTOTALS_2; // can't insert cells
417  bSuccess = false;
418  }
419  }
420 
421  // copy data from import doc into real document
422 
423  if ( bSuccess )
424  {
425  if (bKeepFormat)
426  {
427  // keep formatting of title and first data row from the document
428  // CopyToDocument also copies styles, Apply... needs separate calls
429 
430  SCCOL nMinEndCol = std::min( rParam.nCol2, nEndCol ); // not too much
431  nMinEndCol = sal::static_int_cast<SCCOL>( nMinEndCol + nFormulaCols ); // only if column count unchanged
432  pImportDoc->DeleteAreaTab( 0,0, rDoc.MaxCol(),rDoc.MaxRow(), nTab, InsertDeleteFlags::ATTRIB );
433  rDoc.CopyToDocument(rParam.nCol1, rParam.nRow1, nTab,
434  nMinEndCol, rParam.nRow1, nTab,
435  InsertDeleteFlags::ATTRIB, false, *pImportDoc);
436 
437  SCROW nDataStartRow = rParam.nRow1+1;
438  for (SCCOL nCopyCol=rParam.nCol1; nCopyCol<=nMinEndCol; nCopyCol++)
439  {
440  const ScPatternAttr* pSrcPattern = rDoc.GetPattern(
441  nCopyCol, nDataStartRow, nTab );
442  pImportDoc->ApplyPatternAreaTab( nCopyCol, nDataStartRow, nCopyCol, nEndRow,
443  nTab, *pSrcPattern );
444  const ScStyleSheet* pStyle = pSrcPattern->GetStyleSheet();
445  if (pStyle)
446  pImportDoc->ApplyStyleAreaTab( nCopyCol, nDataStartRow, nCopyCol, nEndRow,
447  nTab, *pStyle );
448  }
449  }
450 
451  // don't set cell protection attribute if table is protected
452  if (rDoc.IsTabProtected(nTab))
453  {
454  ScPatternAttr aPattern(pImportDoc->GetPool());
455  aPattern.GetItemSet().Put( ScProtectionAttr( false,false,false,false ) );
456  pImportDoc->ApplyPatternAreaTab( 0,0,rDoc.MaxCol(),rDoc.MaxRow(), nTab, aPattern );
457  }
458 
459  // copy old data for undo
460 
461  SCCOL nUndoEndCol = std::max( nEndCol, rParam.nCol2 ); // rParam = old end
462  SCROW nUndoEndRow = std::max( nEndRow, rParam.nRow2 );
463 
464  ScDocumentUniquePtr pUndoDoc;
465  std::unique_ptr<ScDBData> pUndoDBData;
466  if ( bRecord )
467  {
468  pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
469  pUndoDoc->InitUndo( &rDoc, nTab, nTab );
470 
471  pUndoDBData.reset(new ScDBData( *pDBData ));
472  }
473 
474  ScMarkData aNewMark(rDoc.GetSheetLimits());
475  aNewMark.SelectOneTable( nTab );
476 
477  if (bRecord)
478  {
479  // do not touch notes (ScUndoImportData does not support drawing undo)
481 
482  // nFormulaCols is set only if column count is unchanged
483  rDoc.CopyToDocument(rParam.nCol1, rParam.nRow1, nTab,
484  nEndCol+nFormulaCols, nEndRow, nTab,
485  nCopyFlags, false, *pUndoDoc);
486  if ( rParam.nCol2 > nEndCol )
487  rDoc.CopyToDocument(nEndCol+1, rParam.nRow1, nTab,
488  nUndoEndCol, nUndoEndRow, nTab,
489  nCopyFlags, false, *pUndoDoc);
490  if ( rParam.nRow2 > nEndRow )
491  rDoc.CopyToDocument(rParam.nCol1, nEndRow+1, nTab,
492  nUndoEndCol+nFormulaCols, nUndoEndRow, nTab,
493  nCopyFlags, false, *pUndoDoc);
494  }
495 
496  // move new data
497 
498  if (bMoveCells)
499  {
500  // clear only the range without the formulas,
501  // so the formula title and first row are preserved
502 
503  ScRange aDelRange( rParam.nCol1, rParam.nRow1, nTab,
504  rParam.nCol2, rParam.nRow2, nTab );
505  rDoc.DeleteAreaTab( aDelRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); // without the formulas
506 
507  ScRange aOld( rParam.nCol1, rParam.nRow1, nTab,
508  rParam.nCol2+nFormulaCols, rParam.nRow2, nTab );
509  ScRange aNew( rParam.nCol1, rParam.nRow1, nTab,
510  nEndCol+nFormulaCols, nEndRow, nTab );
511  rDoc.FitBlock( aOld, aNew, false ); // Do not delete formulas
512  }
513  else if ( nEndCol < rParam.nCol2 ) // DeleteArea calls PutInOrder
514  rDoc.DeleteArea( nEndCol+1, rParam.nRow1, rParam.nCol2, rParam.nRow2,
516 
517  // CopyToDocument doesn't remove contents
518  rDoc.DeleteAreaTab( rParam.nCol1, rParam.nRow1, nEndCol, nEndRow, nTab, InsertDeleteFlags::CONTENTS & ~InsertDeleteFlags::NOTE );
519 
520  // remove each column from ImportDoc after copying to reduce memory usage
521  bool bOldAutoCalc = rDoc.GetAutoCalc();
522  rDoc.SetAutoCalc( false ); // outside of the loop
523  for (SCCOL nCopyCol = rParam.nCol1; nCopyCol <= nEndCol; nCopyCol++)
524  {
525  pImportDoc->CopyToDocument(nCopyCol, rParam.nRow1, nTab, nCopyCol, nEndRow, nTab,
526  InsertDeleteFlags::ALL, false, rDoc);
527  pImportDoc->DeleteAreaTab( nCopyCol, rParam.nRow1, nCopyCol, nEndRow, nTab, InsertDeleteFlags::CONTENTS );
528  }
529  rDoc.SetAutoCalc( bOldAutoCalc );
530 
531  if (nFormulaCols > 0) // copy formulas
532  {
533  if (bKeepFormat) // formats for formulas
534  pImportDoc->CopyToDocument(nEndCol+1, rParam.nRow1, nTab,
535  nEndCol+nFormulaCols, nEndRow, nTab,
536  InsertDeleteFlags::ATTRIB, false, rDoc);
537  // fill formulas
538  ScMarkData aMark(rDoc.GetSheetLimits());
539  aMark.SelectOneTable(nTab);
540 
541  sal_uLong nProgCount = nFormulaCols;
542  nProgCount *= nEndRow-rParam.nRow1-1;
543  ScProgress aProgress( rDoc.GetDocumentShell(),
544  ScResId(STR_FILL_SERIES_PROGRESS), nProgCount, true );
545 
546  rDoc.Fill( nEndCol+1, rParam.nRow1+1, nEndCol+nFormulaCols, rParam.nRow1+1,
547  &aProgress, aMark, nEndRow-rParam.nRow1-1, FILL_TO_BOTTOM, FILL_SIMPLE );
548  }
549 
550  // if new range is smaller, clear old contents
551 
552  if (!bMoveCells) // move has happened above
553  {
554  if ( rParam.nCol2 > nEndCol )
555  rDoc.DeleteArea( nEndCol+1, rParam.nRow1, rParam.nCol2, rParam.nRow2,
556  aNewMark, InsertDeleteFlags::CONTENTS );
557  if ( rParam.nRow2 > nEndRow )
558  rDoc.DeleteArea( rParam.nCol1, nEndRow+1, rParam.nCol2, rParam.nRow2,
559  aNewMark, InsertDeleteFlags::CONTENTS );
560  }
561 
562  // update database range
563  pDBData->SetImportParam( rParam );
564  pDBData->SetHeader( true );
565  pDBData->SetByRow( true );
566  pDBData->SetArea( nTab, rParam.nCol1,rParam.nRow1, nEndCol,nEndRow );
567  pDBData->SetImportSelection( bRealSelection );
568  rDoc.CompileDBFormula();
569 
570  if (bRecord)
571  {
572  ScDocumentUniquePtr pRedoDoc = std::move(pImportDoc);
573 
574  if (nFormulaCols > 0) // include filled formulas for redo
575  rDoc.CopyToDocument(rParam.nCol1, rParam.nRow1, nTab,
576  nEndCol+nFormulaCols, nEndRow, nTab,
577  InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, *pRedoDoc);
578 
579  std::unique_ptr<ScDBData> pRedoDBData(new ScDBData(*pDBData));
580 
581  rDocShell.GetUndoManager()->AddUndoAction(
582  std::make_unique<ScUndoImportData>( &rDocShell, nTab,
583  rParam, nUndoEndCol, nUndoEndRow,
584  nFormulaCols,
585  std::move(pUndoDoc), std::move(pRedoDoc),
586  std::move(pUndoDBData), std::move(pRedoDBData) ) );
587  }
588 
590  rDoc.SetAllFormulasDirty(aCxt);
591  rDocShell.PostPaint(ScRange(0, 0, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab), PaintPartFlags::Grid);
592  aModificator.SetDocumentModified();
593 
594  ScDBRangeRefreshedHint aHint( rParam );
595  rDoc.BroadcastUno( aHint );
596 
597  xWaitWin.reset();
598 
599  if ( bTruncated ) // show warning
601  }
602  else
603  {
604  xWaitWin.reset();
605 
606  if (aErrorMessage.isEmpty())
607  {
608  if (!pErrStringId)
609  pErrStringId = STR_MSSG_IMPORTDATA_0;
610  aErrorMessage = ScResId(pErrStringId);
611  }
612 
613  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(ScDocShell::GetActiveDialogParent(),
614  VclMessageType::Info, VclButtonsType::Ok,
615  aErrorMessage));
616  xInfoBox->run();
617  }
618 
619  pImportDoc.reset();
620 
621  if (bSuccess && pChangeTrack)
622  pChangeTrack->AppendInsert ( aChangedRange );
623 
624  return bSuccess;
625 }
626 
627 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const int nColCount
bool CanFitBlock(const ScRange &rOld, const ScRange &rNew)
Definition: document.cxx:1830
#define SC_DBPROP_DATASOURCENAME
move to a header file?
Definition: dbdocimp.cxx:67
void FitBlock(const ScRange &rOld, const ScRange &rNew, bool bClear=true)
Definition: document.cxx:1861
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1871
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void SetImportSelection(bool bSet)
Definition: dbdata.hxx:202
void setDataSource(const OUString &_sDataSourceNameOrLocation)
OUString aDBName
Definition: global.hxx:455
static weld::Window * GetActiveDialogParent()
Definition: docsh.cxx:2949
sal_uIntPtr sal_uLong
Reference< XFrame > xFrame
bool DoImport(SCTAB nTab, const ScImportParam &rParam, const svx::ODataAccessDescriptor *pDescriptor)
Definition: dbdocimp.cxx:120
const SfxItemSet & GetItemSet() const
#define SCWARN_IMPORT_RANGE_OVERFLOW
Definition: scerrors.hxx:62
const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: documen3.cxx:319
static void ShowInBeamer(const ScImportParam &rParam, const SfxViewFrame *pFrame)
Definition: dbdocimp.cxx:71
create "Importx" (if necessary)
Definition: global.hxx:394
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
SCROW nRow2
Definition: global.hxx:453
SC_DLLPUBLIC void Fill(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScProgress *pProgress, const ScMarkData &rMark, sal_uLong nFillCount, FillDir eFillDir=FILL_TO_BOTTOM, FillCmd eFillCmd=FILL_LINEAR, FillDateCmd eFillDateCmd=FILL_DAY, double nStepValue=1.0, double nMaxValue=1E307)
Definition: documen3.cxx:1134
bool IsDoSize() const
Definition: dbdata.hxx:136
Internal use only (d&d undo): do not delete caption objects of cell notes.
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: document.cxx:3837
Keep selection as is, expand to used data area if no selection.
#define SC_DBPROP_COMMANDTYPE
Definition: dbdocimp.cxx:69
Reference< XController > xController
void SetImportParam(const ScImportParam &rImportParam)
Definition: dbdata.cxx:476
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:876
SfxFrame & GetFrame() const
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)
Definition: document.cxx:2075
SCCOL nCol2
Definition: global.hxx:452
uno::Reference< sdbc::XRow > xRow
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4737
SCROW nRow1
Definition: global.hxx:451
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2397
#define SC_SERVICE_ROWSET
Definition: dbdocimp.cxx:64
void SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: dbdata.cxx:323
const char * GetMessageId() const
Definition: editable.cxx:152
OUString aStatement
Definition: global.hxx:456
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:875
#define DBG_ASSERT(sCon, aError)
int i
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2618
sal_Int16 SCCOL
Definition: types.hxx:22
InsertDeleteFlags
Definition: global.hxx:158
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
SC_DLLPUBLIC void SetAutoCalc(bool bNewAutoCalc)
Definition: documen7.cxx:602
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:877
void DoImportUno(const ScAddress &rPos, const css::uno::Sequence< css::beans::PropertyValue > &aArgs)
Definition: dbdocimp.cxx:107
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
void SelectOneTable(SCTAB nTab)
Definition: markdata.cxx:189
unsigned char sal_Bool
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
const OUString & GetName() const
Definition: dbdata.hxx:122
bool IsKeepFmt() const
Definition: dbdata.hxx:138
void BroadcastUno(const SfxHint &rHint)
Definition: documen3.cxx:930
bool IsEditable() const
Definition: editable.hxx:84
void CompileDBFormula()
Definition: documen4.cxx:556
void SetHeader(bool bHasH)
Definition: dbdata.hxx:131
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
void SetByRow(bool bByR)
Definition: dbdata.hxx:129
void SetState(sal_uLong nVal, sal_uLong nNewRange=0)
Definition: progress.hxx:79
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:18
Reference< XMultiServiceFactory > getProcessServiceFactory()
bool ValidRow(SCROW nRow) const
Definition: document.hxx:879
bool has(DataAccessDescriptorProperty _eWhich) const
sal_uInt8 nType
Definition: global.hxx:459
static void PutData(ScDocument *pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const css::uno::Reference< css::sdbc::XRow > &xRow, long nRowPos, long nType, bool bCurrency, StrData *pStrData=nullptr)
Definition: dbdocutl.cxx:37
Any makeAny(Color const &value)
void DeleteArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const ScMarkData &rMark, InsertDeleteFlags nDelFlag, bool bBroadcast=true, sc::ColumnSpanSet *pBroadcastSpans=nullptr)
Definition: document.cxx:1893
void TestBlock(const ScDocument *pDoc, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll=false)
Definition: editable.cxx:82
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
bool bImport
Definition: global.hxx:454
void SetDocumentModified()
Definition: docsh.cxx:3158
SCCOL nCol1
Definition: global.hxx:450
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1061
#define SAL_WARN(area, stream)
bool IsUndoEnabled() const
Definition: document.hxx:1534
SC_DLLPUBLIC void AppendInsert(const ScRange &rRange, bool bEndOfList=false)
Definition: chgtrack.cxx:2801
static bool GetBoolFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:138
#define SC_DBPROP_COMMAND
Definition: dbdocimp.cxx:68
SC_DLLPUBLIC void DeleteAreaTab(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, InsertDeleteFlags nDelFlag)
Definition: document.cxx:1954
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:450
SC_DLLPUBLIC void GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab, CellType &rCellType) const
Definition: document.cxx:3749
sal_Int16 SCTAB
Definition: types.hxx:23
SC_DLLPUBLIC bool GetAutoCalc() const
Definition: document.hxx:1363