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 )
825 if( pStoreToFilterOptions )
827 *pStoreToFilterOptions));
828 if( pSaveToFilterData->hasElements() )
839 bool bAnyError = !xObjectShell->
DoSaveAs(*pDstMed);
853 const uno::Sequence< beans::PropertyValue >& rInPrintOptions,
854 uno::Sequence< beans::PropertyValue >& rOutPrintOptions)
863 for(
const beans::PropertyValue& rOption : rInPrintOptions)
865 if( rOption.Name ==
"CopyCount" || rOption.Name ==
"FileName"
866 || rOption.Name ==
"Collate" || rOption.Name ==
"Pages"
867 || rOption.Name ==
"Wait" || rOption.Name ==
"PrinterName" )
870 rOutPrintOptions.realloc(
nIndex + 1 );
871 auto pOutPrintOptions = rOutPrintOptions.getArray();
872 pOutPrintOptions[
nIndex ].Name = rOption.Name;
873 pOutPrintOptions[
nIndex++ ].Value = rOption.Value ;
879 const uno::Sequence< beans::PropertyValue >& rInSaveFilterDataptions,
880 uno::Sequence< beans::PropertyValue >& rOutSaveFilterDataOptions,
881 const OUString& sPassword)
883 rOutSaveFilterDataOptions
889 for(
const beans::PropertyValue& rOption : rInSaveFilterDataptions)
891 rOutSaveFilterDataOptions.realloc(
nIndex + 1 );
892 auto pOutSaveFilterDataOptions = rOutSaveFilterDataOptions.getArray();
893 pOutSaveFilterDataOptions[
nIndex ].Name = rOption.Name;
894 pOutSaveFilterDataOptions[
nIndex++ ].Value = rOption.Value ;
902 const WorkingDocType aType,
const SwWrtShell &rSourceWrtShell,
910 const SwDoc *pSourceDoc = rSourceWrtShell.
GetDoc();
925 pWorkWrtShell->GetViewOptions()->SetIdle(
false );
926 pWorkView->AttrChangedNotify(
nullptr);
927 SwDoc* pWorkDoc = pWorkWrtShell->GetDoc();
938 if( aType == WorkingDocType::TARGET )
940 assert( !ppDBManager );
942 pWorkWrtShell->SetLabelDoc(
false );
947 assert(ppDBManager && *ppDBManager);
950 *ppDBManager = pWorkDBManager;
952 if( aType == WorkingDocType::SOURCE )
955 pWorkWrtShell->ChgDBData(
const_cast<SwDoc*
>(pSourceDoc)->GetDBData() );
957 pWorkWrtShell->SetLabelDoc( rSourceWrtShell.
IsLabelDoc() );
964 if( pView ) *pView = pWorkView;
965 if( pWrtShell ) *pWrtShell = pWorkWrtShell;
966 if( pDoc ) *pDoc = pWorkDoc;
969 return xWorkObjectShell.
get();
974 const OUString &sFileURL,
const OUString &sMailRecipient,
975 const OUString &sMailBodyMimeType, rtl_TextEncoding sMailEncoding,
976 const OUString &sAttachmentMimeType )
981 pMessage->addRecipient( sMailRecipient );
984 OUStringBuffer sBody;
988 mail::MailAttachment aAttach;
992 pMessage->addAttachment( aAttach );
997 SfxMedium aMedium( sFileURL, StreamMode::READ );
999 assert( pInStream &&
"no output file created?" );
1004 OStringBuffer sLine;
1005 while ( pInStream->
ReadLine( sLine ) )
1007 sBody.append(OStringToOUString( sLine, sMailEncoding ) +
"\n");
1010 pMessage->setSubject( rMergeDescriptor.
sSubject );
1011 uno::Reference< datatransfer::XTransferable> xBody =
1013 pMessage->setBody( xBody );
1015 for(
const OUString& sCcRecipient : rMergeDescriptor.
aCopiesTo )
1016 pMessage->addCcRecipient( sCcRecipient );
1017 for(
const OUString& sBccRecipient : rMergeDescriptor.
aBlindCopiesTo )
1018 pMessage->addBccRecipient( sBccRecipient );
1033 virtual void mailDelivered( uno::Reference< mail::XMailMessage> xMessage )
override
1041 uno::Reference< mail::XMailMessage>,
const OUString& )
override
1046 xMailDispatcher->stop();
1066 const bool bNeedsTempFiles = ( bMT_EMAIL || bMT_FILE );
1070 OUString sPrefix_ = rMergeDescriptor.
sPrefix;
1074 assert(!bCheckSingleFile_);
1075 bCheckSingleFile_ =
false;
1077 else if( bMT_SHELL || bMT_PRINTER )
1079 assert(bCheckSingleFile_);
1080 bCheckSingleFile_ =
true;
1081 assert(sPrefix_.isEmpty());
1084 const bool bCreateSingleFile = bCheckSingleFile_;
1085 const OUString sDescriptorPrefix = sPrefix_;
1088 static const sal_Int32 nMaxDumpDocs = []() {
1089 if (
const char* sEnv = getenv(
"SW_DEBUG_MAILMERGE_DOCS"))
1090 return OUString(sEnv, strlen(sEnv), osl_getThreadTextEncoding()).
toInt32();
1092 return sal_Int32(0);
1097 OUString sMailBodyMimeType;
1098 rtl_TextEncoding sMailEncoding = ::osl_getThreadTextEncoding();
1100 uno::Reference< beans::XPropertySet > xColumnProp;
1101 uno::Reference< beans::XPropertySet > xPasswordColumnProp;
1105 bool bColumnName = !rMergeDescriptor.
sDBcolumn.isEmpty();
1115 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(
m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
1116 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1117 if( !xCols->hasByName( rMergeDescriptor.
sDBcolumn ) )
1120 aCol >>= xColumnProp;
1122 if(bPasswordColumnName)
1125 aCol >>= xPasswordColumnProp;
1134 m_pImpl->m_xLastMessage.clear();
1138 xMailDispatcher->addListener( xMailListener );
1141 sMailBodyMimeType =
"text/html; charset=utf-8";
1142 sMailEncoding = RTL_TEXTENCODING_UTF8;
1145 sMailBodyMimeType =
"text/plain; charset=UTF-8; format=flowed";
1155 const OUString* pStoreToFilterOptions =
nullptr;
1160 OUString sExtension = rMergeDescriptor.
bSendAsHTML ? OUString(
"html") : OUString(
"txt");
1161 pStoreToFilter = pFilterContainer->
GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
1165 std::shared_ptr<const SfxFilter> pFilter =
1169 pStoreToFilter = pFilter;
1174 const bool bIsPDFexport = pStoreToFilter && pStoreToFilter->GetFilterName() ==
"writer_pdf_Export";
1175 const bool bIsMultiFile = bMT_FILE && !bCreateSingleFile;
1186 std::unique_ptr< utl::TempFileNamed > aTempFile;
1187 sal_uInt16 nStartingPageNo = 0;
1189 std::shared_ptr<weld::GenericDialogController> xProgressDlg;
1194 if( !bIsMergeSilent )
1199 xProgressDlg = std::make_shared<CreateMonitor>(pSourceWindow->
GetFrameWeld());
1202 xProgressDlg = std::make_shared<PrintMonitor>(pSourceWindow->
GetFrameWeld());
1203 static_cast<PrintMonitor*
>(xProgressDlg.get())->set_title(
1209 xProgressDlg.reset();
1215 if( bCreateSingleFile && !pTargetView )
1219 *pSourceShell, bMT_SHELL ? pSourceWindow :
nullptr,
1220 nullptr, &pTargetView, &pTargetShell, &pTargetDoc );
1225 else if( pTargetView )
1230 pTargetDoc = pTargetShell->
GetDoc();
1235 if( bCreateSingleFile )
1243 SfxProgress aProgress(pSourceDocSh, OUString(), 1);
1253 sal_Int32 nDocNo = 1;
1260 int targetDocPageCount = 0;
1262 if( !bIsMergeSilent && !bMT_PRINTER )
1264 sal_Int32 nRecordCount = 1;
1270 sal_Int32 nRecordPerDoc = pSourceShell->
GetDoc()
1272 if ( bSynchronizedDoc && (nRecordPerDoc > 1) )
1274 assert( nRecordPerDoc > 0 );
1276 sal_Int32 nMaxDocs = nRecordCount / nRecordPerDoc;
1277 if ( 0 != nRecordCount % nRecordPerDoc )
1279 static_cast<CreateMonitor*
>(xProgressDlg.get())->SetTotalCount(nMaxDocs);
1282 sal_Int32 nStartRow, nEndRow;
1283 bool bFreezedLayouts =
false;
1285 std::vector< OUString> aFilesToRemove;
1290 SwView* pWorkView =
nullptr;
1294 bool bWorkDocInitialized =
false;
1298 nStartRow =
m_pImpl->pMergeData ?
m_pImpl->pMergeData->xResultSet->getRow() : 0;
1300 OUString sColumnData;
1304 if( bMT_EMAIL || bColumnName )
1306 sColumnData =
GetDBField( xColumnProp, aColumnDBFormat );
1310 if( bNeedsTempFiles && ( !bWorkDocInitialized || !bCreateSingleFile ))
1312 OUString
sPrefix = sDescriptorPrefix;
1316 if( bColumnName && !bMT_EMAIL )
1318 if (!sColumnData.isEmpty())
1319 sLeading = sColumnData;
1333 if( !aTempFile->IsValid() )
1340 uno::Sequence< beans::PropertyValue > aSaveToFilterDataOptions( rMergeDescriptor.
aSaveToFilterData );
1342 if( bMT_EMAIL || bPasswordColumnName )
1344 OUString sPasswordColumnData =
GetDBField( xPasswordColumnProp, aColumnDBFormat );
1350 std::unique_ptr< INetURLObject > aTempFileURL;
1351 if( bNeedsTempFiles )
1352 aTempFileURL.reset(
new INetURLObject(aTempFile->GetURL()));
1353 if( !bIsMergeSilent ) {
1355 static_cast<CreateMonitor*
>(xProgressDlg.get())->SetCurrentPosition(nDocNo);
1358 pPrintMonDlg->
m_xPrinter->set_label(bNeedsTempFiles
1359 ? aTempFileURL->GetBase() : pSourceDocSh->
GetTitle( 2));
1360 OUString sStat =
SwResId(STR_STATSTR_LETTER) +
" " + OUString::number( nDocNo );
1371 if( !bWorkDocInitialized || bCreateSingleFile || bIsPDFexport || bIsMultiFile )
1373 assert( !xWorkDocSh.
Is());
1374 pWorkDocOrigDBManager =
this;
1376 *pSourceShell,
nullptr, &pWorkDocOrigDBManager,
1377 &pWorkView, &pWorkShell, &pWorkDoc );
1378 if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1392 aLayout->FreezeLayout(
false);
1393 aLayout->AllCheckPageDescs();
1404 pWorkShell->SwViewShell::UpdateFields();
1415 text::MailMergeEvent aEvt(
static_cast<text::XMailMergeBroadcaster*
>(xRef.get()), xWorkDocSh->
GetModel() );
1417 xRef->LaunchMailMergeEvent( aEvt );
1422 if( bCreateSingleFile )
1424 assert( pTargetShell &&
"no target shell available!" );
1428 pWorkDoc->RemoveInvisibleContent();
1434 if( bSynchronizedDoc )
1439 if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1443 if( targetDocPageCount % 2 == 1 )
1444 ++targetDocPageCount;
1445 SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc( *pWorkDoc,
1446 nStartingPageNo, !bWorkDocInitialized, targetDocPageCount, nDocNo);
1447 targetDocPageCount += pWorkShell->
GetPageCnt();
1449 if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1458 ::sw::mark::InsertMode::New);
1459 aMergeInfo.
nDBRow = nStartRow;
1465 assert( bNeedsTempFiles );
1468 if (bIsMultiFile && pWorkDoc->HasInvisibleContent())
1470 pWorkDoc->RemoveInvisibleContent();
1477 pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1481 if( !
lcl_SaveDoc( aTempFileURL.get(), pStoreToFilter, pStoreToFilterOptions,
1482 &aSaveToFilterDataOptions, bIsPDFexport,
1483 xWorkDocSh, *pWorkShell, &sFileURL ) )
1489 pWorkDoc->SetDBManager(
this );
1494 aFilesToRemove.push_back( sFileURL );
1498 OSL_FAIL(
"invalid e-Mail address in database column");
1503 rMergeDescriptor, sFileURL, sColumnData, sMailBodyMimeType,
1504 sMailEncoding, pStoreToFilter->GetMimeType() );
1507 std::unique_lock aGuard(
m_pImpl->m_aAllEmailSendMutex );
1508 m_pImpl->m_xLastMessage.set( xMessage );
1509 xMailDispatcher->enqueueMailMessage( xMessage );
1510 if( !xMailDispatcher->isStarted() )
1511 xMailDispatcher->start();
1516 if( bCreateSingleFile || bIsPDFexport || bIsMultiFile)
1518 pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1521 xWorkDocSh =
nullptr;
1525 bWorkDocInitialized =
true;
1527 nEndRow =
m_pImpl->pMergeData ?
m_pImpl->pMergeData->xResultSet->getRow() : 0;
1531 if(!bFreezedLayouts && bCreateSingleFile)
1534 aLayout->FreezeLayout(
true);
1535 bFreezedLayouts =
true;
1546 if( !bCreateSingleFile )
1553 pWorkDoc->SetDBManager(pWorkDocOrigDBManager);
1554 if (xWorkDocSh.
Is())
1564 pTargetDoc->SetInMailMerge(
false);
1565 pTargetDoc->SetAllUniqueFlyNames();
1568 SAL_INFO(
"sw.pageframe",
"(MergeMailFiles pTargetShell->CalcLayout in" );
1570 SAL_INFO(
"sw.pageframe",
"MergeMailFiles pTargetShell->CalcLayout out)" );
1572 pTargetDoc->GetIDocumentUndoRedo().DoUndo(
true );
1575 aLayout->FreezeLayout(
false);
1576 aLayout->AllCheckPageDescs();
1584 assert( aTempFile );
1587 aTempFileURL.
SetURL( aTempFile->GetURL() );
1590 aTempFileURL.
SetURL(sDescriptorPrefix);
1592 aTempFile->EnableKillingFile();
1596 bIsPDFexport, xTargetDocShell.
get(), *pTargetShell ) )
1604 uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.
aPrintOptions );
1606 pTargetView->
ExecPrint( aOptions, bIsMergeSilent,
false );
1614 else if( xTargetDocShell.
is() )
1615 xTargetDocShell->DoClose();
1621 xProgressDlg->response(
RET_OK);
1634 if( xMailDispatcher.is() )
1640 AutoTimer aEmailDispatcherPollTimer(
"sw::SwDBManager aEmailDispatcherPollTimer");
1642 aEmailDispatcherPollTimer.
Start();
1645 aEmailDispatcherPollTimer.
Stop();
1647 xMailDispatcher->stop();
1648 xMailDispatcher->shutdown();
1654 for(
const OUString &sFileURL : aFilesToRemove )
1657 catch (
const uno::Exception&)
1677 const OUString& rTableName,
1678 const OUString& rColNm,
1685 uno::Reference< sdbc::XDataSource> xSource;
1686 uno::Reference< sdbc::XConnection> xConnection;
1687 bool bUseMergeData =
false;
1688 uno::Reference< sdbcx::XColumnsSupplier> xColsSupp;
1689 bool bDisposeConnection =
false;
1691 ((
m_pImpl->pMergeData->sDataSource == rDBName &&
m_pImpl->pMergeData->sCommand == rTableName) ||
1692 (rDBName.isEmpty() && rTableName.isEmpty())))
1694 xConnection =
m_pImpl->pMergeData->xConnection;
1696 bUseMergeData =
true;
1697 xColsSupp.set(
m_pImpl->pMergeData->xResultSet, css::uno::UNO_QUERY);
1699 if(!xConnection.is())
1702 aData.sDataSource = rDBName;
1703 aData.sCommand = rTableName;
1704 aData.nCommandType = -1;
1709 xColsSupp.set(pParam->
xResultSet, css::uno::UNO_QUERY);
1714 bDisposeConnection =
true;
1717 m_pImpl->pMergeData->xConnection = xConnection;
1719 bool bDispose = !xColsSupp.is();
1726 uno::Reference<container::XNameAccess> xCols;
1729 xCols = xColsSupp->getColumns();
1731 catch (
const uno::Exception&)
1735 if(!xCols.is() || !xCols->hasByName(rColNm))
1737 uno::Any aCol = xCols->getByName(rColNm);
1738 uno::Reference< beans::XPropertySet >
xColumn;
1743 ::comphelper::disposeComponent( xColsSupp );
1745 if(bDisposeConnection)
1747 ::comphelper::disposeComponent( xConnection );
1757 uno::Reference< sdbc::XConnection>
const & xConnection,
1758 uno::Reference< beans::XPropertySet>
const & xColumn,
1762 auto xSource = xSource_in;
1769 uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
1771 xSource.set(xChild->getParent(), uno::UNO_QUERY);
1773 if(xSource.is() && xConnection.is() &&
xColumn.is() && pNFormatr)
1776 uno::Reference< util::XNumberFormats > xDocNumberFormats = pNumFormat->getNumberFormats();
1777 uno::Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, uno::UNO_QUERY);
1782 uno::Reference<beans::XPropertySet> xSourceProps(xSource, uno::UNO_QUERY);
1783 uno::Reference< util::XNumberFormats > xNumberFormats;
1784 if(xSourceProps.is())
1786 uno::Any aFormats = xSourceProps->getPropertyValue(
"NumberFormatsSupplier");
1789 uno::Reference<util::XNumberFormatsSupplier> xSuppl;
1790 aFormats >>= xSuppl;
1793 xNumberFormats = xSuppl->getNumberFormats();
1797 bool bUseDefault =
true;
1803 sal_Int32 nFormat = 0;
1804 aFormatKey >>= nFormat;
1805 if(xNumberFormats.is())
1809 uno::Reference<beans::XPropertySet> xNumProps = xNumberFormats->getByKey( nFormat );
1810 uno::Any aFormatString = xNumProps->getPropertyValue(
"FormatString");
1811 uno::Any aLocaleVal = xNumProps->getPropertyValue(
"Locale");
1813 aFormatString >>= sFormat;
1815 aLocaleVal >>= aLoc;
1816 nFormat = xDocNumberFormats->queryKey( sFormat, aLoc,
false );
1817 if(NUMBERFORMAT_ENTRY_NOT_FOUND == sal::static_int_cast< sal_uInt32, sal_Int32>(nFormat))
1818 nFormat = xDocNumberFormats->addNew( sFormat, aLoc );
1820 bUseDefault =
false;
1822 catch (
const uno::Exception&)
1829 catch(
const uno::Exception&)
1831 SAL_WARN(
"sw.mailmerge",
"no FormatKey property found");
1840 const OUString& rTableName,
1841 const OUString& rColNm )
1843 sal_Int32 nRet = sdbc::DataType::SQLNULL;
1845 aData.sDataSource = rDBName;
1846 aData.sCommand = rTableName;
1847 aData.nCommandType = -1;
1849 uno::Reference< sdbc::XConnection> xConnection;
1850 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp;
1851 bool bDispose =
false;
1855 xColsSupp.set( pParam->
xResultSet, uno::UNO_QUERY );
1861 if( !xColsSupp.is() )
1868 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1869 if(xCols->hasByName(rColNm))
1871 uno::Any aCol = xCols->getByName(rColNm);
1872 uno::Reference<beans::XPropertySet> xCol;
1874 uno::Any aType = xCol->getPropertyValue(
"Type");
1878 ::comphelper::disposeComponent( xColsSupp );
1884 uno::Reference<sdbc::XDataSource>& rxSource,
const SwView *pView)
1886 uno::Reference< sdbc::XConnection> xConnection;
1887 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1890 uno::Reference<sdb::XCompletedConnection> xComplConnection(
dbtools::getDataSource(rDataSource, xContext), uno::UNO_QUERY);
1891 if ( xComplConnection.is() )
1893 rxSource.set(xComplConnection, uno::UNO_QUERY);
1895 uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(xContext, pWindow ? pWindow->
GetXWindow() :
nullptr), uno::UNO_QUERY_THROW );
1896 xConnection = xComplConnection->connectWithCompletion( xHandler );
1899 catch(
const uno::Exception&)
1907 const OUString& rTableOrQuery,
1910 uno::Reference< sdbcx::XColumnsSupplier> xRet;
1916 uno::Reference<sdbcx::XTablesSupplier> xTSupplier(xConnection, uno::UNO_QUERY);
1919 uno::Reference<container::XNameAccess> xTables = xTSupplier->getTables();
1920 eTableOrQuery = xTables->hasByName(rTableOrQuery) ?
1925 sdb::CommandType::TABLE : sdb::CommandType::QUERY;
1926 uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1927 uno::Reference<sdbc::XRowSet> xRowSet(xMgr->createInstance(
"com.sun.star.sdb.RowSet"), uno::UNO_QUERY);
1929 OUString sDataSource;
1931 uno::Reference<beans::XPropertySet> xSourceProperties(xSource, uno::UNO_QUERY);
1932 if(xSourceProperties.is())
1934 xSourceProperties->getPropertyValue(
"Name") >>= sDataSource;
1937 uno::Reference<beans::XPropertySet> xRowProperties(xRowSet, uno::UNO_QUERY);
1938 xRowProperties->setPropertyValue(
"DataSourceName",
uno::Any(sDataSource));
1939 xRowProperties->setPropertyValue(
"Command",
uno::Any(rTableOrQuery));
1940 xRowProperties->setPropertyValue(
"CommandType",
uno::Any(nCommandType));
1941 xRowProperties->setPropertyValue(
"FetchSize",
uno::Any(sal_Int32(10)));
1942 xRowProperties->setPropertyValue(
"ActiveConnection",
uno::Any(xConnection));
1944 xRet.set( xRowSet, uno::UNO_QUERY );
1946 catch (
const uno::Exception&)
1958 uno::Reference< sdb::XColumn >
xColumn(xColumnProps, uno::UNO_QUERY);
1960 assert(
xColumn.is() &&
"SwDBManager::::ImportDBField: illegal arguments" );
1964 uno::Any aType = xColumnProps->getPropertyValue(
"Type");
1965 sal_Int32 eDataType = sdbc::DataType::SQLNULL;
1966 aType >>= eDataType;
1969 case sdbc::DataType::CHAR:
1970 case sdbc::DataType::VARCHAR:
1971 case sdbc::DataType::LONGVARCHAR:
1975 sRet = sRet.replace(
'\xb',
'\n' );
1977 catch(
const sdbc::SQLException&)
1981 case sdbc::DataType::BIT:
1982 case sdbc::DataType::BOOLEAN:
1983 case sdbc::DataType::TINYINT:
1984 case sdbc::DataType::SMALLINT:
1985 case sdbc::DataType::INTEGER:
1986 case sdbc::DataType::BIGINT:
1987 case sdbc::DataType::FLOAT:
1988 case sdbc::DataType::REAL:
1989 case sdbc::DataType::DOUBLE:
1990 case sdbc::DataType::NUMERIC:
1991 case sdbc::DataType::DECIMAL:
1992 case sdbc::DataType::DATE:
1993 case sdbc::DataType::TIME:
1994 case sdbc::DataType::TIMESTAMP:
2006 double fVal =
xColumn->getDouble();
2013 catch (
const uno::Exception&)
2027 const OUString& rTableOrQuery,
bool bMergeShell)
2031 return ((rDataSource ==
m_pImpl->pMergeData->sDataSource
2032 && rTableOrQuery ==
m_pImpl->pMergeData->sCommand)
2033 || (rDataSource.isEmpty() && rTableOrQuery.isEmpty()))
2034 &&
m_pImpl->pMergeData->xResultSet.is();
2036 else if(!bMergeShell)
2039 aData.sDataSource = rDataSource;
2040 aData.sCommand = rTableOrQuery;
2041 aData.nCommandType = -1;
2050 const OUString& rColumnName, sal_uInt32 nAbsRecordId,
2052 OUString& rResult,
double* pNumber)
2058 rSourceName ==
m_pImpl->pMergeData->sDataSource &&
2059 rTableName ==
m_pImpl->pMergeData->sCommand)
2061 pFound =
m_pImpl->pMergeData.get();
2066 aData.sDataSource = rSourceName;
2067 aData.sCommand = rTableName;
2068 aData.nCommandType = -1;
2078 [nAbsRecordId](
const uno::Any& rSelection) {
2079 sal_Int32 nSelection = 0;
2080 rSelection >>= nSelection;
2081 return nSelection == static_cast<sal_Int32>(nAbsRecordId);
2088 sal_Int32 nOldRow = 0;
2093 catch(
const uno::Exception&)
2099 if ( nOldRow !=
static_cast<sal_Int32
>(nAbsRecordId) )
2103 if ( nOldRow !=
static_cast<sal_Int32
>(nAbsRecordId) )
2111 OUString &rResult,
double *pNumber)
2125 assert(
m_pImpl->pMergeData &&
m_pImpl->pMergeData->xResultSet.is() &&
"no data source in merge" );
2135 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(
m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
2136 if( !xColsSupp.is() )
2140 uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
2141 const uno::Sequence<OUString>
aColNames = xCols->getElementNames();
2148 for(
const OUString& rColName :
aColNames )
2151 sal_Int32 nColumnType = sdbc::DataType::SQLNULL;
2152 uno::Any aCol = xCols->getByName( rColName );
2153 uno::Reference<beans::XPropertySet> xColumnProps;
2154 aCol >>= xColumnProps;
2155 uno::Any aType = xColumnProps->getPropertyValue(
"Type" );
2156 aType >>= nColumnType;
2157 double aNumber = DBL_MAX;
2162 m_pImpl->pMergeData->sCommand,
2163 rColName, pDocFormatter, nLanguage );
2165 bool colIsNumber = aNumber != DBL_MAX;
2167 aNumber, nColumnType );
2175 SAL_INFO(
"sw.ui",
"'" << rColName <<
"': " << aNumber <<
" / " << aString );
2184 SAL_INFO(
"sw.ui",
"'" << rColName <<
"': " << aString );
2194 const OUString& rDataSource,
const OUString& rCommand)
2198 rDataSource ==
m_pImpl->pMergeData->sDataSource &&
2199 rCommand ==
m_pImpl->pMergeData->sCommand)
2201 pFound =
m_pImpl->pMergeData.get();
2206 aData.sDataSource = rDataSource;
2207 aData.sCommand = rCommand;
2208 aData.nCommandType = -1;
2218 assert( SwDBNextRecord::NEXT ==
action ||
2219 (SwDBNextRecord::FIRST ==
action && pParam) );
2220 if(
nullptr == pParam )
2223 if(
action == SwDBNextRecord::FIRST )
2245 else if(
action == SwDBNextRecord::FIRST )
2251 sal_Int32 nBefore = pParam->
xResultSet->getRow();
2256 ::dbtools::throwFunctionSequenceException( pParam->
xResultSet );
2263 catch(
const uno::Exception & )
2267 "sw.mailmerge",
"exception in ToNextRecord()");
2279 return(
m_pImpl->pMergeData &&
m_pImpl->pMergeData->HasValidRecord() );
2284 sal_uInt32 nRet = 0;
2285 assert(
m_pImpl->pMergeData &&
2286 m_pImpl->pMergeData->xResultSet.is() &&
"no data source in merge" );
2287 if(!
m_pImpl->pMergeData || !
m_pImpl->pMergeData->xResultSet.is())
2291 nRet =
m_pImpl->pMergeData->xResultSet->getRow();
2293 catch(
const uno::Exception&)
2301 assert(
m_pImpl->pMergeData &&
2302 m_pImpl->pMergeData->xResultSet.is() &&
"no data source in merge" );
2303 if(!
m_pImpl->pMergeData || !
m_pImpl->pMergeData->xResultSet.is()|| nSet < 0)
2306 sal_Int32 nAbsPos = nSet;
2307 assert(nAbsPos >= 0);
2309 m_pImpl->pMergeData->bEndOfDB = !bRet;
2316 aData.sDataSource = rDataSource;
2317 aData.sCommand = rTableOrQuery;
2318 aData.nCommandType = -1;
2330 uno::Reference< sdbc::XDatabaseMetaData > xMetaData = pFound->
xConnection->getMetaData();
2334 ->supportsResultSetType(sal_Int32(sdbc::ResultSetType::SCROLL_INSENSITIVE));
2336 catch(
const uno::Exception&)
2342 OUString aQuoteChar = xMetaData->getIdentifierQuoteString();
2343 OUString sStatement =
"SELECT * FROM " + aQuoteChar + rTableOrQuery + aQuoteChar;
2350 catch (
const uno::Exception&)
2363 uno::Reference< sdbc::XDataSource> xSource;
2370 uno::Reference<lang::XComponent> xComponent(pFound->
xConnection, uno::UNO_QUERY);
2372 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
2374 catch(
const uno::Exception&)
2382 const OUString& rDataSource,
const OUString& rTableOrQuery, sal_Int32 nCommandType)
2384 sal_uInt32 nRet = 0xffffffff;
2387 ((rDataSource ==
m_pImpl->pMergeData->sDataSource &&
2388 rTableOrQuery ==
m_pImpl->pMergeData->sCommand) ||
2389 (rDataSource.isEmpty() && rTableOrQuery.isEmpty())) &&
2390 (nCommandType == -1 || nCommandType ==
m_pImpl->pMergeData->nCommandType) &&
2391 m_pImpl->pMergeData->xResultSet.is())
2398 aData.sDataSource = rDataSource;
2399 aData.sCommand = rTableOrQuery;
2400 aData.nCommandType = nCommandType;
2409 if(nSelIndex >= pFound->
aSelection.getLength())
2410 nSelIndex = pFound->
aSelection.getLength() -1;
2411 pFound->
aSelection.getConstArray()[nSelIndex] >>= nRet;
2417 catch(
const uno::Exception&)
2432 if (bIncludingMerge || pParam.get() !=
m_pImpl->pMergeData.get())
2434 pParam->nSelectionIndex = 0;
2435 pParam->bEndOfDB =
false;
2439 pParam->xResultSet->first();
2441 catch(
const uno::Exception&)
2455 (bCreate &&
m_pImpl->pMergeData->nCommandType == -1)))
2457 return m_pImpl->pMergeData.get();
2478 if(bCreate && !pFound)
2484 uno::Reference<lang::XComponent> xComponent(pFound->
xConnection, uno::UNO_QUERY);
2486 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
2488 catch(
const uno::Exception&)
2498 if(
m_pImpl->pMergeData && rDataSource ==
m_pImpl->pMergeData->sDataSource )
2501 return m_pImpl->pMergeData.get();
2506 if(rDataSource == pParam->sDataSource)
2509 pFound = pParam.get();
2513 if(bCreate && !pFound)
2516 aData.sDataSource = rDataSource;
2522 uno::Reference<lang::XComponent> xComponent(pFound->
xConnection, uno::UNO_QUERY);
2524 xComponent->addEventListener(
m_pImpl->m_xDisposeListener);
2526 catch(
const uno::Exception&)
2535 return SW_MOD()->GetDBConfig()->GetAddressSource();
2540 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2541 uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
2542 return xDBContext->getElementNames();
2556 else if (sExt.equalsIgnoreAsciiCase(
"sxc")
2557 || sExt.equalsIgnoreAsciiCase(
"ods")
2558 || sExt.equalsIgnoreAsciiCase(
"xls")
2559 || sExt.equalsIgnoreAsciiCase(
"xlsx"))
2563 else if (sExt.equalsIgnoreAsciiCase(
"sxw") || sExt.equalsIgnoreAsciiCase(
"odt") || sExt.equalsIgnoreAsciiCase(
"doc") || sExt.equalsIgnoreAsciiCase(
"docx"))
2567 else if (sExt.equalsIgnoreAsciiCase(
"dbf"))
2571 else if (sExt.equalsIgnoreAsciiCase(
"csv") || sExt.equalsIgnoreAsciiCase(
"txt"))
2576 else if (sExt.equalsIgnoreAsciiCase(
"mdb") || sExt.equalsIgnoreAsciiCase(
"mde"))
2580 else if (sExt.equalsIgnoreAsciiCase(
"accdb") || sExt.equalsIgnoreAsciiCase(
"accde"))
2595 if (rType == DBConnURIType::UNKNOWN)
2599 case DBConnURIType::UNKNOWN:
2600 case DBConnURIType::ODB:
2602 case DBConnURIType::CALC:
2604 OUString sDBURL =
"sdbc:calc:" +
2609 case DBConnURIType::WRITER:
2611 OUString sDBURL =
"sdbc:writer:" +
2616 case DBConnURIType::DBASE:
2619 aUrlTmp.removeSegment();
2620 aUrlTmp.removeFinalSlash();
2621 OUString sDBURL =
"sdbc:dbase:" +
2626 case DBConnURIType::FLAT:
2629 aUrlTmp.removeSegment();
2630 aUrlTmp.removeFinalSlash();
2631 OUString sDBURL =
"sdbc:flat:" +
2637 case DBConnURIType::MSJET:
2640 OUString sDBURL(
"sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + rURL.
PathToFileName());
2645 case DBConnURIType::MSACE:
2648 OUString sDBURL(
"sdbc:ado:PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=" + rURL.
PathToFileName());
2676OUString LoadAndRegisterDataSource_Impl(
DBConnURIType type,
const uno::Reference< beans::XPropertySet > *pSettings,
2686 uno::Any aURLAny = GetDBunoURI(rURL, type);
2688 case DBConnURIType::UNKNOWN:
2689 case DBConnURIType::CALC:
2690 case DBConnURIType::WRITER:
2692 case DBConnURIType::ODB:
2695 case DBConnURIType::FLAT:
2696 case DBConnURIType::DBASE:
2700 aTableFilterAny <<= aFilters;
2703 case DBConnURIType::MSJET:
2704 case DBConnURIType::MSACE:
2705 aSuppressVersionsAny <<=
true;
2711 uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
2712 uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
2714 OUString sNewName = rURL.
getName(
2716 sal_Int32 nExtLen = sExt.getLength();
2717 sNewName = sNewName.replaceAt(sNewName.getLength() - nExtLen - 1, nExtLen + 1, u
"");
2722 while (xDBContext->hasByName(sFind))
2723 sFind = sNewName + OUString::number(++nIndex);
2725 uno::Reference<uno::XInterface> xNewInstance;
2730 aDataSource >>= xNewInstance;
2734 xNewInstance = xDBContext->createInstance();
2735 uno::Reference<beans::XPropertySet> xDataProperties(xNewInstance, uno::UNO_QUERY);
2738 xDataProperties->setPropertyValue(
"URL", aURLAny);
2740 xDataProperties->setPropertyValue(
"TableFilter", aTableFilterAny);
2741 if (aSuppressVersionsAny.
hasValue())
2742 xDataProperties->setPropertyValue(
"SuppressVersionColumns", aSuppressVersionsAny);
2744 xDataProperties->setPropertyValue(
"Info", aInfoAny);
2746 if (DBConnURIType::FLAT == type && pSettings)
2748 uno::Any aSettings = xDataProperties->getPropertyValue(
"Settings");
2749 uno::Reference < beans::XPropertySet > xDSSettings;
2750 aSettings >>= xDSSettings;
2751 ::comphelper::copyProperties(*pSettings, xDSSettings);
2752 xDSSettings->setPropertyValue(
"Extension",
uno::Any(sExt));
2755 uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, uno::UNO_QUERY_THROW);
2756 uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW);
2757 OUString aOwnURL = getOwnURL(pDocShell);
2758 if (aOwnURL.isEmpty())
2762 const OUString sTmpName =
utl::CreateTempURL(sNewName,
true, u
".odb", pDestDir ? pDestDir : &sHomePath);
2763 xStore->storeAsURL(sTmpName, uno::Sequence<beans::PropertyValue>());
2768 OUString aStreamRelPath =
"EmbeddedDatabase";
2769 uno::Reference<embed::XStorage> xStorage = pDocShell->
GetStorage();
2773 uno::Reference<lang::XMultiServiceFactory>
xFactory(pDocShell->
GetModel(), uno::UNO_QUERY);
2774 uno::Reference<beans::XPropertySet> xPropertySet(
xFactory->createInstance(
"com.sun.star.document.Settings"), uno::UNO_QUERY);
2775 xPropertySet->setPropertyValue(
"EmbeddedDatabaseName",
uno::Any(aStreamRelPath));
2781 xDBContext->registerObject(sFind, xNewInstance);
2783 catch (
const uno::Exception&)
2793 sfx2::FileDialogHelper aDlgHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, pParent);
2795 uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDlgHelper.
GetFilePicker();
2797 OUString sFilterAll(
SwResId(STR_FILTER_ALL));
2798 OUString sFilterAllData(
SwResId(STR_FILTER_ALL_DATA));
2800 const std::vector<std::pair<OUString, OUString>> filters{
2801 {
SwResId(STR_FILTER_SXB),
"*.odb" },
2802 {
SwResId(STR_FILTER_SXC),
"*.ods;*.sxc" },
2803 {
SwResId(STR_FILTER_SXW),
"*.odt;*.sxw" },
2804 {
SwResId(STR_FILTER_DBF),
"*.dbf" },
2805 {
SwResId(STR_FILTER_XLS),
"*.xls;*.xlsx" },
2806 {
SwResId(STR_FILTER_DOC),
"*.doc;*.docx" },
2807 {
SwResId(STR_FILTER_TXT),
"*.txt" },
2808 {
SwResId(STR_FILTER_CSV),
"*.csv" },
2810 {
SwResId(STR_FILTER_MDB),
"*.mdb;*.mde" },
2811 {
SwResId(STR_FILTER_ACCDB),
"*.accdb;*.accde" },
2815 OUStringBuffer sAllDataFilter;
2819 if (!sAllDataFilter.isEmpty())
2820 sAllDataFilter.append(
';');
2821 sAllDataFilter.append(
filter);
2824 xFP->appendFilter( sFilterAll,
"*" );
2825 xFP->appendFilter( sFilterAllData, sAllDataFilter.makeStringAndClear());
2831 xFP->setCurrentFilter( sFilterAll ) ;
2835 uno::Reference< beans::XPropertySet > aSettings;
2839 if( DBConnURIType::FLAT ==
type )
2841 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2842 uno::Reference < sdb::XTextConnectionSettings > xSettingsDlg = sdb::TextConnectionSettings::create(xContext);
2843 if( xSettingsDlg->execute() )
2844 aSettings.set( uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY_THROW ) );
2846 sFind = LoadAndRegisterDataSource_Impl(
type, DBConnURIType::FLAT ==
type ? &aSettings :
nullptr,
aURL,
nullptr, pDocShell );
2854 const uno::Reference<embed::XStorage>& xStorage,
2855 const OUString& rStreamRelPath,
2856 const OUString& rOwnURL,
bool bCopyTo)
2859 OUString
const sTmpName = ConstructVndSunStarPkgUrl(rOwnURL, rStreamRelPath);
2863 {
"TargetStorage",
uno::Any(xStorage)},
2864 {
"StreamRelPath",
uno::Any(rStreamRelPath)},
2868 xStorable->storeToURL(sTmpName, aSequence);
2870 xStorable->storeAsURL(sTmpName, aSequence);
2875 return LoadAndRegisterDataSource_Impl( DBConnURIType::UNKNOWN,
nullptr,
INetURLObject(rURI), pDestDir,
nullptr );
2882 void switchEmbeddedDatabaseStorage(
const uno::Reference<sdb::XDatabaseContext>& rDatabaseContext,
const OUString& rName)
2884 uno::Reference<sdb::XDocumentDataSource> xDS(rDatabaseContext->getByName(rName), uno::UNO_QUERY);
2887 uno::Reference<document::XStorageBasedDocument> xStorageDoc(xDS->getDatabaseDocument(), uno::UNO_QUERY);
2897 if (xDatabaseContext->hasByName(rName))
2899 switchEmbeddedDatabaseStorage(xDatabaseContext, rName);
2900 xDatabaseContext->revokeObject(rName);
2911 if (sDataSource.isEmpty())
2912 sDataSource =
"EmbeddedDatabase";
2918 OUString
const aURL = ConstructVndSunStarPkgUrl(
2922 uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(
aURL), uno::UNO_QUERY);
2923 xDatabaseContext->registerObject( sDataSource, xDataSource );
2931 const uno::Sequence<beans::PropertyValue>& rProperties)
2936 OUString sDataSource, sDataTableOrQuery;
2937 uno::Sequence<uno::Any> aSelection;
2939 sal_Int32 nCmdType = sdb::CommandType::TABLE;
2940 uno::Reference< sdbc::XConnection> xConnection;
2952 if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty())
2954 OSL_FAIL(
"PropertyValues missing or unset");
2960 if(!xConnection.is())
2975 uno::Reference<sdbc::XResultSet> xResSet =
m_pImpl->pMergeDialog->GetResultSet();
2993 if(
m_pImpl->pMergeDialog->IsGenerateFromDataBase())
2996 if(
m_pImpl->pMergeDialog->IsFileEncryptedFromDataBase())
3000 Merge( aMergeDesc );
3012 if (pParam.get() == pFound)
3016 uno::Reference<lang::XComponent> xComp(pParam->xConnection, uno::UNO_QUERY);
3020 catch(
const uno::RuntimeException&)
3030 m_pImpl->pMergeDialog.disposeAndClear();
3034 const uno::Sequence< beans::PropertyValue>& rProperties)
3036 OUString sDataSource, sDataTableOrQuery;
3037 uno::Reference<sdbc::XResultSet> xResSet;
3038 uno::Sequence<uno::Any> aSelection;
3039 sal_Int16 nCmdType = sdb::CommandType::TABLE;
3040 uno::Reference< sdbc::XConnection> xConnection;
3041 for(
const beans::PropertyValue& rValue : rProperties)
3043 if ( rValue.Name ==
"DataSourceName" )
3044 rValue.Value >>= sDataSource;
3045 else if ( rValue.Name ==
"Command" )
3046 rValue.Value >>= sDataTableOrQuery;
3047 else if ( rValue.Name ==
"Cursor" )
3048 rValue.Value >>= xResSet;
3049 else if ( rValue.Name ==
"Selection" )
3050 rValue.Value >>= aSelection;
3051 else if ( rValue.Name ==
"CommandType" )
3052 rValue.Value >>= nCmdType;
3053 else if ( rValue.Name ==
"ActiveConnection" )
3054 rValue.Value >>= xConnection;
3056 if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty() || !xResSet.is())
3058 OSL_FAIL(
"PropertyValues missing or unset");
3061 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
3062 uno::Reference<sdbc::XDataSource> xSource;
3063 uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
3065 xSource.set(xChild->getParent(), uno::UNO_QUERY);
3068 uno::Reference< sdbcx::XColumnsSupplier > xColSupp( xResSet, uno::UNO_QUERY );
3071 aDBData.
sCommand = sDataTableOrQuery;
3079 if(
RET_OK != pDlg->Execute() )
3083 if(!xConnection.is())
3084 xConnection = xSource->getConnection(sDummy, sDummy);
3087 pDlg->DataToDoc( aSelection , xSource, xConnection, xResSet);
3089 catch (
const uno::Exception&)
3097 uno::Reference<sdbc::XDataSource> xSource;
3100 uno::Reference<container::XChild> xChild(_xConnection, uno::UNO_QUERY);
3102 xSource.set(xChild->getParent(), uno::UNO_QUERY);
3103 if ( !xSource.is() )
3106 catch (
const uno::Exception&)
3114 const OUString& _sCommand,
3115 sal_Int32 _nCommandType,
3116 const uno::Reference<sdbc::XConnection>& _xConnection,
3119 uno::Reference<sdbc::XResultSet> xResultSet;
3122 uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
3125 uno::Reference<uno::XInterface> xInstance = xMgr->createInstance(
"com.sun.star.sdb.RowSet");
3126 uno::Reference<beans::XPropertySet> xRowSetPropSet(xInstance, uno::UNO_QUERY);
3127 if(xRowSetPropSet.is())
3129 xRowSetPropSet->setPropertyValue(
"DataSourceName",
uno::Any(_sDataSourceName));
3130 xRowSetPropSet->setPropertyValue(
"ActiveConnection",
uno::Any(_xConnection));
3131 xRowSetPropSet->setPropertyValue(
"Command",
uno::Any(_sCommand));
3132 xRowSetPropSet->setPropertyValue(
"CommandType",
uno::Any(_nCommandType));
3134 uno::Reference< sdb::XCompletedExecution > xRowSet(xInstance, uno::UNO_QUERY);
3139 uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(
comphelper::getComponentContext(xMgr), pWindow ? pWindow->
GetXWindow() :
nullptr), uno::UNO_QUERY_THROW );
3140 xRowSet->executeWithCompletion(xHandler);
3142 xResultSet.set(xRowSet, uno::UNO_QUERY);
3146 catch (
const uno::Exception&)
3155 bool bLoad =
m_sEmbeddedName != rEmbeddedName && !rEmbeddedName.isEmpty();
3156 bool bRegisterListener =
m_sEmbeddedName.isEmpty() && !rEmbeddedName.isEmpty();
3162 uno::Reference<embed::XStorage> xStorage = rDocShell.
GetStorage();
3165 if (xStorage->hasByName(rEmbeddedName))
3169 if (bRegisterListener)
3171 m_pImpl->m_xDataSourceRemovedListener =
new SwDataSourceRemovedListener(*
this);
3186 if (
m_pImpl->m_xDataSourceRemovedListener.is())
3188 m_pImpl->m_xDataSourceRemovedListener->Dispose();
3189 m_pImpl->m_xDataSourceRemovedListener.clear();
3194 : m_pDBManager(&rManager)
3202 if (!m_pDBManager)
return;
3204 uno::Reference<sdbc::XConnection> xSource(rSource.Source, uno::UNO_QUERY);
3205 for (
size_t nPos = m_pDBManager->m_DataSourceParams.size();
nPos;
nPos--)
3207 SwDSParam* pParam = m_pDBManager->m_DataSourceParams[
nPos - 1].get();
3211 m_pDBManager->m_DataSourceParams.erase(
3212 m_pDBManager->m_DataSourceParams.begin() +
nPos - 1);
3224 aDescriptor.
setDataSource(xConfigItem->GetCurrentDBData().sDataSource);
3232 xConfigItem->SetTargetView(
nullptr);
3253 xConfigItem->DisposeResultSet();
3254 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
void append(const OUString &rId, const OUString &rStr)
virtual OUString get_active_text() const=0
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)