26#include <com/sun/star/sdb/CommandType.hpp>
27#include <com/sun/star/sdb/XDocumentDataSource.hpp>
28#include <com/sun/star/lang/DisposedException.hpp>
29#include <com/sun/star/lang/XEventListener.hpp>
30#include <com/sun/star/uri/UriReferenceFactory.hpp>
31#include <com/sun/star/uri/VndSunStarPkgUrlReferenceFactory.hpp>
32#include <com/sun/star/util/NumberFormatter.hpp>
33#include <com/sun/star/sdb/DatabaseContext.hpp>
34#include <com/sun/star/sdb/TextConnectionSettings.hpp>
35#include <com/sun/star/sdb/XCompletedConnection.hpp>
36#include <com/sun/star/sdb/XCompletedExecution.hpp>
37#include <com/sun/star/container/XChild.hpp>
38#include <com/sun/star/text/MailMergeEvent.hpp>
39#include <com/sun/star/frame/XStorable.hpp>
40#include <com/sun/star/task/InteractionHandler.hpp>
41#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
42#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
43#include <com/sun/star/beans/XPropertySet.hpp>
77#include <com/sun/star/sdbc/XRowSet.hpp>
78#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
79#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
80#include <com/sun/star/sdb/XQueriesSupplier.hpp>
81#include <com/sun/star/sdb/XColumn.hpp>
82#include <com/sun/star/sdbc/DataType.hpp>
83#include <com/sun/star/sdbc/ResultSetType.hpp>
84#include <com/sun/star/sdbc/SQLException.hpp>
85#include <com/sun/star/mail/MailAttachment.hpp>
96#include <com/sun/star/util/XNumberFormatTypes.hpp>
106#include <rtl/textenc.h>
107#include <rtl/tencinfo.h>
114#include <section.hxx>
140OUString ConstructVndSunStarPkgUrl(
const OUString& rMainURL, std::u16string_view rStreamRelPath)
143 auto xUri = css::uri::UriReferenceFactory::create(xContext)->parse(rMainURL);
145 xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)
146 ->createVndSunStarPkgUrlReference(xUri);
148 return xUri->getUriReference() +
"/"
160enum class SwDBNextRecord {
NEXT,
FIRST };
168enum class WorkingDocType { SOURCE,
TARGET,
COPY };
173 const WorkingDocType aType,
const SwWrtShell &rSourceWrtShell,
184 uno::Reference<beans::XPropertySet> xPrSet(pParam->
xResultSet, uno::UNO_QUERY);
190 uno::Any aFinal = xPrSet->getPropertyValue(
"IsRowCountFinal");
197 uno::Any aCount = xPrSet->getPropertyValue(
"RowCount");
198 if( aCount >>= rCount )
201 catch(
const uno::Exception&)
209 :
public cppu::WeakImplHelper< lang::XEventListener >
214 virtual void SAL_CALL
disposing(
const lang::EventObject& Source )
override;
226class SwDataSourceRemovedListener :
public cppu::WeakImplHelper<sdb::XDatabaseRegistrationsListener>
228 uno::Reference<sdb::XDatabaseContext> m_xDatabaseContext;
232 explicit SwDataSourceRemovedListener(
SwDBManager& rDBManager);
233 virtual ~SwDataSourceRemovedListener()
override;
234 virtual void SAL_CALL registeredDatabaseLocation(
const sdb::DatabaseRegistrationEvent& rEvent)
override;
235 virtual void SAL_CALL revokedDatabaseLocation(
const sdb::DatabaseRegistrationEvent& rEvent)
override;
236 virtual void SAL_CALL changedDatabaseLocation(
const sdb::DatabaseRegistrationEvent& rEvent)
override;
237 virtual void SAL_CALL disposing(
const lang::EventObject& rObject)
override;
243SwDataSourceRemovedListener::SwDataSourceRemovedListener(
SwDBManager& rDBManager)
244 : m_pDBManager(&rDBManager)
247 m_xDatabaseContext = sdb::DatabaseContext::create(xComponentContext);
248 m_xDatabaseContext->addDatabaseRegistrationsListener(
this);
251SwDataSourceRemovedListener::~SwDataSourceRemovedListener()
253 if (m_xDatabaseContext.is())
254 m_xDatabaseContext->removeDatabaseRegistrationsListener(
this);
257void SAL_CALL SwDataSourceRemovedListener::registeredDatabaseLocation(
const sdb::DatabaseRegistrationEvent& )
261void SAL_CALL SwDataSourceRemovedListener::revokedDatabaseLocation(
const sdb::DatabaseRegistrationEvent& rEvent)
263 if (!m_pDBManager || m_pDBManager->getEmbeddedName().isEmpty())
266 SwDoc* pDoc = m_pDBManager->getDoc();
274 const OUString sTmpName = ConstructVndSunStarPkgUrl(
276 m_pDBManager->getEmbeddedName());
278 if (sTmpName != rEvent.OldLocation)
284 pDocShell->
GetStorage()->removeElement(m_pDBManager->getEmbeddedName());
285 m_pDBManager->setEmbeddedName(OUString(), *pDocShell);
288void SAL_CALL SwDataSourceRemovedListener::changedDatabaseLocation(
const sdb::DatabaseRegistrationEvent& rEvent)
290 if (rEvent.OldLocation != rEvent.NewLocation)
291 revokedDatabaseLocation(rEvent);
294void SwDataSourceRemovedListener::disposing(
const lang::EventObject& )
296 m_xDatabaseContext.clear();
299void SwDataSourceRemovedListener::Dispose()
301 m_pDBManager =
nullptr;
327 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
328 rParam.
xFormatter = util::NumberFormatter::create(xContext);
329 uno::Reference<beans::XPropertySet> xSourceProps(
335 if(!xSourceProps.is())
338 uno::Any aFormats = xSourceProps->getPropertyValue(
"NumberFormatsSupplier");
342 uno::Reference<util::XNumberFormatsSupplier> xSuppl;
346 uno::Reference< beans::XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
347 uno::Any aNull = xSettings->getPropertyValue(
"NullDate");
350 rParam.
xFormatter->attachNumberFormatsSupplier(xSuppl);
377 bRet = pParam->
xResultSet->absolute( nAbsPos );
381 OSL_FAIL(
"no absolute positioning available");
384 catch(
const uno::Exception&)
391 const uno::Reference< beans::XPropertySet > &rColumnProps,
392 LanguageType nLanguage, OUString &rResult,
double* pNumber)
410 LanguageType nLanguage, OUString& rResult,
double* pNumber)
412 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( pParam->
xResultSet, uno::UNO_QUERY );
413 uno::Reference<container::XNameAccess> xCols;
416 xCols = xColsSupp->getColumns();
418 catch(
const lang::DisposedException&)
421 if(!xCols.is() || !xCols->hasByName(rColumnName))
423 uno::Any aCol = xCols->getByName(rColumnName);
424 uno::Reference< beans::XPropertySet > xColumnProps;
425 aCol >>= xColumnProps;
450 pWorkDocOrigDBManager =
this;
452 WorkingDocType::SOURCE, rMergeDesc.
rSh,
nullptr,
453 &pWorkDocOrigDBManager,
nullptr, &pWorkShell, &pWorkDoc );
459 if( !xWorkObjSh.
Is() )
460 pWorkShell = &rMergeDesc.
rSh;
465 aData.nCommandType = sdb::CommandType::TABLE;
466 uno::Reference<sdbc::XResultSet> xResSet;
467 uno::Sequence<uno::Any> aSelection;
468 uno::Reference< sdbc::XConnection> xConnection;
481 if((
aData.sDataSource.isEmpty() ||
aData.sCommand.isEmpty()) && !xResSet.is())
495 aData.nCommandType = -1;
504 uno::Reference<lang::XComponent> xComponent(
m_DataSourceParams.back()->xConnection, uno::UNO_QUERY);
506 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
508 catch(
const uno::Exception&)
513 if(!
m_pImpl->pMergeData->xConnection.is())
514 m_pImpl->pMergeData->xConnection = xConnection;
529 std::vector<OUString> aDBNames;
530 aDBNames.emplace_back();
545 pWorkShell->SwViewShell::UpdateFields(
true );
567 if( xWorkObjSh.
Is() )
569 pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
591 std::optional<SwWait> oWait;
614 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(
m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
615 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
617 uno::Sequence<OUString>
aColNames = xCols->getElementNames();
618 const OUString* pColNames =
aColNames.getConstArray();
622 uno::Any aCol = xCols->getByName(pColNames[
i]);
623 uno::Reference< beans::XPropertySet > xColumnProp;
624 aCol >>= xColumnProp;
626 sStr.append(
GetDBField( xColumnProp, aDBFormat));
630 pSh->SwEditShell::Insert2(sStr.makeStringAndClear());
631 pSh->SwFEShell::SplitNode();
640 uno::Reference< sdbc::XConnection> xConnection;
645 if ( !rDBName.isEmpty() )
648 if (xConnection.is())
650 uno::Reference<sdbcx::XTablesSupplier> xTSupplier(xConnection, uno::UNO_QUERY);
653 uno::Reference<container::XNameAccess> xTables = xTSupplier->getTables();
654 const uno::Sequence<OUString> aTables = xTables->getElementNames();
655 for (
const OUString& rTable : aTables)
658 uno::Reference<sdb::XQueriesSupplier> xQSupplier(xConnection, uno::UNO_QUERY);
661 uno::Reference<container::XNameAccess> xQueries = xQSupplier->getQueries();
662 const uno::Sequence<OUString> aQueries = xQueries->getElementNames();
663 for (
const OUString& rQuery : aQueries)
666 if (!sOldTableName.isEmpty())
675 const OUString& rDBName,
const OUString& rTableName)
678 aData.sDataSource = rDBName;
679 aData.sCommand = rTableName;
680 aData.nCommandType = -1;
682 uno::Reference< sdbc::XConnection> xConnection;
693 uno::Reference< sdbc::XConnection>
const & xConnection,
694 const OUString& rTableName)
700 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
701 const uno::Sequence<OUString>
aColNames = xCols->getElementNames();
702 for (
const OUString& rColName : aColNames)
706 ::comphelper::disposeComponent( xColsSupp );
726 std::vector<uno::Reference<sdbc::XConnection>> aCopiedConnections;
729 if(pParam->xConnection.is())
731 aCopiedConnections.push_back(pParam->xConnection);
734 for (
const auto & xConnection : aCopiedConnections)
738 uno::Reference<lang::XComponent> xComp(xConnection, uno::UNO_QUERY);
742 catch(
const uno::RuntimeException&)
758 for (
size_t nSection = 0; nSection < nSections; ++nSection)
772 const char *name,
int no = 0 )
774 static OUString sTempDirURL;
775 if( sTempDirURL.isEmpty() )
783 SAL_INFO(
"sw.mailmerge",
"Dump directory: " << sTempDirURL );
786 if( sTempDirURL.isEmpty() )
789 OUString basename = OUString::createFromAscii(
name );
791 basename += OUString::number(no) +
"-";
795 auto pDstMed = std::make_unique<SfxMedium>(
797 StreamMode::STD_READWRITE );
798 bool bAnyError = !xTargetDocShell->
DoSaveAs( *pDstMed );
802 SAL_WARN(
"sw.mailmerge",
"Error saving: " << aTempFile.
GetURL() );
804 SAL_INFO(
"sw.mailmerge",
"Saved doc as: " << aTempFile.
GetURL() );
809 const std::shared_ptr<const SfxFilter>& pStoreToFilter,
810 const OUString* pStoreToFilterOptions,
811 const uno::Sequence< beans::PropertyValue >* pSaveToFilterData,
812 const bool bIsPDFexport,
815 OUString *
const decodedURL =
nullptr )
823 if( pStoreToFilterOptions )
825 *pStoreToFilterOptions));
826 if( pSaveToFilterData->hasElements() )
836 bool bAnyError = !xObjectShell->
DoSaveAs(*pDstMed);
850 const uno::Sequence< beans::PropertyValue >& rInPrintOptions,
851 uno::Sequence< beans::PropertyValue >& rOutPrintOptions)
860 for(
const beans::PropertyValue& rOption : rInPrintOptions)
862 if( rOption.Name ==
"CopyCount" || rOption.Name ==
"FileName"
863 || rOption.Name ==
"Collate" || rOption.Name ==
"Pages"
864 || rOption.Name ==
"Wait" || rOption.Name ==
"PrinterName" )
867 rOutPrintOptions.realloc(
nIndex + 1 );
868 auto pOutPrintOptions = rOutPrintOptions.getArray();
869 pOutPrintOptions[
nIndex ].Name = rOption.Name;
870 pOutPrintOptions[
nIndex++ ].Value = rOption.Value ;
876 const uno::Sequence< beans::PropertyValue >& rInSaveFilterDataptions,
877 uno::Sequence< beans::PropertyValue >& rOutSaveFilterDataOptions,
878 const OUString& sPassword)
880 rOutSaveFilterDataOptions
886 for(
const beans::PropertyValue& rOption : rInSaveFilterDataptions)
888 rOutSaveFilterDataOptions.realloc(
nIndex + 1 );
889 auto pOutSaveFilterDataOptions = rOutSaveFilterDataOptions.getArray();
890 pOutSaveFilterDataOptions[
nIndex ].Name = rOption.Name;
891 pOutSaveFilterDataOptions[
nIndex++ ].Value = rOption.Value ;
899 const WorkingDocType aType,
const SwWrtShell &rSourceWrtShell,
907 const SwDoc *pSourceDoc = rSourceWrtShell.
GetDoc();
922 pWorkWrtShell->GetViewOptions()->SetIdle(
false );
923 pWorkView->AttrChangedNotify(
nullptr);
924 SwDoc* pWorkDoc = pWorkWrtShell->GetDoc();
935 if( aType == WorkingDocType::TARGET )
937 assert( !ppDBManager );
939 pWorkWrtShell->SetLabelDoc(
false );
944 assert(ppDBManager && *ppDBManager);
947 *ppDBManager = pWorkDBManager;
949 if( aType == WorkingDocType::SOURCE )
952 pWorkWrtShell->ChgDBData(
const_cast<SwDoc*
>(pSourceDoc)->GetDBData() );
954 pWorkWrtShell->SetLabelDoc( rSourceWrtShell.
IsLabelDoc() );
961 if( pView ) *pView = pWorkView;
962 if( pWrtShell ) *pWrtShell = pWorkWrtShell;
963 if( pDoc ) *pDoc = pWorkDoc;
966 return xWorkObjectShell.
get();
971 const OUString &sFileURL,
const OUString &sMailRecipient,
972 const OUString &sMailBodyMimeType, rtl_TextEncoding sMailEncoding,
973 const OUString &sAttachmentMimeType )
978 pMessage->addRecipient( sMailRecipient );
981 OUStringBuffer sBody;
985 mail::MailAttachment aAttach;
989 pMessage->addAttachment( aAttach );
994 SfxMedium aMedium( sFileURL, StreamMode::READ );
996 assert( pInStream &&
"no output file created?" );
1001 OStringBuffer sLine;
1002 while ( pInStream->
ReadLine( sLine ) )
1004 sBody.append(OStringToOUString( sLine, sMailEncoding ) +
"\n");
1007 pMessage->setSubject( rMergeDescriptor.
sSubject );
1008 uno::Reference< datatransfer::XTransferable> xBody =
1010 pMessage->setBody( xBody );
1012 for(
const OUString& sCcRecipient : rMergeDescriptor.
aCopiesTo )
1013 pMessage->addCcRecipient( sCcRecipient );
1014 for(
const OUString& sBccRecipient : rMergeDescriptor.
aBlindCopiesTo )
1015 pMessage->addBccRecipient( sBccRecipient );
1030 virtual void mailDelivered( uno::Reference< mail::XMailMessage> xMessage )
override
1038 uno::Reference< mail::XMailMessage>,
const OUString& )
override
1043 xMailDispatcher->stop();
1063 const bool bNeedsTempFiles = ( bMT_EMAIL || bMT_FILE );
1067 OUString sPrefix_ = rMergeDescriptor.
sPrefix;
1071 assert(!bCheckSingleFile_);
1072 bCheckSingleFile_ =
false;
1074 else if( bMT_SHELL || bMT_PRINTER )
1076 assert(bCheckSingleFile_);
1077 bCheckSingleFile_ =
true;
1078 assert(sPrefix_.isEmpty());
1081 const bool bCreateSingleFile = bCheckSingleFile_;
1082 const OUString sDescriptorPrefix = sPrefix_;
1085 static const sal_Int32 nMaxDumpDocs = []() {
1086 if (
const char* sEnv = getenv(
"SW_DEBUG_MAILMERGE_DOCS"))
1087 return OUString(sEnv, strlen(sEnv), osl_getThreadTextEncoding()).
toInt32();
1089 return sal_Int32(0);
1094 OUString sMailBodyMimeType;
1095 rtl_TextEncoding sMailEncoding = ::osl_getThreadTextEncoding();
1097 uno::Reference< beans::XPropertySet > xColumnProp;
1098 uno::Reference< beans::XPropertySet > xPasswordColumnProp;
1102 bool bColumnName = !rMergeDescriptor.
sDBcolumn.isEmpty();
1112 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(
m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
1113 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1114 if( !xCols->hasByName( rMergeDescriptor.
sDBcolumn ) )
1117 aCol >>= xColumnProp;
1119 if(bPasswordColumnName)
1122 aCol >>= xPasswordColumnProp;
1131 m_pImpl->m_xLastMessage.clear();
1135 xMailDispatcher->addListener( xMailListener );
1138 sMailBodyMimeType =
"text/html; charset=utf-8";
1139 sMailEncoding = RTL_TEXTENCODING_UTF8;
1142 sMailBodyMimeType =
"text/plain; charset=UTF-8; format=flowed";
1152 const OUString* pStoreToFilterOptions =
nullptr;
1157 OUString sExtension = rMergeDescriptor.
bSendAsHTML ? OUString(
"html") : OUString(
"txt");
1158 pStoreToFilter = pFilterContainer->
GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
1162 std::shared_ptr<const SfxFilter> pFilter =
1166 pStoreToFilter = pFilter;
1171 const bool bIsPDFexport = pStoreToFilter && pStoreToFilter->GetFilterName() ==
"writer_pdf_Export";
1172 const bool bIsMultiFile = bMT_FILE && !bCreateSingleFile;
1183 std::unique_ptr< utl::TempFileNamed > aTempFile;
1184 sal_uInt16 nStartingPageNo = 0;
1186 std::shared_ptr<weld::GenericDialogController> xProgressDlg;
1191 if( !bIsMergeSilent )
1196 xProgressDlg = std::make_shared<CreateMonitor>(pSourceWindow->
GetFrameWeld());
1199 xProgressDlg = std::make_shared<PrintMonitor>(pSourceWindow->
GetFrameWeld());
1200 static_cast<PrintMonitor*
>(xProgressDlg.get())->set_title(
1206 xProgressDlg.reset();
1212 if( bCreateSingleFile && !pTargetView )
1216 *pSourceShell, bMT_SHELL ? pSourceWindow :
nullptr,
1217 nullptr, &pTargetView, &pTargetShell, &pTargetDoc );
1222 else if( pTargetView )
1227 pTargetDoc = pTargetShell->
GetDoc();
1232 if( bCreateSingleFile )
1240 SfxProgress aProgress(pSourceDocSh, OUString(), 1);
1250 sal_Int32 nDocNo = 1;
1257 int targetDocPageCount = 0;
1259 if( !bIsMergeSilent && !bMT_PRINTER )
1261 sal_Int32 nRecordCount = 1;
1267 sal_Int32 nRecordPerDoc = pSourceShell->
GetDoc()
1269 if ( bSynchronizedDoc && (nRecordPerDoc > 1) )
1271 assert( nRecordPerDoc > 0 );
1273 sal_Int32 nMaxDocs = nRecordCount / nRecordPerDoc;
1274 if ( 0 != nRecordCount % nRecordPerDoc )
1276 static_cast<CreateMonitor*
>(xProgressDlg.get())->SetTotalCount(nMaxDocs);
1279 sal_Int32 nStartRow, nEndRow;
1280 bool bFreezedLayouts =
false;
1282 std::vector< OUString> aFilesToRemove;
1287 SwView* pWorkView =
nullptr;
1291 bool bWorkDocInitialized =
false;
1295 nStartRow =
m_pImpl->pMergeData ?
m_pImpl->pMergeData->xResultSet->getRow() : 0;
1297 OUString sColumnData;
1301 if( bMT_EMAIL || bColumnName )
1303 sColumnData =
GetDBField( xColumnProp, aColumnDBFormat );
1307 if( bNeedsTempFiles && ( !bWorkDocInitialized || !bCreateSingleFile ))
1309 OUString
sPrefix = sDescriptorPrefix;
1313 if( bColumnName && !bMT_EMAIL )
1315 if (!sColumnData.isEmpty())
1316 sLeading = sColumnData;
1330 if( !aTempFile->IsValid() )
1337 uno::Sequence< beans::PropertyValue > aSaveToFilterDataOptions( rMergeDescriptor.
aSaveToFilterData );
1339 if( bMT_EMAIL || bPasswordColumnName )
1341 OUString sPasswordColumnData =
GetDBField( xPasswordColumnProp, aColumnDBFormat );
1347 std::unique_ptr< INetURLObject > aTempFileURL;
1348 if( bNeedsTempFiles )
1349 aTempFileURL.reset(
new INetURLObject(aTempFile->GetURL()));
1350 if( !bIsMergeSilent ) {
1352 static_cast<CreateMonitor*
>(xProgressDlg.get())->SetCurrentPosition(nDocNo);
1355 pPrintMonDlg->
m_xPrinter->set_label(bNeedsTempFiles
1356 ? aTempFileURL->GetBase() : pSourceDocSh->
GetTitle( 2));
1357 OUString sStat =
SwResId(STR_STATSTR_LETTER) +
" " + OUString::number( nDocNo );
1368 if( !bWorkDocInitialized || bCreateSingleFile || bIsPDFexport || bIsMultiFile )
1370 assert( !xWorkDocSh.
Is());
1371 pWorkDocOrigDBManager =
this;
1373 *pSourceShell,
nullptr, &pWorkDocOrigDBManager,
1374 &pWorkView, &pWorkShell, &pWorkDoc );
1375 if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1389 aLayout->FreezeLayout(
false);
1390 aLayout->AllCheckPageDescs();
1401 pWorkShell->SwViewShell::UpdateFields();
1412 text::MailMergeEvent aEvt(
static_cast<text::XMailMergeBroadcaster*
>(xRef.get()), xWorkDocSh->
GetModel() );
1414 xRef->LaunchMailMergeEvent( aEvt );
1419 if( bCreateSingleFile )
1421 assert( pTargetShell &&
"no target shell available!" );
1425 pWorkDoc->RemoveInvisibleContent();
1431 if( bSynchronizedDoc )
1436 if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1440 if( targetDocPageCount % 2 == 1 )
1441 ++targetDocPageCount;
1442 SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc( *pWorkDoc,
1443 nStartingPageNo, !bWorkDocInitialized, targetDocPageCount, nDocNo);
1444 targetDocPageCount += pWorkShell->
GetPageCnt();
1446 if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1455 ::sw::mark::InsertMode::New);
1456 aMergeInfo.
nDBRow = nStartRow;
1462 assert( bNeedsTempFiles );
1465 if (bIsMultiFile && pWorkDoc->HasInvisibleContent())
1467 pWorkDoc->RemoveInvisibleContent();
1474 pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1478 if( !
lcl_SaveDoc( aTempFileURL.get(), pStoreToFilter, pStoreToFilterOptions,
1479 &aSaveToFilterDataOptions, bIsPDFexport,
1480 xWorkDocSh, *pWorkShell, &sFileURL ) )
1486 pWorkDoc->SetDBManager(
this );
1491 aFilesToRemove.push_back( sFileURL );
1495 OSL_FAIL(
"invalid e-Mail address in database column");
1500 rMergeDescriptor, sFileURL, sColumnData, sMailBodyMimeType,
1501 sMailEncoding, pStoreToFilter->GetMimeType() );
1504 std::unique_lock aGuard(
m_pImpl->m_aAllEmailSendMutex );
1505 m_pImpl->m_xLastMessage.set( xMessage );
1506 xMailDispatcher->enqueueMailMessage( xMessage );
1507 if( !xMailDispatcher->isStarted() )
1508 xMailDispatcher->start();
1513 if( bCreateSingleFile || bIsPDFexport || bIsMultiFile)
1515 pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1518 xWorkDocSh =
nullptr;
1522 bWorkDocInitialized =
true;
1524 nEndRow =
m_pImpl->pMergeData ?
m_pImpl->pMergeData->xResultSet->getRow() : 0;
1528 if(!bFreezedLayouts && bCreateSingleFile)
1531 aLayout->FreezeLayout(
true);
1532 bFreezedLayouts =
true;
1543 if( !bCreateSingleFile )
1550 pWorkDoc->SetDBManager(pWorkDocOrigDBManager);
1551 if (xWorkDocSh.
Is())
1561 pTargetDoc->SetInMailMerge(
false);
1562 pTargetDoc->SetAllUniqueFlyNames();
1565 SAL_INFO(
"sw.pageframe",
"(MergeMailFiles pTargetShell->CalcLayout in" );
1567 SAL_INFO(
"sw.pageframe",
"MergeMailFiles pTargetShell->CalcLayout out)" );
1569 pTargetDoc->GetIDocumentUndoRedo().DoUndo(
true );
1572 aLayout->FreezeLayout(
false);
1573 aLayout->AllCheckPageDescs();
1581 assert( aTempFile );
1584 aTempFileURL.
SetURL( aTempFile->GetURL() );
1587 aTempFileURL.
SetURL(sDescriptorPrefix);
1589 aTempFile->EnableKillingFile();
1593 bIsPDFexport, xTargetDocShell.
get(), *pTargetShell ) )
1601 uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.
aPrintOptions );
1603 pTargetView->
ExecPrint( aOptions, bIsMergeSilent,
false );
1611 else if( xTargetDocShell.
is() )
1612 xTargetDocShell->DoClose();
1618 xProgressDlg->response(
RET_OK);
1631 if( xMailDispatcher.is() )
1637 AutoTimer aEmailDispatcherPollTimer(
"sw::SwDBManager aEmailDispatcherPollTimer");
1639 aEmailDispatcherPollTimer.
Start();
1642 aEmailDispatcherPollTimer.
Stop();
1644 xMailDispatcher->stop();
1645 xMailDispatcher->shutdown();
1651 for(
const OUString &sFileURL : aFilesToRemove )
1654 catch (
const uno::Exception&)
1674 const OUString& rTableName,
1675 const OUString& rColNm,
1682 uno::Reference< sdbc::XDataSource> xSource;
1683 uno::Reference< sdbc::XConnection> xConnection;
1684 bool bUseMergeData =
false;
1685 uno::Reference< sdbcx::XColumnsSupplier> xColsSupp;
1686 bool bDisposeConnection =
false;
1688 ((
m_pImpl->pMergeData->sDataSource == rDBName &&
m_pImpl->pMergeData->sCommand == rTableName) ||
1689 (rDBName.isEmpty() && rTableName.isEmpty())))
1691 xConnection =
m_pImpl->pMergeData->xConnection;
1693 bUseMergeData =
true;
1694 xColsSupp.set(
m_pImpl->pMergeData->xResultSet, css::uno::UNO_QUERY);
1696 if(!xConnection.is())
1699 aData.sDataSource = rDBName;
1700 aData.sCommand = rTableName;
1701 aData.nCommandType = -1;
1706 xColsSupp.set(pParam->
xResultSet, css::uno::UNO_QUERY);
1711 bDisposeConnection =
true;
1714 m_pImpl->pMergeData->xConnection = xConnection;
1716 bool bDispose = !xColsSupp.is();
1723 uno::Reference<container::XNameAccess> xCols;
1726 xCols = xColsSupp->getColumns();
1728 catch (
const uno::Exception&)
1732 if(!xCols.is() || !xCols->hasByName(rColNm))
1734 uno::Any aCol = xCols->getByName(rColNm);
1735 uno::Reference< beans::XPropertySet >
xColumn;
1740 ::comphelper::disposeComponent( xColsSupp );
1742 if(bDisposeConnection)
1744 ::comphelper::disposeComponent( xConnection );
1754 uno::Reference< sdbc::XConnection>
const & xConnection,
1755 uno::Reference< beans::XPropertySet>
const & xColumn,
1759 auto xSource = xSource_in;
1766 uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
1768 xSource.set(xChild->getParent(), uno::UNO_QUERY);
1770 if(xSource.is() && xConnection.is() &&
xColumn.is() && pNFormatr)
1773 uno::Reference< util::XNumberFormats > xDocNumberFormats = pNumFormat->getNumberFormats();
1774 uno::Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, uno::UNO_QUERY);
1779 uno::Reference<beans::XPropertySet> xSourceProps(xSource, uno::UNO_QUERY);
1780 uno::Reference< util::XNumberFormats > xNumberFormats;
1781 if(xSourceProps.is())
1783 uno::Any aFormats = xSourceProps->getPropertyValue(
"NumberFormatsSupplier");
1786 uno::Reference<util::XNumberFormatsSupplier> xSuppl;
1787 aFormats >>= xSuppl;
1790 xNumberFormats = xSuppl->getNumberFormats();
1794 bool bUseDefault =
true;
1800 sal_Int32 nFormat = 0;
1801 aFormatKey >>= nFormat;
1802 if(xNumberFormats.is())
1806 uno::Reference<beans::XPropertySet> xNumProps = xNumberFormats->getByKey( nFormat );
1807 uno::Any aFormatString = xNumProps->getPropertyValue(
"FormatString");
1808 uno::Any aLocaleVal = xNumProps->getPropertyValue(
"Locale");
1810 aFormatString >>= sFormat;
1812 aLocaleVal >>= aLoc;
1813 nFormat = xDocNumberFormats->queryKey( sFormat, aLoc,
false );
1814 if(NUMBERFORMAT_ENTRY_NOT_FOUND == sal::static_int_cast< sal_uInt32, sal_Int32>(nFormat))
1815 nFormat = xDocNumberFormats->addNew( sFormat, aLoc );
1817 bUseDefault =
false;
1819 catch (
const uno::Exception&)
1826 catch(
const uno::Exception&)
1828 SAL_WARN(
"sw.mailmerge",
"no FormatKey property found");
1837 const OUString& rTableName,
1838 const OUString& rColNm )
1840 sal_Int32 nRet = sdbc::DataType::SQLNULL;
1842 aData.sDataSource = rDBName;
1843 aData.sCommand = rTableName;
1844 aData.nCommandType = -1;
1846 uno::Reference< sdbc::XConnection> xConnection;
1847 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp;
1848 bool bDispose =
false;
1852 xColsSupp.set( pParam->
xResultSet, uno::UNO_QUERY );
1858 if( !xColsSupp.is() )
1865 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1866 if(xCols->hasByName(rColNm))
1868 uno::Any aCol = xCols->getByName(rColNm);
1869 uno::Reference<beans::XPropertySet> xCol;
1871 uno::Any aType = xCol->getPropertyValue(
"Type");
1875 ::comphelper::disposeComponent( xColsSupp );
1881 uno::Reference<sdbc::XDataSource>& rxSource,
const SwView *pView)
1883 uno::Reference< sdbc::XConnection> xConnection;
1884 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1887 uno::Reference<sdb::XCompletedConnection> xComplConnection(
dbtools::getDataSource(rDataSource, xContext), uno::UNO_QUERY);
1888 if ( xComplConnection.is() )
1890 rxSource.set(xComplConnection, uno::UNO_QUERY);
1892 uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(xContext, pWindow ? pWindow->
GetXWindow() :
nullptr), uno::UNO_QUERY_THROW );
1893 xConnection = xComplConnection->connectWithCompletion( xHandler );
1896 catch(
const uno::Exception&)
1904 const OUString& rTableOrQuery,
1907 uno::Reference< sdbcx::XColumnsSupplier> xRet;
1913 uno::Reference<sdbcx::XTablesSupplier> xTSupplier(xConnection, uno::UNO_QUERY);
1916 uno::Reference<container::XNameAccess> xTables = xTSupplier->getTables();
1917 eTableOrQuery = xTables->hasByName(rTableOrQuery) ?
1922 sdb::CommandType::TABLE : sdb::CommandType::QUERY;
1923 uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1924 uno::Reference<sdbc::XRowSet> xRowSet(xMgr->createInstance(
"com.sun.star.sdb.RowSet"), uno::UNO_QUERY);
1926 OUString sDataSource;
1928 uno::Reference<beans::XPropertySet> xSourceProperties(xSource, uno::UNO_QUERY);
1929 if(xSourceProperties.is())
1931 xSourceProperties->getPropertyValue(
"Name") >>= sDataSource;
1934 uno::Reference<beans::XPropertySet> xRowProperties(xRowSet, uno::UNO_QUERY);
1935 xRowProperties->setPropertyValue(
"DataSourceName",
uno::Any(sDataSource));
1936 xRowProperties->setPropertyValue(
"Command",
uno::Any(rTableOrQuery));
1937 xRowProperties->setPropertyValue(
"CommandType",
uno::Any(nCommandType));
1938 xRowProperties->setPropertyValue(
"FetchSize",
uno::Any(sal_Int32(10)));
1939 xRowProperties->setPropertyValue(
"ActiveConnection",
uno::Any(xConnection));
1941 xRet.set( xRowSet, uno::UNO_QUERY );
1943 catch (
const uno::Exception&)
1955 uno::Reference< sdb::XColumn >
xColumn(xColumnProps, uno::UNO_QUERY);
1957 assert(
xColumn.is() &&
"SwDBManager::::ImportDBField: illegal arguments" );
1961 uno::Any aType = xColumnProps->getPropertyValue(
"Type");
1962 sal_Int32 eDataType = sdbc::DataType::SQLNULL;
1963 aType >>= eDataType;
1966 case sdbc::DataType::CHAR:
1967 case sdbc::DataType::VARCHAR:
1968 case sdbc::DataType::LONGVARCHAR:
1972 sRet = sRet.replace(
'\xb',
'\n' );
1974 catch(
const sdbc::SQLException&)
1978 case sdbc::DataType::BIT:
1979 case sdbc::DataType::BOOLEAN:
1980 case sdbc::DataType::TINYINT:
1981 case sdbc::DataType::SMALLINT:
1982 case sdbc::DataType::INTEGER:
1983 case sdbc::DataType::BIGINT:
1984 case sdbc::DataType::FLOAT:
1985 case sdbc::DataType::REAL:
1986 case sdbc::DataType::DOUBLE:
1987 case sdbc::DataType::NUMERIC:
1988 case sdbc::DataType::DECIMAL:
1989 case sdbc::DataType::DATE:
1990 case sdbc::DataType::TIME:
1991 case sdbc::DataType::TIMESTAMP:
2003 double fVal =
xColumn->getDouble();
2010 catch (
const uno::Exception&)
2024 const OUString& rTableOrQuery,
bool bMergeShell)
2028 return ((rDataSource ==
m_pImpl->pMergeData->sDataSource
2029 && rTableOrQuery ==
m_pImpl->pMergeData->sCommand)
2030 || (rDataSource.isEmpty() && rTableOrQuery.isEmpty()))
2031 &&
m_pImpl->pMergeData->xResultSet.is();
2033 else if(!bMergeShell)
2036 aData.sDataSource = rDataSource;
2037 aData.sCommand = rTableOrQuery;
2038 aData.nCommandType = -1;
2047 const OUString& rColumnName, sal_uInt32 nAbsRecordId,
2049 OUString& rResult,
double* pNumber)
2055 rSourceName ==
m_pImpl->pMergeData->sDataSource &&
2056 rTableName ==
m_pImpl->pMergeData->sCommand)
2058 pFound =
m_pImpl->pMergeData.get();
2063 aData.sDataSource = rSourceName;
2064 aData.sCommand = rTableName;
2065 aData.nCommandType = -1;
2075 [nAbsRecordId](
const uno::Any& rSelection) {
2076 sal_Int32 nSelection = 0;
2077 rSelection >>= nSelection;
2078 return nSelection == static_cast<sal_Int32>(nAbsRecordId);
2085 sal_Int32 nOldRow = 0;
2090 catch(
const uno::Exception&)
2096 if ( nOldRow !=
static_cast<sal_Int32
>(nAbsRecordId) )
2100 if ( nOldRow !=
static_cast<sal_Int32
>(nAbsRecordId) )
2108 OUString &rResult,
double *pNumber)
2122 assert(
m_pImpl->pMergeData &&
m_pImpl->pMergeData->xResultSet.is() &&
"no data source in merge" );
2132 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(
m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
2133 if( !xColsSupp.is() )
2137 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
2138 const uno::Sequence<OUString>
aColNames = xCols->getElementNames();
2145 for(
const OUString& rColName :
aColNames )
2148 sal_Int32 nColumnType = sdbc::DataType::SQLNULL;
2149 uno::Any aCol = xCols->getByName( rColName );
2150 uno::Reference<beans::XPropertySet> xColumnProps;
2151 aCol >>= xColumnProps;
2152 uno::Any aType = xColumnProps->getPropertyValue(
"Type" );
2153 aType >>= nColumnType;
2154 double aNumber = DBL_MAX;
2159 m_pImpl->pMergeData->sCommand,
2160 rColName, pDocFormatter, nLanguage );
2162 bool colIsNumber = aNumber != DBL_MAX;
2164 aNumber, nColumnType );
2172 SAL_INFO(
"sw.ui",
"'" << rColName <<
"': " << aNumber <<
" / " << aString );
2181 SAL_INFO(
"sw.ui",
"'" << rColName <<
"': " << aString );
2191 const OUString& rDataSource,
const OUString& rCommand)
2195 rDataSource ==
m_pImpl->pMergeData->sDataSource &&
2196 rCommand ==
m_pImpl->pMergeData->sCommand)
2198 pFound =
m_pImpl->pMergeData.get();
2203 aData.sDataSource = rDataSource;
2204 aData.sCommand = rCommand;
2205 aData.nCommandType = -1;
2215 assert( SwDBNextRecord::NEXT ==
action ||
2216 (SwDBNextRecord::FIRST ==
action && pParam) );
2217 if(
nullptr == pParam )
2220 if(
action == SwDBNextRecord::FIRST )
2242 else if(
action == SwDBNextRecord::FIRST )
2248 sal_Int32 nBefore = pParam->
xResultSet->getRow();
2253 ::dbtools::throwFunctionSequenceException( pParam->
xResultSet );
2260 catch(
const uno::Exception & )
2264 "sw.mailmerge",
"exception in ToNextRecord()");
2276 return(
m_pImpl->pMergeData &&
m_pImpl->pMergeData->HasValidRecord() );
2281 sal_uInt32 nRet = 0;
2282 assert(
m_pImpl->pMergeData &&
2283 m_pImpl->pMergeData->xResultSet.is() &&
"no data source in merge" );
2284 if(!
m_pImpl->pMergeData || !
m_pImpl->pMergeData->xResultSet.is())
2288 nRet =
m_pImpl->pMergeData->xResultSet->getRow();
2290 catch(
const uno::Exception&)
2298 assert(
m_pImpl->pMergeData &&
2299 m_pImpl->pMergeData->xResultSet.is() &&
"no data source in merge" );
2300 if(!
m_pImpl->pMergeData || !
m_pImpl->pMergeData->xResultSet.is()|| nSet < 0)
2303 sal_Int32 nAbsPos = nSet;
2304 assert(nAbsPos >= 0);
2306 m_pImpl->pMergeData->bEndOfDB = !bRet;
2313 aData.sDataSource = rDataSource;
2314 aData.sCommand = rTableOrQuery;
2315 aData.nCommandType = -1;
2327 uno::Reference< sdbc::XDatabaseMetaData > xMetaData = pFound->
xConnection->getMetaData();
2331 ->supportsResultSetType(sal_Int32(sdbc::ResultSetType::SCROLL_INSENSITIVE));
2333 catch(
const uno::Exception&)
2339 OUString aQuoteChar = xMetaData->getIdentifierQuoteString();
2340 OUString sStatement =
"SELECT * FROM " + aQuoteChar + rTableOrQuery + aQuoteChar;
2347 catch (
const uno::Exception&)
2360 uno::Reference< sdbc::XDataSource> xSource;
2367 uno::Reference<lang::XComponent> xComponent(pFound->
xConnection, uno::UNO_QUERY);
2369 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
2371 catch(
const uno::Exception&)
2379 const OUString& rDataSource,
const OUString& rTableOrQuery, sal_Int32 nCommandType)
2381 sal_uInt32 nRet = 0xffffffff;
2384 ((rDataSource ==
m_pImpl->pMergeData->sDataSource &&
2385 rTableOrQuery ==
m_pImpl->pMergeData->sCommand) ||
2386 (rDataSource.isEmpty() && rTableOrQuery.isEmpty())) &&
2387 (nCommandType == -1 || nCommandType ==
m_pImpl->pMergeData->nCommandType) &&
2388 m_pImpl->pMergeData->xResultSet.is())
2395 aData.sDataSource = rDataSource;
2396 aData.sCommand = rTableOrQuery;
2397 aData.nCommandType = nCommandType;
2406 if(nSelIndex >= pFound->
aSelection.getLength())
2407 nSelIndex = pFound->
aSelection.getLength() -1;
2408 pFound->
aSelection.getConstArray()[nSelIndex] >>= nRet;
2414 catch(
const uno::Exception&)
2429 if (bIncludingMerge || pParam.get() !=
m_pImpl->pMergeData.get())
2431 pParam->nSelectionIndex = 0;
2432 pParam->bEndOfDB =
false;
2436 pParam->xResultSet->first();
2438 catch(
const uno::Exception&)
2452 (bCreate &&
m_pImpl->pMergeData->nCommandType == -1)))
2454 return m_pImpl->pMergeData.get();
2475 if(bCreate && !pFound)
2481 uno::Reference<lang::XComponent> xComponent(pFound->
xConnection, uno::UNO_QUERY);
2483 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
2485 catch(
const uno::Exception&)
2495 if(
m_pImpl->pMergeData && rDataSource ==
m_pImpl->pMergeData->sDataSource )
2498 return m_pImpl->pMergeData.get();
2503 if(rDataSource == pParam->sDataSource)
2506 pFound = pParam.get();
2510 if(bCreate && !pFound)
2513 aData.sDataSource = rDataSource;
2519 uno::Reference<lang::XComponent> xComponent(pFound->
xConnection, uno::UNO_QUERY);
2521 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
2523 catch(
const uno::Exception&)
2532 return SW_MOD()->GetDBConfig()->GetAddressSource();
2537 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2538 uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
2539 return xDBContext->getElementNames();
2553 else if (sExt.equalsIgnoreAsciiCase(
"sxc")
2554 || sExt.equalsIgnoreAsciiCase(
"ods")
2555 || sExt.equalsIgnoreAsciiCase(
"xls")
2556 || sExt.equalsIgnoreAsciiCase(
"xlsx"))
2560 else if (sExt.equalsIgnoreAsciiCase(
"sxw") || sExt.equalsIgnoreAsciiCase(
"odt") || sExt.equalsIgnoreAsciiCase(
"doc") || sExt.equalsIgnoreAsciiCase(
"docx"))
2564 else if (sExt.equalsIgnoreAsciiCase(
"dbf"))
2568 else if (sExt.equalsIgnoreAsciiCase(
"csv") || sExt.equalsIgnoreAsciiCase(
"txt"))
2573 else if (sExt.equalsIgnoreAsciiCase(
"mdb") || sExt.equalsIgnoreAsciiCase(
"mde"))
2577 else if (sExt.equalsIgnoreAsciiCase(
"accdb") || sExt.equalsIgnoreAsciiCase(
"accde"))
2592 if (rType == DBConnURIType::UNKNOWN)
2596 case DBConnURIType::UNKNOWN:
2597 case DBConnURIType::ODB:
2599 case DBConnURIType::CALC:
2601 OUString sDBURL =
"sdbc:calc:" +
2606 case DBConnURIType::WRITER:
2608 OUString sDBURL =
"sdbc:writer:" +
2613 case DBConnURIType::DBASE:
2616 aUrlTmp.removeSegment();
2617 aUrlTmp.removeFinalSlash();
2618 OUString sDBURL =
"sdbc:dbase:" +
2623 case DBConnURIType::FLAT:
2626 aUrlTmp.removeSegment();
2627 aUrlTmp.removeFinalSlash();
2628 OUString sDBURL =
"sdbc:flat:" +
2634 case DBConnURIType::MSJET:
2637 OUString sDBURL(
"sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + rURL.
PathToFileName());
2642 case DBConnURIType::MSACE:
2645 OUString sDBURL(
"sdbc:ado:PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=" + rURL.
PathToFileName());
2673OUString LoadAndRegisterDataSource_Impl(
DBConnURIType type,
const uno::Reference< beans::XPropertySet > *pSettings,
2683 uno::Any aURLAny = GetDBunoURI(rURL, type);
2685 case DBConnURIType::UNKNOWN:
2686 case DBConnURIType::CALC:
2687 case DBConnURIType::WRITER:
2689 case DBConnURIType::ODB:
2692 case DBConnURIType::FLAT:
2693 case DBConnURIType::DBASE:
2697 aTableFilterAny <<= aFilters;
2700 case DBConnURIType::MSJET:
2701 case DBConnURIType::MSACE:
2702 aSuppressVersionsAny <<=
true;
2708 uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
2709 uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
2711 OUString sNewName = rURL.
getName(
2713 sal_Int32 nExtLen = sExt.getLength();
2714 sNewName = sNewName.replaceAt(sNewName.getLength() - nExtLen - 1, nExtLen + 1, u
"");
2719 while (xDBContext->hasByName(sFind))
2720 sFind = sNewName + OUString::number(++nIndex);
2722 uno::Reference<uno::XInterface> xNewInstance;
2727 aDataSource >>= xNewInstance;
2731 xNewInstance = xDBContext->createInstance();
2732 uno::Reference<beans::XPropertySet> xDataProperties(xNewInstance, uno::UNO_QUERY);
2735 xDataProperties->setPropertyValue(
"URL", aURLAny);
2737 xDataProperties->setPropertyValue(
"TableFilter", aTableFilterAny);
2738 if (aSuppressVersionsAny.
hasValue())
2739 xDataProperties->setPropertyValue(
"SuppressVersionColumns", aSuppressVersionsAny);
2741 xDataProperties->setPropertyValue(
"Info", aInfoAny);
2743 if (DBConnURIType::FLAT == type && pSettings)
2745 uno::Any aSettings = xDataProperties->getPropertyValue(
"Settings");
2746 uno::Reference < beans::XPropertySet > xDSSettings;
2747 aSettings >>= xDSSettings;
2748 ::comphelper::copyProperties(*pSettings, xDSSettings);
2749 xDSSettings->setPropertyValue(
"Extension",
uno::Any(sExt));
2752 uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, uno::UNO_QUERY_THROW);
2753 uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW);
2754 OUString aOwnURL = getOwnURL(pDocShell);
2755 if (aOwnURL.isEmpty())
2759 const OUString sTmpName =
utl::CreateTempURL(sNewName,
true, u
".odb", pDestDir ? pDestDir : &sHomePath);
2760 xStore->storeAsURL(sTmpName, uno::Sequence<beans::PropertyValue>());
2765 OUString aStreamRelPath =
"EmbeddedDatabase";
2766 uno::Reference<embed::XStorage> xStorage = pDocShell->
GetStorage();
2770 uno::Reference<lang::XMultiServiceFactory>
xFactory(pDocShell->
GetModel(), uno::UNO_QUERY);
2771 uno::Reference<beans::XPropertySet> xPropertySet(
xFactory->createInstance(
"com.sun.star.document.Settings"), uno::UNO_QUERY);
2772 xPropertySet->setPropertyValue(
"EmbeddedDatabaseName",
uno::Any(aStreamRelPath));
2778 xDBContext->registerObject(sFind, xNewInstance);
2780 catch (
const uno::Exception&)
2790 sfx2::FileDialogHelper aDlgHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, pParent);
2792 uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDlgHelper.
GetFilePicker();
2794 OUString sFilterAll(
SwResId(STR_FILTER_ALL));
2795 OUString sFilterAllData(
SwResId(STR_FILTER_ALL_DATA));
2797 const std::vector<std::pair<OUString, OUString>> filters{
2798 {
SwResId(STR_FILTER_SXB),
"*.odb" },
2799 {
SwResId(STR_FILTER_SXC),
"*.ods;*.sxc" },
2800 {
SwResId(STR_FILTER_SXW),
"*.odt;*.sxw" },
2801 {
SwResId(STR_FILTER_DBF),
"*.dbf" },
2802 {
SwResId(STR_FILTER_XLS),
"*.xls;*.xlsx" },
2803 {
SwResId(STR_FILTER_DOC),
"*.doc;*.docx" },
2804 {
SwResId(STR_FILTER_TXT),
"*.txt" },
2805 {
SwResId(STR_FILTER_CSV),
"*.csv" },
2807 {
SwResId(STR_FILTER_MDB),
"*.mdb;*.mde" },
2808 {
SwResId(STR_FILTER_ACCDB),
"*.accdb;*.accde" },
2812 OUStringBuffer sAllDataFilter;
2816 if (!sAllDataFilter.isEmpty())
2817 sAllDataFilter.append(
';');
2818 sAllDataFilter.append(
filter);
2821 xFP->appendFilter( sFilterAll,
"*" );
2822 xFP->appendFilter( sFilterAllData, sAllDataFilter.makeStringAndClear());
2828 xFP->setCurrentFilter( sFilterAll ) ;
2832 uno::Reference< beans::XPropertySet > aSettings;
2836 if( DBConnURIType::FLAT ==
type )
2838 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2839 uno::Reference < sdb::XTextConnectionSettings > xSettingsDlg = sdb::TextConnectionSettings::create(xContext);
2840 if( xSettingsDlg->execute() )
2841 aSettings.set( uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY_THROW ) );
2843 sFind = LoadAndRegisterDataSource_Impl(
type, DBConnURIType::FLAT ==
type ? &aSettings :
nullptr,
aURL,
nullptr, pDocShell );
2851 const uno::Reference<embed::XStorage>& xStorage,
2852 const OUString& rStreamRelPath,
2853 const OUString& rOwnURL,
bool bCopyTo)
2856 OUString
const sTmpName = ConstructVndSunStarPkgUrl(rOwnURL, rStreamRelPath);
2860 {
"TargetStorage",
uno::Any(xStorage)},
2861 {
"StreamRelPath",
uno::Any(rStreamRelPath)},
2865 xStorable->storeToURL(sTmpName, aSequence);
2867 xStorable->storeAsURL(sTmpName, aSequence);
2872 return LoadAndRegisterDataSource_Impl( DBConnURIType::UNKNOWN,
nullptr,
INetURLObject(rURI), pDestDir,
nullptr );
2879 void switchEmbeddedDatabaseStorage(
const uno::Reference<sdb::XDatabaseContext>& rDatabaseContext,
const OUString& rName)
2881 uno::Reference<sdb::XDocumentDataSource> xDS(rDatabaseContext->getByName(rName), uno::UNO_QUERY);
2884 uno::Reference<document::XStorageBasedDocument> xStorageDoc(xDS->getDatabaseDocument(), uno::UNO_QUERY);
2894 if (xDatabaseContext->hasByName(rName))
2896 switchEmbeddedDatabaseStorage(xDatabaseContext, rName);
2897 xDatabaseContext->revokeObject(rName);
2908 if (sDataSource.isEmpty())
2909 sDataSource =
"EmbeddedDatabase";
2915 OUString
const aURL = ConstructVndSunStarPkgUrl(
2919 uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(
aURL), uno::UNO_QUERY);
2920 xDatabaseContext->registerObject( sDataSource, xDataSource );
2928 const uno::Sequence<beans::PropertyValue>& rProperties)
2933 OUString sDataSource, sDataTableOrQuery;
2934 uno::Sequence<uno::Any> aSelection;
2936 sal_Int32 nCmdType = sdb::CommandType::TABLE;
2937 uno::Reference< sdbc::XConnection> xConnection;
2949 if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty())
2951 OSL_FAIL(
"PropertyValues missing or unset");
2957 if(!xConnection.is())
2972 uno::Reference<sdbc::XResultSet> xResSet =
m_pImpl->pMergeDialog->GetResultSet();
2990 if(
m_pImpl->pMergeDialog->IsGenerateFromDataBase())
2993 if(
m_pImpl->pMergeDialog->IsFileEncryptedFromDataBase())
2997 Merge( aMergeDesc );
3009 if (pParam.get() == pFound)
3013 uno::Reference<lang::XComponent> xComp(pParam->xConnection, uno::UNO_QUERY);
3017 catch(
const uno::RuntimeException&)
3027 m_pImpl->pMergeDialog.disposeAndClear();
3031 const uno::Sequence< beans::PropertyValue>& rProperties)
3033 OUString sDataSource, sDataTableOrQuery;
3034 uno::Reference<sdbc::XResultSet> xResSet;
3035 uno::Sequence<uno::Any> aSelection;
3036 sal_Int16 nCmdType = sdb::CommandType::TABLE;
3037 uno::Reference< sdbc::XConnection> xConnection;
3038 for(
const beans::PropertyValue& rValue : rProperties)
3040 if ( rValue.Name ==
"DataSourceName" )
3041 rValue.Value >>= sDataSource;
3042 else if ( rValue.Name ==
"Command" )
3043 rValue.Value >>= sDataTableOrQuery;
3044 else if ( rValue.Name ==
"Cursor" )
3045 rValue.Value >>= xResSet;
3046 else if ( rValue.Name ==
"Selection" )
3047 rValue.Value >>= aSelection;
3048 else if ( rValue.Name ==
"CommandType" )
3049 rValue.Value >>= nCmdType;
3050 else if ( rValue.Name ==
"ActiveConnection" )
3051 rValue.Value >>= xConnection;
3053 if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty() || !xResSet.is())
3055 OSL_FAIL(
"PropertyValues missing or unset");
3058 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
3059 uno::Reference<sdbc::XDataSource> xSource;
3060 uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
3062 xSource.set(xChild->getParent(), uno::UNO_QUERY);
3065 uno::Reference< sdbcx::XColumnsSupplier > xColSupp( xResSet, uno::UNO_QUERY );
3068 aDBData.
sCommand = sDataTableOrQuery;
3076 if(
RET_OK != pDlg->Execute() )
3080 if(!xConnection.is())
3081 xConnection = xSource->getConnection(sDummy, sDummy);
3084 pDlg->DataToDoc( aSelection , xSource, xConnection, xResSet);
3086 catch (
const uno::Exception&)
3094 uno::Reference<sdbc::XDataSource> xSource;
3097 uno::Reference<container::XChild> xChild(_xConnection, uno::UNO_QUERY);
3099 xSource.set(xChild->getParent(), uno::UNO_QUERY);
3100 if ( !xSource.is() )
3103 catch (
const uno::Exception&)
3111 const OUString& _sCommand,
3112 sal_Int32 _nCommandType,
3113 const uno::Reference<sdbc::XConnection>& _xConnection,
3116 uno::Reference<sdbc::XResultSet> xResultSet;
3119 uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
3122 uno::Reference<uno::XInterface> xInstance = xMgr->createInstance(
"com.sun.star.sdb.RowSet");
3123 uno::Reference<beans::XPropertySet> xRowSetPropSet(xInstance, uno::UNO_QUERY);
3124 if(xRowSetPropSet.is())
3126 xRowSetPropSet->setPropertyValue(
"DataSourceName",
uno::Any(_sDataSourceName));
3127 xRowSetPropSet->setPropertyValue(
"ActiveConnection",
uno::Any(_xConnection));
3128 xRowSetPropSet->setPropertyValue(
"Command",
uno::Any(_sCommand));
3129 xRowSetPropSet->setPropertyValue(
"CommandType",
uno::Any(_nCommandType));
3131 uno::Reference< sdb::XCompletedExecution > xRowSet(xInstance, uno::UNO_QUERY);
3136 uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(
comphelper::getComponentContext(xMgr), pWindow ? pWindow->
GetXWindow() :
nullptr), uno::UNO_QUERY_THROW );
3137 xRowSet->executeWithCompletion(xHandler);
3139 xResultSet.set(xRowSet, uno::UNO_QUERY);
3143 catch (
const uno::Exception&)
3152 bool bLoad =
m_sEmbeddedName != rEmbeddedName && !rEmbeddedName.isEmpty();
3153 bool bRegisterListener =
m_sEmbeddedName.isEmpty() && !rEmbeddedName.isEmpty();
3159 uno::Reference<embed::XStorage> xStorage = rDocShell.
GetStorage();
3162 if (xStorage->hasByName(rEmbeddedName))
3166 if (bRegisterListener)
3168 m_pImpl->m_xDataSourceRemovedListener =
new SwDataSourceRemovedListener(*
this);
3183 if (
m_pImpl->m_xDataSourceRemovedListener.is())
3185 m_pImpl->m_xDataSourceRemovedListener->Dispose();
3186 m_pImpl->m_xDataSourceRemovedListener.clear();
3191 : m_pDBManager(&rManager)
3199 if (!m_pDBManager)
return;
3201 uno::Reference<sdbc::XConnection> xSource(rSource.Source, uno::UNO_QUERY);
3202 for (
size_t nPos = m_pDBManager->m_DataSourceParams.size();
nPos;
nPos--)
3204 SwDSParam* pParam = m_pDBManager->m_DataSourceParams[
nPos - 1].get();
3208 m_pDBManager->m_DataSourceParams.erase(
3209 m_pDBManager->m_DataSourceParams.begin() +
nPos - 1);
3221 aDescriptor.
setDataSource(xConfigItem->GetCurrentDBData().sDataSource);
3229 xConfigItem->SetTargetView(
nullptr);
3250 xConfigItem->DisposeResultSet();
3251 xConfigItem->DocumentReloaded();
SfxApplication * SfxGetpApp()
static bool Reschedule(bool bHandleAllCurrentEvents=false)
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
virtual const JobSetup * getJobsetup() const =0
Returns the Jobsetup.
virtual void setPrintData(const SwPrintData &rPrtData)=0
Sets the PrintData.
virtual void setJobsetup(const JobSetup &rJobSetup)=0
Sets the Jobsetup.
virtual const SwPrintData & getPrintData() const =0
Returns the PrintData.
virtual sal_Int32 GetRecordsPerDocument() const =0
virtual bool EmbedAllLinks()=0
Embed all local links (ranges/graphics).
virtual void ResetModified()=0
MailDispatcher listener interface.
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetFileExtension() const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
OUString getBase(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString PathToFileName() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
static OUString encode(std::u16string_view rText, Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
A MailDispatcher should be used for sending a bunch a mail messages asynchronously.
std::unique_ptr< weld::Label > m_xPrintInfo
std::unique_ptr< weld::Label > m_xPrinter
static void FinishPrintJob(const std::shared_ptr< vcl::PrinterController > &i_pController)
bool PutString(const OUString &)
static void ProcessEventsToIdle()
void NotifyEvent(const SfxEventHint &rEvent, bool bSynchron=true)
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4Extension(const OUString &rExt, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
vcl::Window & GetWindow() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const INetURLObject & GetURLObject() const
SfxItemSet & GetItemSet() const
void SetFilter(const std::shared_ptr< const SfxFilter > &pFilter)
bool DoSaveAs(SfxMedium &rNewStor)
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true)
SfxMedium * GetMedium() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
OUString GetTitle(sal_uInt16 nMaxLen=0) const
css::uno::Reference< css::embed::XStorage > const & GetStorage()
SfxViewShell * GetViewShell() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxDispatcher * GetDispatcher()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxFrame & GetFrame() const
virtual SfxObjectShell * GetObjectShell() override
weld::Window * GetFrameWeld() const
static SfxViewFrame * LoadHiddenDocument(SfxObjectShell const &i_rDoc, SfxInterfaceId i_nViewId)
weld::Window * GetFrameWeld() const
SfxViewFrame & GetViewFrame() const
const std::shared_ptr< vcl::PrinterController > & GetPrinterController() const
void ExecPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
bool ReadLine(OStringBuffer &rStr, sal_Int32 nMaxBytesToRead=0xFFFE)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
const OUString & GetTempPath() const
virtual VclPtr< AbstractMailMergeDlg > CreateMailMergeDlg(weld::Window *pParent, SwWrtShell &rSh, const OUString &rSourceName, const OUString &rTableName, sal_Int32 nCommandType, const css::uno::Reference< css::sdbc::XConnection > &xConnection)=0
virtual VclPtr< AbstractSwInsertDBColAutoPilot > CreateSwInsertDBColAutoPilot(SwView &rView, css::uno::Reference< css::sdbc::XDataSource > rxSource, css::uno::Reference< css::sdbcx::XColumnsSupplier > xColSupp, const SwDBData &rData)=0
static SwAbstractDialogFactory * Create()
void VarChange(const OUString &rStr, const SwSbxValue &rValue)
bool SttEndDoc(bool bStt)
static bool FormatValue(SvNumberFormatter const *pDocFormatter, OUString const &aString, sal_uInt32 nFormat, double &aNumber, sal_Int32 nColumnType, SwDBField *pField=nullptr)
SwDBManager * m_pDBManager
virtual void SAL_CALL disposing(const lang::EventObject &Source) override
ConnectionDisposedListener_Impl(SwDBManager &rMgr)
virtual void mailDeliveryError(::rtl::Reference< MailDispatcher > xMailDispatcher, uno::Reference< mail::XMailMessage >, const OUString &) override
MailDispatcherListener_Impl(SwDBManager &rDBManager)
SwDBManager & m_rDBManager
virtual void mailDelivered(uno::Reference< mail::XMailMessage > xMessage) override
virtual void idle() override
Called when there are no more mail messages to deliver.
static css::uno::Reference< css::sdbc::XConnection > GetConnection(const OUString &rDataSource, css::uno::Reference< css::sdbc::XDataSource > &rxSource, const SwView *pView)
static css::uno::Reference< css::sdbcx::XColumnsSupplier > GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection > const &xConnection, const OUString &rTableOrQuery, SwDBSelect eTableOrQuery=SwDBSelect::UNKNOWN)
std::vector< OUString > m_aNotUsedConnections
Not used connections.
void RevokeLastRegistrations()
Revoke not committed registrations in case of mail merge cancel.
css::uno::Reference< css::sdbc::XConnection > const & RegisterConnection(OUString const &rSource)
create and store or find an already stored connection to a data source for use in SwFieldMgr and SwDB...
SAL_DLLPRIVATE bool ToNextMergeRecord()
const SwXMailMerge * m_pMergeEvtSrc
!= 0 if mail merge events are to be send
SAL_DLLPRIVATE SwDSParam * FindDSConnection(const OUString &rSource, bool bCreate)
static std::vector< std::pair< SwDocShell *, OUString > > s_aUncommittedRegistrations
Store last registrations to revoke or commit.
void releaseRevokeListener()
Stop reacting to removed database registrations.
bool Merge(const SwMergeDescriptor &rMergeDesc)
Merging of data records into fields.
bool m_bInMerge
merge process active
static OUString GetDBField(css::uno::Reference< css::beans::XPropertySet > const &xColumnProp, const SwDBFormatData &rDBFormatData, double *pNumber=nullptr)
SAL_DLLPRIVATE void ImportFromConnection(SwWrtShell *pSh)
Insert data record as text into document.
bool IsDataSourceOpen(const OUString &rDataSource, const OUString &rTableOrQuery, bool bMergeShell)
check if a data source is open
void CloseAll(bool bIncludingMerge=true)
close all data sources - after fields were updated
bool FillCalcWithMergeData(SvNumberFormatter *pDocFormatter, LanguageType nLanguage, SwCalc &aCalc)
static const SwDBData & GetAddressDBName()
static sal_uLong GetColumnFormat(css::uno::Reference< css::sdbc::XDataSource > const &xSource, css::uno::Reference< css::sdbc::XConnection > const &xConnection, css::uno::Reference< css::beans::XPropertySet > const &xColumn, SvNumberFormatter *pNFormatr, LanguageType nLanguage)
static css::uno::Sequence< OUString > GetExistingDatabaseNames()
const OUString & getEmbeddedName() const
bool GetTableNames(weld::ComboBox &rBox, const OUString &rDBName)
Fill listbox with all table names of a database.
const SwXMailMerge * GetMailMergeEvtSrc() const
MailMergeEvent source.
SAL_DLLPRIVATE void ImplDestroy()
SwDBManager(SwDBManager const &)=delete
static std::shared_ptr< SwMailMergeConfigItem > PerformMailMerge(SwView const *pView)
void setEmbeddedName(const OUString &rEmbeddedName, SwDocShell &rDocShell)
void GetColumnNames(weld::ComboBox &rBox, const OUString &rDBName, const OUString &rTableName)
Fill listbox with all column names of a database table.
SAL_DLLPRIVATE bool IsValidMergeRecord() const
bool ToRecordId(sal_Int32 nSet)
void RevokeNotUsedConnections()
Remove not used connections.
bool m_bMergeSilent
suppress display of dialogs/boxes (used when called over API)
void SetAsUsed(const OUString &rName)
Set connection as used.
sal_Int32 GetColumnType(const OUString &rDBName, const OUString &rTableName, const OUString &rColNm)
static css::uno::Reference< css::sdbc::XDataSource > getDataSourceAsParent(const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const OUString &_sDataSourceName)
try to get the data source from the given connection through the XChild interface.
SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell *pSh)
Insert a single data record as text into document.
OUString m_sEmbeddedName
Name of the embedded database that's included in the current document.
bool IsMergeSilent() const
void ExecuteFormLetter(SwWrtShell &rSh, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
static void InsertText(SwWrtShell &rSh, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
SwDSParams_t m_DataSourceParams
bool GetMergeColumnCnt(const OUString &rColumnName, LanguageType nLanguage, OUString &rResult, double *pNumber)
bool OpenDataSource(const OUString &rDataSource, const OUString &rTableOrQuery)
open the source while fields are updated - for the calculator only!
static OUString LoadAndRegisterDataSource(weld::Window *pParent, SwDocShell *pDocShell=nullptr)
Loads a data source from file and registers it.
void LoadAndRegisterEmbeddedDataSource(const SwDBData &rData, const SwDocShell &rDocShell)
Load the embedded data source of the document and also register it.
bool IsInitDBFields() const
Initialize data fields that lack name of database.
bool GetColumnCnt(const OUString &rSourceName, const OUString &rTableName, const OUString &rColumnName, sal_uInt32 nAbsRecordId, LanguageType nLanguage, OUString &rResult, double *pNumber)
SwDoc * m_pDoc
The document that owns this manager.
void CommitLastRegistrations()
Accept not committed registrations.
void ToNextRecord(const OUString &rDataSource, const OUString &rTableOrQuery)
static css::uno::Reference< css::sdbc::XResultSet > createCursor(const OUString &_sDataSourceName, const OUString &_sCommand, sal_Int32 _nCommandType, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const SwView *pView)
creates a RowSet, which must be disposed after use.
static void StoreEmbeddedDataSource(const css::uno::Reference< css::frame::XStorable > &xStorable, const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &rStreamRelPath, const OUString &rOwnURL, bool bCopyTo=false)
static void RevokeDataSource(const OUString &rName)
Unregister a data source.
SAL_DLLPRIVATE SwDSParam * FindDSData(const SwDBData &rData, bool bCreate)
MergeStatus m_aMergeStatus
current / last merge status
SAL_DLLPRIVATE bool MergeMailFiles(SwWrtShell *pSh, const SwMergeDescriptor &rMergeDescriptor)
Run the mail merge for defined modes, except DBMGR_MERGE.
void SetInitDBFields(bool b)
bool IsMergeError() const
sal_uInt32 GetSelectedRecordId()
std::unique_ptr< SwDBManager_Impl > m_pImpl
static OUString GetEventName(sal_Int32 nId)
const SwView * GetView() const
SwDoc * GetDoc()
returns Doc. But be careful!
SwDBData const & GetDBData()
IDocumentState const & getIDocumentState() const
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
SfxObjectShell * CreateCopy(bool bCallInitNew, bool bEmpty) const
void SetInMailMerge(bool bNew)
SwDBManager * GetDBManager() const
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
IDocumentUndoRedo & GetIDocumentUndoRedo()
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
void SetDBManager(SwDBManager *pNewMgr)
void ReplaceDocumentProperties(const SwDoc &rSource, bool mailMerge=false)
Replace document properties with those from rSource.
SwDocShell * GetDocShell()
virtual void CalcLayout() override
To enable set up of StartActions and EndActions.
bool DoesGroupUndo() const
void StartAllAction()
For all views of this document.
size_t GetSectionFormatCount() const
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
bool IsExpFieldsLocked() const
void ChangeDBFields(const std::vector< OUString > &rOldNames, const OUString &rNewName)
bool ConvertFieldsToText()
Replace fields by text - mailmerge support.
void UpdateSection(size_t const nSect, SwSectionData &, SfxItemSet const *const =nullptr)
SwDBData const & GetDBData() const
Database information.
void SetNumberingRestart()
Set all numbering start points to a fixed value - mailmerge support.
void DoGroupUndo(bool bUn)
const SwSectionFormat & GetSectionFormat(size_t nFormat) const
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
void SetLabelDoc(bool bFlag)
Labels: Synchronize ranges.
sal_uInt16 GetVirtPageNum() const
static const OUString & GetTypeStr(SwFieldTypesEnum nTypeId)
static std::shared_ptr< const SfxFilter > GetFileFilter(const OUString &rFileName)
Detect for the given file which filter should be used.
void AddMergedDocument(SwDocMergeInfo const &rInfo)
OUString const & GetMailAddress() const
void SetTargetView(SwView *pView)
bool IsMailReplyTo() const
OUString const & GetMailReplyTo() const
Marks a node in the document model.
PaM is Point and Mark: a selection of the document model.
void SetDBvalue(bool bSet)
void SetType(SectionType const eNew)
SectionType GetType() const
void SetLinkFileName(OUString const &rNew)
void SetIdle(bool b) const
const SwViewOption * GetViewOptions() const
SwWrtShell & GetWrtShell() const
std::shared_ptr< SwMailMergeConfigItem > const & GetMailMergeConfigItem() const
SwWrtShell * GetWrtShellPtr() const
SwDocShell * GetDocShell()
Used by the UI to modify the document model.
void ChgDBData(const SwDBData &SwDBData)
bool DelRight(bool isReplaceHeuristic=false)
bool HasSelection() const
const SwView & GetView() const
Gives UNO access to the global mail merge functionality, via the com.sun.star.text....
void SetTimeout(sal_uInt64 nTimeoutMs)
virtual void Start(bool bStartTimer=true) override
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
void SetContext(Context _eNewContext)
bool has(DataAccessDescriptorProperty _eWhich) const
OUString getDataSource() const
void setDataSource(const OUString &_sDataSourceNameOrLocation)
OUString const & GetURL() const
virtual Point GetPosPixel() const
virtual void SetPosPixel(const Point &rNewPos)
weld::Window * GetFrameWeld() const
virtual OUString get_active_text() const=0
void append(const weld::ComboBoxEntry &rItem)
void append_text(const OUString &rStr)
void set_active_text(const OUString &rStr)
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
static bool lcl_MoveAbsolute(SwDSParam *pParam, tools::Long nAbsPos)
static bool lcl_getCountFromResultSet(sal_Int32 &rCount, const SwDSParam *pParam)
static void lcl_SaveDebugDoc(SfxObjectShell *xTargetDocShell, const char *name, int no=0)
static bool lcl_ToNextRecord(SwDSParam *pParam, const SwDBNextRecord action=SwDBNextRecord::NEXT)
static SfxObjectShell * lcl_CreateWorkingDocument(const WorkingDocType aType, const SwWrtShell &rSourceWrtShell, const vcl::Window *pSourceWindow, SwDBManager **const ppDBManager, SwView **const pView, SwWrtShell **const pWrtShell, rtl::Reference< SwDoc > *const pDoc)
static void lcl_PreparePrinterOptions(const uno::Sequence< beans::PropertyValue > &rInPrintOptions, uno::Sequence< beans::PropertyValue > &rOutPrintOptions)
static rtl::Reference< SwMailMessage > lcl_CreateMailFromDoc(const SwMergeDescriptor &rMergeDescriptor, const OUString &sFileURL, const OUString &sMailRecipient, const OUString &sMailBodyMimeType, rtl_TextEncoding sMailEncoding, const OUString &sAttachmentMimeType)
static bool lcl_SaveDoc(const INetURLObject *pFileURL, const std::shared_ptr< const SfxFilter > &pStoreToFilter, const OUString *pStoreToFilterOptions, const uno::Sequence< beans::PropertyValue > *pSaveToFilterData, const bool bIsPDFexport, SfxObjectShell *xObjectShell, SwWrtShell &rWorkShell, OUString *const decodedURL=nullptr)
static void lcl_InitNumberFormatter(SwDSParam &rParam, uno::Reference< sdbc::XDataSource > const &xSource)
static void lcl_RemoveSectionLinks(SwWrtShell &rWorkShell)
static void lcl_PrepareSaveFilterDataOptions(const uno::Sequence< beans::PropertyValue > &rInSaveFilterDataptions, uno::Sequence< beans::PropertyValue > &rOutSaveFilterDataOptions, const OUString &sPassword)
static void lcl_GetColumnCnt(SwDSParam *pParam, const uno::Reference< beans::XPropertySet > &rColumnProps, LanguageType nLanguage, OUString &rResult, double *pNumber)
@ DBMGR_MERGE_EMAIL
Send mail merge as email.
@ DBMGR_MERGE
Data records in fields.
@ DBMGR_MERGE_SHELL
Create merge doc and keep the doc shell.
@ DBMGR_MERGE_PRINTER
Print mail merge.
@ DBMGR_MERGE_FILE
Save mail merge as files.
#define suppress_fun_call_w_exception(expr)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream)
#define ERRCODE_IO_NOTSUPPORTED
Reference< XSingleServiceFactory > xFactory
css::uno::Sequence< OUString > aBlindCopiesTo
css::uno::Sequence< OUString > aCopiesTo
css::uno::Reference< css::mail::XSmtpService > xSmtpServer
OUString sPrefix
Basename incl.
OUString sDBPasswordColumn
DB column to fetch password.
bool bPrefixIsFilename
Use the sPrefix as the target filename also overwriting an existing target file.
OUString sDBcolumn
DB column to fetch EMail of Filename from.
css::uno::Sequence< css::beans::PropertyValue > aPrintOptions
css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData
OUString sSaveToFilterOptions
CharClass & GetAppCharClass()
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
constexpr OUStringLiteral aData
bool UCB_DeleteFile(const OUString &rURL)
bool CheckMailAddress(std::u16string_view aMailAddress)
void Dispose(const T &xInterface)
const LanguageTag & getLocale()
OString stripStart(const OString &rIn, char c)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Dialog to specify the properties of date form field.
DBConnURIType GetDBunoType(const INetURLObject &rURL)
OUString CreateTempURL(const OUString *pParent, bool bDirectory)
sal_Int32 toInt32(std::u16string_view rStr)
const Color aColNames[SC_RANGECOLORS]
constexpr auto SFX_INTERFACE_NONE
std::unique_ptr< SwDSParam > pMergeData
std::mutex m_aAllEmailSendMutex
rtl::Reference< SwDBManager::ConnectionDisposedListener_Impl > m_xDisposeListener
rtl::Reference< SwDataSourceRemovedListener > m_xDataSourceRemovedListener
uno::Reference< mail::XMailMessage > m_xLastMessage
SwDBManager_Impl(SwDBManager &rDBManager)
VclPtr< AbstractMailMergeDlg > pMergeDialog
css::uno::Reference< css::util::XNumberFormatter > xFormatter
css::uno::Reference< css::sdbc::XResultSet > xResultSet
css::uno::Reference< css::sdbc::XStatement > xStatement
css::util::Date aNullDate
css::uno::Reference< css::sdbc::XConnection > xConnection
css::uno::Sequence< css::uno::Any > aSelection
bool HasValidRecord() const
tools::Long nSelectionIndex
sw::mark::IMark * startPageInTarget
const svx::ODataAccessDescriptor & rDescriptor
const DBManagerOptions nMergeType
SwMailMergeConfigItem * pMailMergeConfigItem
bool bCreateSingleFile
Create a single or multiple results.
#define STR_SW_EVENT_FIELD_MERGE
#define STR_SW_EVENT_MAIL_MERGE
#define STR_SW_EVENT_MAIL_MERGE_END
#define STR_SW_EVENT_FIELD_MERGE_FINISHED
OUString SwResId(TranslateId aId)