/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
xControllerSelection->select(uno::Any(aSelection.createPropertyValueSequence()));
} else
{
OSL_FAIL("no selection supplier in the beamer!");
}
}
void ScDBDocFunc::DoImportUno( const ScAddress& rPos, const uno::Sequence<beans::PropertyValue>& aArgs )
{
svx::ODataAccessDescriptor aDesc( aArgs ); // includes selection and result set
uno::Sequence<uno::Any> aSelection; if ( pDescriptor && pDescriptor->has(svx::DataAccessDescriptorProperty::Selection) )
{
(*pDescriptor)[svx::DataAccessDescriptorProperty::Selection] >>= aSelection;
nListCount = aSelection.getLength(); if ( nListCount > 0 )
{
bDoSelection = true; if ( pDescriptor->has(svx::DataAccessDescriptorProperty::BookmarkSelection) )
bBookmarkSelection = ScUnoHelpFunctions::GetBoolFromAny( (*pDescriptor)[svx::DataAccessDescriptorProperty::BookmarkSelection] ); if ( bBookmarkSelection )
{ // From bookmarks, there's no way to detect if all records are selected. // Rely on base to pass no selection in that case.
bRealSelection = true;
}
}
}
uno::Reference<sdbc::XResultSet> xResultSet; if ( pDescriptor && pDescriptor->has(svx::DataAccessDescriptorProperty::Cursor) )
xResultSet.set((*pDescriptor)[svx::DataAccessDescriptorProperty::Cursor], uno::UNO_QUERY);
// ImportDoc - also used for Redo
ScDocumentUniquePtr pImportDoc(new ScDocument( SCDOCMODE_UNDO ));
pImportDoc->InitUndo( rDoc, nTab, nTab );
// get data from database into import document
try
{ // progress bar // only text (title is still needed, for the cancel button)
ScProgress aProgress( &rDocShell, ScResId(STR_UNDO_IMPORTDATA), 0, true );
sal_Int32 nColCount = 0;
uno::Reference<sdbc::XResultSetMetaData> xMeta;
uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY ); if ( xMetaSupp.is() )
xMeta = xMetaSupp->getMetaData(); if ( xMeta.is() )
nColCount = xMeta->getColumnCount(); // this is the number of real columns
bool bEnd = false; if ( !bDoSelection )
xRowSet->beforeFirst();
sal_uInt16 nInserted = 0; while ( !bEnd )
{ // skip rows that are not selected if ( !bDoSelection )
{
bEnd = !xRowSet->next(); if ( !bEnd )
++nRowsRead;
} else
{ if (nListPos < nListCount)
{ if ( bBookmarkSelection )
{
bEnd = !xLocate->moveToBookmark(aSelection[nListPos]);
} else// use record numbers
{
sal_Int32 nNextRow = 0;
aSelection[nListPos] >>= nNextRow; if ( nRowsRead+1 < nNextRow )
bRealSelection = true;
nRowsRead = nNextRow;
bEnd = !xRowSet->absolute(nRowsRead);
}
++nListPos;
} else
{ if ( !bBookmarkSelection && xRowSet->next() )
bRealSelection = true; // more data available but not used
bEnd = true;
}
}
++nInserted; if (!(nInserted & 15))
{
aProgress.SetState( 0 );
}
} else// past the end of the spreadsheet
{
bEnd = true; // don't continue
bTruncated = true; // warning flag
}
}
}
bool bKeepFormat = pDBData->IsKeepFmt(); bool bMoveCells = pDBData->IsDoSize();
SCCOL nFormulaCols = 0; // columns to be filled with formulas if (bMoveCells && nEndCol == rParam.nCol2)
{ // if column count changes, formulas would become invalid anyway // -> only set nFormulaCols for unchanged column count
SCCOL nTestCol = rParam.nCol2 + 1; // right of the data
SCROW nTestRow = rParam.nRow1 + 1; // below the title row while ( nTestCol <= rDoc.MaxCol() &&
rDoc.GetCellType(ScAddress( nTestCol, nTestRow, nTab )) == CELLTYPE_FORMULA )
{
++nTestCol;
++nFormulaCols;
}
}
if (bSuccess)
{ // old and new range editable?
ScEditableTester aTester;
aTester.TestBlock( rDoc, nTab, rParam.nCol1,rParam.nRow1,rParam.nCol2,rParam.nRow2 );
aTester.TestBlock( rDoc, nTab, rParam.nCol1,rParam.nRow1,nEndCol,nEndRow ); if ( !aTester.IsEditable() )
{
pErrStringId = aTester.GetMessageId();
bSuccess = false;
} elseif ( (pChangeTrack = rDoc.GetChangeTrack()) != nullptr )
aChangedRange = ScRange(rParam.nCol1, rParam.nRow1, nTab,
nEndCol+nFormulaCols, nEndRow, nTab );
}
if ( bSuccess )
{ if (bKeepFormat)
{ // keep formatting of title and first data row from the document // CopyToDocument also copies styles, Apply... needs separate calls
SCCOL nMinEndCol = std::min( rParam.nCol2, nEndCol ); // not too much
nMinEndCol = sal::static_int_cast<SCCOL>( nMinEndCol + nFormulaCols ); // only if column count unchanged
pImportDoc->DeleteAreaTab( 0,0, rDoc.MaxCol(),rDoc.MaxRow(), nTab, InsertDeleteFlags::ATTRIB );
rDoc.CopyToDocument(rParam.nCol1, rParam.nRow1, nTab,
nMinEndCol, rParam.nRow1, nTab,
InsertDeleteFlags::ATTRIB, false, *pImportDoc);
if (bRecord)
{ // do not touch notes (ScUndoImportData does not support drawing undo)
InsertDeleteFlags nCopyFlags = InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE;
// nFormulaCols is set only if column count is unchanged
rDoc.CopyToDocument(rParam.nCol1, rParam.nRow1, nTab,
nEndCol+nFormulaCols, nEndRow, nTab,
nCopyFlags, false, *pUndoDoc); if ( rParam.nCol2 > nEndCol )
rDoc.CopyToDocument(nEndCol+1, rParam.nRow1, nTab,
nUndoEndCol, nUndoEndRow, nTab,
nCopyFlags, false, *pUndoDoc); if ( rParam.nRow2 > nEndRow )
rDoc.CopyToDocument(rParam.nCol1, nEndRow+1, nTab,
nUndoEndCol+nFormulaCols, nUndoEndRow, nTab,
nCopyFlags, false, *pUndoDoc);
}
// move new data
if (bMoveCells)
{ // clear only the range without the formulas, // so the formula title and first row are preserved
ScRange aDelRange( rParam.nCol1, rParam.nRow1, nTab,
rParam.nCol2, rParam.nRow2, nTab );
rDoc.DeleteAreaTab( aDelRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); // without the formulas
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.