LibreOffice Module sc (master)  1
docsh8.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <vcl/errinf.hxx>
23 #include <tools/urlobj.hxx>
24 #include <svl/converter.hxx>
27 #include <comphelper/types.hxx>
28 #include <ucbhelper/content.hxx>
29 #include <svx/txenctab.hxx>
31 #include <unotools/charclass.hxx>
32 #include <rtl/character.hxx>
33 #include <rtl/tencinfo.h>
34 #include <sal/log.hxx>
35 #include <osl/diagnose.h>
36 #include <tools/diagnose_ex.h>
37 
38 #include <com/sun/star/sdb/CommandType.hpp>
39 #include <com/sun/star/sdbc/DataType.hpp>
40 #include <com/sun/star/sdbc/SQLException.hpp>
41 #include <com/sun/star/sdbc/XConnection.hpp>
42 #include <com/sun/star/sdbc/XDriverAccess.hpp>
43 #include <com/sun/star/sdbc/DriverManager.hpp>
44 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
45 #include <com/sun/star/sdbc/XRow.hpp>
46 #include <com/sun/star/sdbc/XRowSet.hpp>
47 #include <com/sun/star/sdbc/XRowUpdate.hpp>
48 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
49 #include <com/sun/star/sdbcx/XAppend.hpp>
50 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
51 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
52 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
53 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/ucb/NameClash.hpp>
57 #include <com/sun/star/ucb/TransferInfo.hpp>
58 #include <com/sun/star/ucb/XCommandInfo.hpp>
59 
60 #include <scerrors.hxx>
61 #include <docsh.hxx>
62 #include <progress.hxx>
63 #include <editutil.hxx>
64 #include <cellform.hxx>
65 #include <dbdocutl.hxx>
66 #include <dociter.hxx>
67 #include <globstr.hrc>
68 #include <scresid.hxx>
69 #include <svl/zformat.hxx>
70 #include <svl/intitem.hxx>
71 #include <patattr.hxx>
72 #include <scitems.hxx>
73 #include <docpool.hxx>
74 #include <segmenttree.hxx>
75 #include <docparam.hxx>
76 #include <cellvalue.hxx>
77 
78 #include <unordered_set>
79 #include <vector>
80 
81 using namespace com::sun::star;
82 using ::std::vector;
83 
84 #if HAVE_FEATURE_DBCONNECTIVITY
85 
86 #define SC_SERVICE_ROWSET "com.sun.star.sdb.RowSet"
87 
89 #define SC_DBPROP_ACTIVECONNECTION "ActiveConnection"
90 #define SC_DBPROP_COMMAND "Command"
91 #define SC_DBPROP_COMMANDTYPE "CommandType"
92 #define SC_DBPROP_PROPCHANGE_NOTIFY "PropertyChangeNotificationEnabled"
93 
94 #define SC_DBPROP_NAME "Name"
95 #define SC_DBPROP_TYPE "Type"
96 #define SC_DBPROP_PRECISION "Precision"
97 #define SC_DBPROP_SCALE "Scale"
98 
99 #define SC_DBPROP_EXTENSION "Extension"
100 #define SC_DBPROP_CHARSET "CharSet"
101 
102 namespace
103 {
104  ErrCode lcl_getDBaseConnection(uno::Reference<sdbc::XDriverManager2>& _rDrvMgr, uno::Reference<sdbc::XConnection>& _rConnection, OUString& _rTabName, const OUString& rFullFileName, rtl_TextEncoding eCharSet)
105  {
107  aURL.SetSmartProtocol( INetProtocol::File );
108  aURL.SetSmartURL( rFullFileName );
109  _rTabName = aURL.getBase( INetURLObject::LAST_SEGMENT, true,
111  OUString aExtension = aURL.getExtension();
112  aURL.removeSegment();
113  aURL.removeFinalSlash();
114  OUString aPath = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
115  uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
116 
117  _rDrvMgr.set( sdbc::DriverManager::create( xContext ) );
118 
119  // get connection
120 
121  const OUString aConnUrl{"sdbc:dbase:" + aPath};
122 
123  // sdbc:dbase is based on the css.sdbc.FILEConnectionProperties UNOIDL service, so we can
124  // transport the raw rtl_TextEncoding value instead of having to translate it into an IANA
125  // character set name string (which might not exist for certain eCharSet values, like
126  // RTL_TEXTENCODING_MS_950):
127  uno::Sequence<beans::PropertyValue> aProps( comphelper::InitPropertySequence({
128  { SC_DBPROP_EXTENSION, uno::Any(aExtension) },
129  { SC_DBPROP_CHARSET, uno::Any(eCharSet) }
130  }));
131 
132  _rConnection = _rDrvMgr->getConnectionWithInfo( aConnUrl, aProps );
133  return ERRCODE_NONE;
134  }
135 }
136 
137 #endif // HAVE_FEATURE_DBCONNECTIVITY
138 
139 // MoveFile/KillFile/IsDocument: similar to SfxContentHelper
140 
141 bool ScDocShell::MoveFile( const INetURLObject& rSourceObj, const INetURLObject& rDestObj )
142 {
143  bool bMoveData = true;
144  bool bRet = true, bKillSource = false;
145  if ( rSourceObj.GetProtocol() != rDestObj.GetProtocol() )
146  {
147  bMoveData = false;
148  bKillSource = true;
149  }
150  OUString aName = rDestObj.getName();
151  INetURLObject aDestPathObj = rDestObj;
152  aDestPathObj.removeSegment();
153  aDestPathObj.setFinalSlash();
154 
155  try
156  {
158  uno::Reference< css::ucb::XCommandEnvironment >(),
160  uno::Reference< css::ucb::XCommandInfo > xInfo = aDestPath.getCommands();
161  OUString aTransferName = "transfer";
162  if ( xInfo->hasCommandByName( aTransferName ) )
163  {
164  aDestPath.executeCommand( aTransferName, uno::makeAny(
165  css::ucb::TransferInfo( bMoveData, rSourceObj.GetMainURL(INetURLObject::DecodeMechanism::NONE), aName,
166  css::ucb::NameClash::ERROR ) ) );
167  }
168  else
169  {
170  OSL_FAIL( "transfer command not available" );
171  }
172  }
173  catch( uno::Exception& )
174  {
175  // ucb may throw different exceptions on failure now
176  bRet = false;
177  }
178 
179  if ( bKillSource )
180  KillFile( rSourceObj );
181 
182  return bRet;
183 }
184 
186 {
187  bool bRet = true;
188  try
189  {
191  uno::Reference< css::ucb::XCommandEnvironment >(),
193  aCnt.executeCommand( "delete", css::uno::Any( true ) );
194  }
195  catch( uno::Exception& )
196  {
197  // ucb may throw different exceptions on failure now
198  bRet = false;
199  }
200 
201  return bRet;
202 }
203 
205 {
206  bool bRet = false;
207  try
208  {
210  uno::Reference< css::ucb::XCommandEnvironment >(),
212  bRet = aCnt.isDocument();
213  }
214  catch( uno::Exception& )
215  {
216  // ucb may throw different exceptions on failure now - warning only
217  OSL_FAIL( "Any other exception" );
218  }
219 
220  return bRet;
221 }
222 
223 #if HAVE_FEATURE_DBCONNECTIVITY
224 
225 static void lcl_setScalesToColumns(ScDocument& rDoc, const vector<long>& rScales)
226 {
227  SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
228  if (!pFormatter)
229  return;
230 
231  SCCOL nColCount = static_cast<SCCOL>(rScales.size());
232  for (SCCOL i = 0; i < nColCount; ++i)
233  {
234  if (rScales[i] < 0)
235  continue;
236 
237  sal_uInt32 nOldFormat;
238  rDoc.GetNumberFormat(i, 0, 0, nOldFormat);
239  const SvNumberformat* pOldEntry = pFormatter->GetEntry(nOldFormat);
240  if (!pOldEntry)
241  continue;
242 
243  LanguageType eLang = pOldEntry->GetLanguage();
244  bool bThousand, bNegRed;
245  sal_uInt16 nPrecision, nLeading;
246  pOldEntry->GetFormatSpecialInfo(bThousand, bNegRed, nPrecision, nLeading);
247 
248  nPrecision = static_cast<sal_uInt16>(rScales[i]);
249  OUString aNewPicture = pFormatter->GenerateFormat(nOldFormat, eLang,
250  bThousand, bNegRed, nPrecision, nLeading);
251 
252  sal_uInt32 nNewFormat = pFormatter->GetEntryKey(aNewPicture, eLang);
253  if (nNewFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
254  {
255  sal_Int32 nErrPos = 0;
256  SvNumFormatType nNewType = SvNumFormatType::ALL;
257  bool bOk = pFormatter->PutEntry(
258  aNewPicture, nErrPos, nNewType, nNewFormat, eLang);
259 
260  if (!bOk)
261  continue;
262  }
263 
264  ScPatternAttr aNewAttrs( rDoc.GetPool() );
265  SfxItemSet& rSet = aNewAttrs.GetItemSet();
266  rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) );
267  rDoc.ApplyPatternAreaTab(i, 0, i, rDoc.MaxRow(), 0, aNewAttrs);
268  }
269 }
270 
271 #endif // HAVE_FEATURE_DBCONNECTIVITY
272 
273 ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
274  std::map<SCCOL, ScColWidthParam>& aColWidthParam, ScFlatBoolRowSegments& rRowHeightsRecalc )
275 {
276 #if !HAVE_FEATURE_DBCONNECTIVITY
277  (void) rFullFileName;
278  (void) eCharSet;
279  (void) aColWidthParam;
280  (void) rRowHeightsRecalc;
281 
282  return ERRCODE_IO_GENERAL;
283 #else
284 
285  ErrCode nErr = ERRCODE_NONE;
286 
287  try
288  {
289  tools::Long i;
290  tools::Long nColCount = 0;
291  OUString aTabName;
292  uno::Reference<sdbc::XDriverManager2> xDrvMan;
293  uno::Reference<sdbc::XConnection> xConnection;
294  ErrCode nRet = lcl_getDBaseConnection(xDrvMan,xConnection,aTabName,rFullFileName,eCharSet);
295  if ( !xConnection.is() || !xDrvMan.is() )
296  return nRet;
297  ::utl::DisposableComponent aConnectionHelper(xConnection);
298 
299  ScProgress aProgress( this, ScResId( STR_LOAD_DOC ), 0, true );
300  uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory();
301  uno::Reference<sdbc::XRowSet> xRowSet( xFactory->createInstance(SC_SERVICE_ROWSET),
302  uno::UNO_QUERY);
303  ::utl::DisposableComponent aRowSetHelper(xRowSet);
304  uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY );
305  OSL_ENSURE( xRowProp.is(), "can't get RowSet" );
306  if (!xRowProp.is()) return SCERR_IMPORT_CONNECT;
307 
308  xRowProp->setPropertyValue( SC_DBPROP_ACTIVECONNECTION, uno::Any(xConnection) );
309 
310  xRowProp->setPropertyValue( SC_DBPROP_COMMANDTYPE, uno::Any(sdb::CommandType::TABLE) );
311 
312  xRowProp->setPropertyValue( SC_DBPROP_COMMAND, uno::Any(aTabName) );
313 
314  xRowProp->setPropertyValue( SC_DBPROP_PROPCHANGE_NOTIFY, uno::Any(false) );
315 
316  xRowSet->execute();
317 
318  uno::Reference<sdbc::XResultSetMetaData> xMeta;
319  uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY );
320  if ( xMetaSupp.is() )
321  xMeta = xMetaSupp->getMetaData();
322  if ( xMeta.is() )
323  nColCount = xMeta->getColumnCount(); // this is the number of real columns
324 
325  if ( nColCount > m_aDocument.MaxCol()+1 )
326  {
327  nColCount = m_aDocument.MaxCol()+1;
328  nErr = SCWARN_IMPORT_COLUMN_OVERFLOW; // warning
329  }
330 
331  uno::Reference<sdbc::XRow> xRow( xRowSet, uno::UNO_QUERY );
332  OSL_ENSURE( xRow.is(), "can't get Row" );
333  if (!xRow.is()) return SCERR_IMPORT_CONNECT;
334 
335  // currency flag is not needed for dBase
336  uno::Sequence<sal_Int32> aColTypes( nColCount ); // column types
337  sal_Int32* pTypeArr = aColTypes.getArray();
338  for (i=0; i<nColCount; i++)
339  pTypeArr[i] = xMeta->getColumnType( i+1 );
340 
341  // read column names
343 
344  aProgress.SetState( 0 );
345 
346  vector<long> aScales(nColCount, -1);
347  for (i=0; i<nColCount; i++)
348  {
349  OUString aHeader = xMeta->getColumnLabel( i+1 );
350 
351  switch ( pTypeArr[i] )
352  {
353  case sdbc::DataType::BIT:
354  aHeader += ",L";
355  break;
357  aHeader += ",D";
358  break;
359  case sdbc::DataType::LONGVARCHAR:
360  aHeader += ",M";
361  break;
362  case sdbc::DataType::VARCHAR:
363  aHeader += ",C," + OUString::number( xMeta->getColumnDisplaySize( i+1 ) );
364  break;
365  case sdbc::DataType::DECIMAL:
366  {
367  tools::Long nPrec = xMeta->getPrecision( i+1 );
368  tools::Long nScale = xMeta->getScale( i+1 );
369  aHeader += ",N," +
370  OUString::number(
372  nPrec, nScale ) ) +
373  "," +
374  OUString::number( nScale );
375  aScales[i] = nScale;
376  }
377  break;
378  }
379 
380  m_aDocument.SetString( static_cast<SCCOL>(i), 0, 0, aHeader );
381  }
382 
383  lcl_setScalesToColumns(m_aDocument, aScales);
384 
385  SCROW nRow = 1; // 0 is column titles
386  bool bEnd = false;
387  while ( !bEnd && xRowSet->next() )
388  {
389  if ( nRow <= m_aDocument.MaxRow() )
390  {
391  bool bSimpleRow = true;
392  SCCOL nCol = 0;
393  for (i=0; i<nColCount; i++)
394  {
396  ScDatabaseDocUtil::PutData( m_aDocument, nCol, nRow, 0,
397  xRow, i+1, pTypeArr[i], false,
398  &aStrData );
399 
400  if (aStrData.mnStrLength > aColWidthParam[nCol].mnMaxTextLen)
401  {
402  aColWidthParam[nCol].mnMaxTextLen = aStrData.mnStrLength;
403  aColWidthParam[nCol].mnMaxTextRow = nRow;
404  }
405 
406  if (!aStrData.mbSimpleText)
407  {
408  bSimpleRow = false;
409  aColWidthParam[nCol].mbSimpleText = false;
410  }
411 
412  ++nCol;
413  }
414  if (!bSimpleRow)
415  rRowHeightsRecalc.setTrue(nRow, nRow);
416  ++nRow;
417  }
418  else // past the end of the spreadsheet
419  {
420  bEnd = true; // don't continue
421  nErr = SCWARN_IMPORT_RANGE_OVERFLOW; // warning message
422  }
423  }
424  }
425  catch ( sdbc::SQLException& )
426  {
427  nErr = SCERR_IMPORT_CONNECT;
428  }
429  catch ( uno::Exception& )
430  {
431  OSL_FAIL("Unexpected exception in database");
432  nErr = ERRCODE_IO_GENERAL;
433  }
434 
435  return nErr;
436 #endif // HAVE_FEATURE_DBCONNECTIVITY
437 }
438 
439 #if HAVE_FEATURE_DBCONNECTIVITY
440 
441 namespace {
442 
443 void lcl_GetColumnTypes(
444  ScDocShell& rDocShell, const ScRange& rDataRange, bool bHasFieldNames,
445  OUString* pColNames, sal_Int32* pColTypes, sal_Int32* pColLengths,
446  sal_Int32* pColScales, bool& bHasMemo, rtl_TextEncoding eCharSet )
447 {
448  ScDocument& rDoc = rDocShell.GetDocument();
449  SvNumberFormatter* pNumFmt = rDoc.GetFormatTable();
450 
451  SCTAB nTab = rDataRange.aStart.Tab();
452  SCCOL nFirstCol = rDataRange.aStart.Col();
453  SCROW nFirstRow = rDataRange.aStart.Row();
454  SCCOL nLastCol = rDataRange.aEnd.Col();
455  SCROW nLastRow = rDataRange.aEnd.Row();
456 
457  typedef std::unordered_set<OUString> StrSetType;
458  StrSetType aFieldNames;
459 
460  tools::Long nField = 0;
461  SCROW nFirstDataRow = ( bHasFieldNames ? nFirstRow + 1 : nFirstRow );
462  for ( SCCOL nCol = nFirstCol; nCol <= nLastCol; nCol++ )
463  {
464  bool bTypeDefined = false;
465  bool bPrecDefined = false;
466  sal_Int32 nFieldLen = 0;
467  sal_Int32 nPrecision = 0;
468  sal_Int32 nDbType = sdbc::DataType::SQLNULL;
469  OUString aFieldName;
470 
471  // Fieldname[,Type[,Width[,Prec]]]
472  // Type etc.: L; D; C[,W]; N[,W[,P]]
473  if ( bHasFieldNames )
474  {
475  OUString aString {rDoc.GetString(nCol, nFirstRow, nTab).toAsciiUpperCase()};
476  sal_Int32 nIdx {0};
477  aFieldName = aString.getToken( 0, ',', nIdx);
478  if ( nIdx>0 )
479  {
480  aString = aString.replaceAll(" ", "");
481  switch ( aString.getToken( 0, ',', nIdx )[0] )
482  {
483  case 'L' :
484  nDbType = sdbc::DataType::BIT;
485  nFieldLen = 1;
486  bTypeDefined = true;
487  bPrecDefined = true;
488  break;
489  case 'D' :
490  nDbType = sdbc::DataType::DATE;
491  nFieldLen = 8;
492  bTypeDefined = true;
493  bPrecDefined = true;
494  break;
495  case 'M' :
496  nDbType = sdbc::DataType::LONGVARCHAR;
497  nFieldLen = 10;
498  bTypeDefined = true;
499  bPrecDefined = true;
500  bHasMemo = true;
501  break;
502  case 'C' :
503  nDbType = sdbc::DataType::VARCHAR;
504  bTypeDefined = true;
505  bPrecDefined = true;
506  break;
507  case 'N' :
508  nDbType = sdbc::DataType::DECIMAL;
509  bTypeDefined = true;
510  break;
511  }
512  if ( bTypeDefined && !nFieldLen && nIdx>0 )
513  {
514  nFieldLen = aString.getToken( 0, ',', nIdx ).toInt32();
515  if ( !bPrecDefined && nIdx>0 )
516  {
517  OUString aTmp( aString.getToken( 0, ',', nIdx ) );
518  if ( CharClass::isAsciiNumeric(aTmp) )
519  {
520  nPrecision = aTmp.toInt32();
521  if (nPrecision && nFieldLen < nPrecision+1)
522  nFieldLen = nPrecision + 1; // include decimal separator
523  bPrecDefined = true;
524  }
525  }
526  }
527  }
528 
529  // Check field name and generate valid field name if necessary.
530  // First character has to be alphabetical, subsequent characters
531  // have to be alphanumerical or underscore.
532  // "_DBASELOCK" is reserved (obsolete because first character is
533  // not alphabetical).
534  // No duplicated names.
535  if ( !rtl::isAsciiAlpha(aFieldName[0]) )
536  aFieldName = "N" + aFieldName;
537  OUStringBuffer aTmpStr;
538  sal_Unicode c;
539  for ( const sal_Unicode* p = aFieldName.getStr(); ( c = *p ) != 0; p++ )
540  {
541  if ( rtl::isAsciiAlpha(c) || rtl::isAsciiDigit(c) || c == '_' )
542  aTmpStr.append(c);
543  else
544  aTmpStr.append("_");
545  }
546  aFieldName = aTmpStr.makeStringAndClear();
547  if ( aFieldName.getLength() > 10 )
548  aFieldName = aFieldName.copy(0, 10);
549 
550  if (!aFieldNames.insert(aFieldName).second)
551  { // Duplicated field name, append numeric suffix.
552  sal_uInt16 nSub = 1;
553  OUString aFixPart( aFieldName );
554  do
555  {
556  ++nSub;
557  OUString aVarPart = OUString::number( nSub );
558  if ( aFixPart.getLength() + aVarPart.getLength() > 10 )
559  aFixPart = aFixPart.copy( 0, 10 - aVarPart.getLength() );
560  aFieldName = aFixPart + aVarPart;
561  } while (!aFieldNames.insert(aFieldName).second);
562  }
563  }
564  else
565  {
566  aFieldName = "N" + OUString::number(nCol+1);
567  }
568 
569  if ( !bTypeDefined )
570  { // Field type.
571  ScRefCellValue aCell(rDoc, ScAddress(nCol, nFirstDataRow, nTab));
572  if (aCell.isEmpty() || aCell.hasString())
573  nDbType = sdbc::DataType::VARCHAR;
574  else
575  {
576  sal_uInt32 nFormat;
577  rDoc.GetNumberFormat( nCol, nFirstDataRow, nTab, nFormat );
578  switch ( pNumFmt->GetType( nFormat ) )
579  {
580  case SvNumFormatType::LOGICAL :
581  nDbType = sdbc::DataType::BIT;
582  nFieldLen = 1;
583  break;
584  case SvNumFormatType::DATE :
585  nDbType = sdbc::DataType::DATE;
586  nFieldLen = 8;
587  break;
588  case SvNumFormatType::TIME :
589  case SvNumFormatType::DATETIME :
590  nDbType = sdbc::DataType::VARCHAR;
591  break;
592  default:
593  nDbType = sdbc::DataType::DECIMAL;
594  }
595  }
596  }
597  // Field length.
598  if ( nDbType == sdbc::DataType::VARCHAR && !nFieldLen )
599  { // Determine maximum field width.
600  nFieldLen = rDoc.GetMaxStringLen( nTab, nCol, nFirstDataRow,
601  nLastRow, eCharSet );
602  if ( nFieldLen == 0 )
603  nFieldLen = 1;
604  }
605  else if ( nDbType == sdbc::DataType::DECIMAL )
606  { // Determine maximum field width and precision.
607  sal_Int32 nLen;
608  sal_uInt16 nPrec;
609  nLen = rDoc.GetMaxNumberStringLen( nPrec, nTab, nCol,
610  nFirstDataRow, nLastRow );
611  // dBaseIII precision limit: 15
612  if ( nPrecision > 15 )
613  nPrecision = 15;
614  if ( nPrec > 15 )
615  nPrec = 15;
616  if ( bPrecDefined && nPrecision != nPrec )
617  {
618  if (nPrecision < nPrec)
619  {
620  // This is a hairy case. User defined nPrecision but a
621  // number format has more precision. Modifying a dBase
622  // field may as well render the resulting file useless for
623  // an application that relies on its defined structure,
624  // especially if we are resaving an already existing file.
625  // So who's right, the user who (or the loaded file that)
626  // defined the field, or the user who applied the format?
627  // Commit f59e350d1733125055f1144f8b3b1b0a46f6d1ca gave the
628  // format a higher priority, which is debatable.
629  SAL_WARN( "sc", "lcl_GetColumnTypes: conflicting dBase field precision for "
630  << aFieldName << " (" << nPrecision << "<" << nPrec << ")");
631 
632  // Adjust length to larger predefined integer part. There
633  // may be a reason that the field was prepared for larger
634  // numbers.
635  if (nFieldLen - nPrecision > nLen - nPrec)
636  nLen = nFieldLen - (nPrecision ? nPrecision+1 : 0) + 1 + nPrec;
637  // And override precision.
638  nPrecision = nPrec;
639  }
640  else
641  {
642 #if 1
643  // Adjust length to predefined precision.
644  nLen = nLen + ( nPrecision - nPrec );
645 #else
646  /* If the above override for (nPrecision < nPrec) was not in place then
647  * nPrecision could be 0 and this would be the code path to correctly
648  * calculate nLen. But as is, nPrecision is never 0 here, see CID#982304 */
649 
650  // Adjust length to predefined precision.
651  if ( nPrecision )
652  nLen = nLen + ( nPrecision - nPrec );
653  else
654  nLen -= nPrec+1; // also remove the decimal separator
655 #endif
656  }
657  }
658  if (nFieldLen < nLen)
659  {
660  if (!bTypeDefined)
661  nFieldLen = nLen;
662  else
663  {
664  // Again a hairy case and conflict. Furthermore, the
665  // larger overall length may be a result of only a higher
666  // precision obtained from formats.
667  SAL_WARN( "sc", "lcl_GetColumnTypes: conflicting dBase field length for "
668  << aFieldName << " (" << nFieldLen << "<" << nLen << ")");
669  nFieldLen = nLen;
670  }
671  }
672  if ( !bPrecDefined )
673  nPrecision = nPrec;
674  if ( nFieldLen == 0 )
675  nFieldLen = 1;
676  else if ( nFieldLen > 19 )
677  nFieldLen = 19; // dBaseIII numeric field length limit: 19
678  if ( nPrecision && nFieldLen < nPrecision + 2 )
679  nFieldLen = nPrecision + 2; // 0. must fit into
680  // 538 MUST: Sdb internal representation adds 2 to the field length!
681  // To give the user what he wants we must subtract it here.
684  nFieldLen = SvDbaseConverter::ConvertPrecisionToOdbc( nFieldLen, nPrecision );
685  }
686  if ( nFieldLen > 254 )
687  {
688  if ( nDbType == sdbc::DataType::VARCHAR )
689  { // Too long for a normal text field => memo field.
690  nDbType = sdbc::DataType::LONGVARCHAR;
691  nFieldLen = 10;
692  bHasMemo = true;
693  }
694  else
695  nFieldLen = 254; // bad luck...
696  }
697 
698  pColNames[nField] = aFieldName;
699  pColTypes[nField] = nDbType;
700  pColLengths[nField] = nFieldLen;
701  pColScales[nField] = nPrecision;
702 
703  ++nField;
704  }
705 }
706 
707 void lcl_getLongVarCharEditString( OUString& rString,
708  const ScRefCellValue& rCell, ScFieldEditEngine& rEditEngine )
709 {
710  if (!rCell.mpEditText)
711  return;
712 
713  rEditEngine.SetTextCurrentDefaults(*rCell.mpEditText);
714  rString = rEditEngine.GetText( LINEEND_CRLF );
715 }
716 
717 void lcl_getLongVarCharString(
718  OUString& rString, ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, SvNumberFormatter& rNumFmt )
719 {
720  const Color* pColor;
721  ScAddress aPos(nCol, nRow, nTab);
722  sal_uInt32 nFormat = rDoc.GetNumberFormat(aPos);
723  rString = ScCellFormat::GetString(rDoc, aPos, nFormat, &pColor, rNumFmt);
724 }
725 
726 }
727 
728 #endif // HAVE_FEATURE_DBCONNECTIVITY
729 
730 ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding eCharSet, bool& bHasMemo )
731 {
732 #if !HAVE_FEATURE_DBCONNECTIVITY
733  (void) rFullFileName;
734  (void) eCharSet;
735  (void) bHasMemo;
736 
737  return ERRCODE_IO_GENERAL;
738 #else
739  // remove the file so the dBase driver doesn't find an invalid file
740  INetURLObject aDeleteObj( rFullFileName, INetProtocol::File );
741  KillFile( aDeleteObj );
742 
743  ErrCode nErr = ERRCODE_NONE;
744 
745  SCCOL nFirstCol, nLastCol;
746  SCROW nFirstRow, nLastRow;
747  SCTAB nTab = GetSaveTab();
748  m_aDocument.GetDataStart( nTab, nFirstCol, nFirstRow );
749  m_aDocument.GetCellArea( nTab, nLastCol, nLastRow );
750  if ( nFirstCol > nLastCol )
751  nFirstCol = nLastCol;
752  if ( nFirstRow > nLastRow )
753  nFirstRow = nLastRow;
754  ScProgress aProgress( this, ScResId( STR_SAVE_DOC ),
755  nLastRow - nFirstRow, true );
756  SvNumberFormatter* pNumFmt = m_aDocument.GetFormatTable();
757 
758  bool bHasFieldNames = true;
759  for ( SCCOL nDocCol = nFirstCol; nDocCol <= nLastCol && bHasFieldNames; nDocCol++ )
760  { // only Strings in first row => are field names
761  if ( !m_aDocument.HasStringData( nDocCol, nFirstRow, nTab ) )
762  bHasFieldNames = false;
763  }
764 
765  tools::Long nColCount = nLastCol - nFirstCol + 1;
766  uno::Sequence<OUString> aColNames( nColCount );
767  uno::Sequence<sal_Int32> aColTypes( nColCount );
768  uno::Sequence<sal_Int32> aColLengths( nColCount );
769  uno::Sequence<sal_Int32> aColScales( nColCount );
770 
771  ScRange aDataRange( nFirstCol, nFirstRow, nTab, nLastCol, nLastRow, nTab );
772  lcl_GetColumnTypes( *this, aDataRange, bHasFieldNames,
773  aColNames.getArray(), aColTypes.getArray(),
774  aColLengths.getArray(), aColScales.getArray(),
775  bHasMemo, eCharSet );
776  // also needed for exception catch
777  SCROW nDocRow = 0;
778  ScFieldEditEngine aEditEngine(&m_aDocument, m_aDocument.GetEditPool());
779  OUString aString;
780 
781  try
782  {
783  uno::Reference<sdbc::XDriverManager2> xDrvMan;
784  uno::Reference<sdbc::XConnection> xConnection;
785  OUString aTabName;
786  ErrCode nRet = lcl_getDBaseConnection(xDrvMan,xConnection,aTabName,rFullFileName,eCharSet);
787  if ( !xConnection.is() || !xDrvMan.is() )
788  return nRet;
789  ::utl::DisposableComponent aConnectionHelper(xConnection);
790 
791  // get dBase driver
792  uno::Reference< sdbcx::XDataDefinitionSupplier > xDDSup( xDrvMan->getDriverByURL( xConnection->getMetaData()->getURL() ), uno::UNO_QUERY );
793  if ( !xDDSup.is() )
794  return SCERR_EXPORT_CONNECT;
795 
796  // create table
797  uno::Reference<sdbcx::XTablesSupplier> xTablesSupp =xDDSup->getDataDefinitionByConnection( xConnection );
798  OSL_ENSURE( xTablesSupp.is(), "can't get Data Definition" );
799  if (!xTablesSupp.is()) return SCERR_EXPORT_CONNECT;
800 
801  uno::Reference<container::XNameAccess> xTables = xTablesSupp->getTables();
802  OSL_ENSURE( xTables.is(), "can't get Tables" );
803  if (!xTables.is()) return SCERR_EXPORT_CONNECT;
804 
805  uno::Reference<sdbcx::XDataDescriptorFactory> xTablesFact( xTables, uno::UNO_QUERY );
806  OSL_ENSURE( xTablesFact.is(), "can't get tables factory" );
807  if (!xTablesFact.is()) return SCERR_EXPORT_CONNECT;
808 
809  uno::Reference<sdbcx::XAppend> xTablesAppend( xTables, uno::UNO_QUERY );
810  OSL_ENSURE( xTablesAppend.is(), "can't get tables XAppend" );
811  if (!xTablesAppend.is()) return SCERR_EXPORT_CONNECT;
812 
813  uno::Reference<beans::XPropertySet> xTableDesc = xTablesFact->createDataDescriptor();
814  OSL_ENSURE( xTableDesc.is(), "can't get table descriptor" );
815  if (!xTableDesc.is()) return SCERR_EXPORT_CONNECT;
816 
817  xTableDesc->setPropertyValue( SC_DBPROP_NAME, uno::Any(aTabName) );
818 
819  // create columns
820 
821  uno::Reference<sdbcx::XColumnsSupplier> xColumnsSupp( xTableDesc, uno::UNO_QUERY );
822  OSL_ENSURE( xColumnsSupp.is(), "can't get columns supplier" );
823  if (!xColumnsSupp.is()) return SCERR_EXPORT_CONNECT;
824 
825  uno::Reference<container::XNameAccess> xColumns = xColumnsSupp->getColumns();
826  OSL_ENSURE( xColumns.is(), "can't get columns" );
827  if (!xColumns.is()) return SCERR_EXPORT_CONNECT;
828 
829  uno::Reference<sdbcx::XDataDescriptorFactory> xColumnsFact( xColumns, uno::UNO_QUERY );
830  OSL_ENSURE( xColumnsFact.is(), "can't get columns factory" );
831  if (!xColumnsFact.is()) return SCERR_EXPORT_CONNECT;
832 
833  uno::Reference<sdbcx::XAppend> xColumnsAppend( xColumns, uno::UNO_QUERY );
834  OSL_ENSURE( xColumnsAppend.is(), "can't get columns XAppend" );
835  if (!xColumnsAppend.is()) return SCERR_EXPORT_CONNECT;
836 
837  const OUString* pColNames = aColNames.getConstArray();
838  const sal_Int32* pColTypes = aColTypes.getConstArray();
839  const sal_Int32* pColLengths = aColLengths.getConstArray();
840  const sal_Int32* pColScales = aColScales.getConstArray();
841  tools::Long nCol;
842 
843  for (nCol=0; nCol<nColCount; nCol++)
844  {
845  uno::Reference<beans::XPropertySet> xColumnDesc = xColumnsFact->createDataDescriptor();
846  OSL_ENSURE( xColumnDesc.is(), "can't get column descriptor" );
847  if (!xColumnDesc.is()) return SCERR_EXPORT_CONNECT;
848 
849  xColumnDesc->setPropertyValue( SC_DBPROP_NAME, uno::Any(pColNames[nCol]) );
850 
851  xColumnDesc->setPropertyValue( SC_DBPROP_TYPE, uno::Any(pColTypes[nCol]) );
852 
853  xColumnDesc->setPropertyValue( SC_DBPROP_PRECISION, uno::Any(pColLengths[nCol]) );
854 
855  xColumnDesc->setPropertyValue( SC_DBPROP_SCALE, uno::Any(pColScales[nCol]) );
856 
857  xColumnsAppend->appendByDescriptor( xColumnDesc );
858  }
859 
860  xTablesAppend->appendByDescriptor( xTableDesc );
861 
862  // get row set for writing
863  uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory();
864  uno::Reference<sdbc::XRowSet> xRowSet( xFactory->createInstance(SC_SERVICE_ROWSET),
865  uno::UNO_QUERY);
866  ::utl::DisposableComponent aRowSetHelper(xRowSet);
867  uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY );
868  OSL_ENSURE( xRowProp.is(), "can't get RowSet" );
869  if (!xRowProp.is()) return SCERR_EXPORT_CONNECT;
870 
871  xRowProp->setPropertyValue( SC_DBPROP_ACTIVECONNECTION, uno::Any(xConnection) );
872 
873  xRowProp->setPropertyValue( SC_DBPROP_COMMANDTYPE, uno::Any(sal_Int32(sdb::CommandType::TABLE)) );
874 
875  xRowProp->setPropertyValue( SC_DBPROP_COMMAND, uno::Any(aTabName) );
876 
877  xRowSet->execute();
878 
879  // write data rows
880 
881  uno::Reference<sdbc::XResultSetUpdate> xResultUpdate( xRowSet, uno::UNO_QUERY );
882  OSL_ENSURE( xResultUpdate.is(), "can't get XResultSetUpdate" );
883  if (!xResultUpdate.is()) return SCERR_EXPORT_CONNECT;
884 
885  uno::Reference<sdbc::XRowUpdate> xRowUpdate( xRowSet, uno::UNO_QUERY );
886  OSL_ENSURE( xRowUpdate.is(), "can't get XRowUpdate" );
887  if (!xRowUpdate.is()) return SCERR_EXPORT_CONNECT;
888 
889  SCROW nFirstDataRow = ( bHasFieldNames ? nFirstRow + 1 : nFirstRow );
890  double fVal;
891 
892  for ( nDocRow = nFirstDataRow; nDocRow <= nLastRow; nDocRow++ )
893  {
894  xResultUpdate->moveToInsertRow();
895 
896  for (nCol=0; nCol<nColCount; nCol++)
897  {
898  SCCOL nDocCol = sal::static_int_cast<SCCOL>( nFirstCol + nCol );
899 
900  switch (pColTypes[nCol])
901  {
902  case sdbc::DataType::LONGVARCHAR:
903  {
904  ScRefCellValue aCell(m_aDocument, ScAddress(nDocCol, nDocRow, nTab));
905  if (!aCell.isEmpty())
906  {
907  if (aCell.meType == CELLTYPE_EDIT)
908  { // preserve paragraphs
909  lcl_getLongVarCharEditString(aString, aCell, aEditEngine);
910  }
911  else
912  {
913  lcl_getLongVarCharString(
914  aString, m_aDocument, nDocCol, nDocRow, nTab, *pNumFmt);
915  }
916  xRowUpdate->updateString( nCol+1, aString );
917  }
918  else
919  xRowUpdate->updateNull( nCol+1 );
920  }
921  break;
922 
923  case sdbc::DataType::VARCHAR:
924  aString = m_aDocument.GetString(nDocCol, nDocRow, nTab);
925  xRowUpdate->updateString( nCol+1, aString );
926  if ( nErr == ERRCODE_NONE && pColLengths[nCol] < aString.getLength() )
927  nErr = SCWARN_EXPORT_DATALOST;
928  break;
929 
931  {
932  m_aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
933  // differentiate between 0 with value and 0 no-value
934  bool bIsNull = (fVal == 0.0);
935  if ( bIsNull )
936  bIsNull = !m_aDocument.HasValueData( nDocCol, nDocRow, nTab );
937  if ( bIsNull )
938  {
939  xRowUpdate->updateNull( nCol+1 );
940  if ( nErr == ERRCODE_NONE &&
941  m_aDocument.HasStringData( nDocCol, nDocRow, nTab ) )
942  nErr = SCWARN_EXPORT_DATALOST;
943  }
944  else
945  {
946  Date aDate = pNumFmt->GetNullDate(); // tools date
947  aDate.AddDays(fVal);
948  xRowUpdate->updateDate( nCol+1, aDate.GetUNODate() );
949  }
950  }
951  break;
952 
953  case sdbc::DataType::DECIMAL:
954  case sdbc::DataType::BIT:
955  m_aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
956  if ( fVal == 0.0 && nErr == ERRCODE_NONE &&
957  m_aDocument.HasStringData( nDocCol, nDocRow, nTab ) )
958  nErr = SCWARN_EXPORT_DATALOST;
959  if ( pColTypes[nCol] == sdbc::DataType::BIT )
960  xRowUpdate->updateBoolean( nCol+1, ( fVal != 0.0 ) );
961  else
962  xRowUpdate->updateDouble( nCol+1, fVal );
963  break;
964 
965  default:
966  OSL_FAIL( "ScDocShell::DBaseExport: unknown FieldType" );
967  if ( nErr == ERRCODE_NONE )
968  nErr = SCWARN_EXPORT_DATALOST;
969  m_aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
970  xRowUpdate->updateDouble( nCol+1, fVal );
971  }
972  }
973 
974  xResultUpdate->insertRow();
975 
978 
979  aProgress.SetStateOnPercent( nDocRow - nFirstRow );
980  }
981 
982  comphelper::disposeComponent( xRowSet );
983  comphelper::disposeComponent( xConnection );
984  }
985  catch ( const sdbc::SQLException& aException )
986  {
987  sal_Int32 nError = aException.ErrorCode;
988  TOOLS_WARN_EXCEPTION("sc", "ScDocShell::DBaseExport");
989 
990  if (nError == 22018 || nError == 22001)
991  {
992  // SQL error 22018: Character not in target encoding.
993  // SQL error 22001: String length exceeds field width (after encoding).
994  bool bEncErr = (nError == 22018);
995  bool bIsOctetTextEncoding = rtl_isOctetTextEncoding( eCharSet);
996  OSL_ENSURE( !bEncErr || bIsOctetTextEncoding, "ScDocShell::DBaseExport: encoding error and not an octet textencoding");
997  SCCOL nDocCol = nFirstCol;
998  const sal_Int32* pColTypes = aColTypes.getConstArray();
999  const sal_Int32* pColLengths = aColLengths.getConstArray();
1000  ScHorizontalCellIterator aIter( m_aDocument, nTab, nFirstCol,
1001  nDocRow, nLastCol, nDocRow);
1002  bool bTest = true;
1003  while (bTest)
1004  {
1005  ScRefCellValue* pCell = aIter.GetNext( nDocCol, nDocRow);
1006  if (!pCell)
1007  break;
1008  SCCOL nCol = nDocCol - nFirstCol;
1009  switch (pColTypes[nCol])
1010  {
1011  case sdbc::DataType::LONGVARCHAR:
1012  {
1013  if (pCell->meType == CELLTYPE_EDIT)
1014  lcl_getLongVarCharEditString(aString, *pCell, aEditEngine);
1015  else
1016  lcl_getLongVarCharString(
1017  aString, m_aDocument, nDocCol, nDocRow, nTab, *pNumFmt);
1018  }
1019  break;
1020 
1021  case sdbc::DataType::VARCHAR:
1022  aString = m_aDocument.GetString(nDocCol, nDocRow, nTab);
1023  break;
1024 
1025  // NOTE: length of DECIMAL fields doesn't need to be
1026  // checked here, the database driver adjusts the field
1027  // width accordingly.
1028 
1029  default:
1030  bTest = false;
1031  }
1032  if (bTest)
1033  {
1034  sal_Int32 nLen;
1035  if (bIsOctetTextEncoding)
1036  {
1037  OString aOString;
1038  if (!aString.convertToString( &aOString, eCharSet,
1039  RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1040  RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))
1041  {
1042  bTest = false;
1043  bEncErr = true;
1044  }
1045  nLen = aOString.getLength();
1046  if (!bTest)
1047  SAL_WARN("sc", "ScDocShell::DBaseExport encoding error, string with default replacements: ``" << aString << "''");
1048  }
1049  else
1050  nLen = aString.getLength() * sizeof(sal_Unicode);
1051  if (!bEncErr &&
1052  pColTypes[nCol] != sdbc::DataType::LONGVARCHAR &&
1053  pColLengths[nCol] < nLen)
1054  {
1055  bTest = false;
1056  SAL_INFO("sc", "ScDocShell::DBaseExport: field width: " << pColLengths[nCol] << ", encoded length: " << nLen);
1057  }
1058  }
1059  else
1060  bTest = true;
1061  }
1062  OUString sPosition(ScAddress(nDocCol, nDocRow, nTab).GetColRowString());
1063  OUString sEncoding(SvxTextEncodingTable::GetTextString(eCharSet));
1064  nErr = *new TwoStringErrorInfo( (bEncErr ? SCERR_EXPORT_ENCODING :
1065  SCERR_EXPORT_FIELDWIDTH), sPosition, sEncoding,
1066  DialogMask::ButtonsOk | DialogMask::MessageError);
1067  }
1068  else if ( !aException.Message.isEmpty() )
1069  nErr = *new StringErrorInfo( SCERR_EXPORT_SQLEXCEPTION, aException.Message, DialogMask::ButtonsOk | DialogMask::MessageError);
1070  else
1071  nErr = SCERR_EXPORT_DATA;
1072  }
1073  catch ( uno::Exception& )
1074  {
1075  OSL_FAIL("Unexpected exception in database");
1076  nErr = ERRCODE_IO_GENERAL;
1077  }
1078 
1079  return nErr;
1080 #endif // HAVE_FEATURE_DBCONNECTIVITY
1081 }
1082 
1083 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE ErrCode DBaseImport(const OUString &rFullFileName, rtl_TextEncoding eCharSet, std::map< SCCOL, ScColWidthParam > &aColWidthParam, ScFlatBoolRowSegments &rRowHeightsRecalc)
Definition: docsh8.cxx:273
const int nColCount
OUString GetText(LineEnd eEnd=LINEEND_LF) const
URL aURL
ScAddress aStart
Definition: address.hxx:500
#define SCERR_EXPORT_SQLEXCEPTION
Definition: scerrors.hxx:57
ScRefCellValue * GetNext(SCCOL &rCol, SCROW &rRow)
Definition: dociter.cxx:2127
SCROW Row() const
Definition: address.hxx:262
const Color aColNames[SC_RANGECOLORS]
Definition: rfindlst.cxx:25
bool isEmpty() const
Definition: cellvalue.cxx:670
OUString getBase(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
long Long
void SetStateOnPercent(sal_uLong nVal)
Definition: progress.hxx:97
SvNumFormatType GetType(sal_uInt32 nFIndex) const
#define SCWARN_IMPORT_RANGE_OVERFLOW
Definition: scerrors.hxx:62
SC_DLLPUBLIC void GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32 &rFormat) const
Definition: document.cxx:3641
ScAddress aEnd
Definition: address.hxx:501
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
static void PutData(ScDocument &rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const css::uno::Reference< css::sdbc::XRow > &xRow, tools::Long nRowPos, tools::Long nType, bool bCurrency, StrData *pStrData=nullptr)
Definition: dbdocutl.cxx:37
#define SC_DBPROP_COMMANDTYPE
Definition: dpobject.cxx:101
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6061
css::util::Date GetUNODate() const
sal_uInt16 sal_Unicode
bool setFinalSlash()
const EditTextObject * mpEditText
Definition: cellvalue.hxx:110
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
bool setTrue(SCROW nRow1, SCROW nRow2)
SC_DLLPUBLIC OUString GetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScInterpreterContext *pContext=nullptr) const
Definition: document.cxx:3486
static SVL_DLLPUBLIC sal_Int32 ConvertPrecisionToOdbc(sal_Int32 _nLen, sal_Int32 _nScale)
SCTAB Tab() const
Definition: address.hxx:271
uno::Reference< sdbc::XRow > xRow
#define SCERR_EXPORT_FIELDWIDTH
Definition: scerrors.hxx:56
#define SC_DBPROP_COMMAND
Definition: dpobject.cxx:100
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool PutEntry(OUString &rString, sal_Int32 &nCheckPos, SvNumFormatType &nType, sal_uInt32 &nKey, LanguageType eLnge=LANGUAGE_DONTKNOW)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:438
#define TOOLS_WARN_EXCEPTION(area, stream)
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:559
#define ERRCODE_IO_GENERAL
static SAL_DLLPRIVATE bool MoveFile(const INetURLObject &rSource, const INetURLObject &rDest)
Definition: docsh8.cxx:141
int i
void SetSmartProtocol(INetProtocol eTheSmartScheme)
static SAL_DLLPRIVATE bool KillFile(const INetURLObject &rURL)
Definition: docsh8.cxx:185
sal_Int16 SCCOL
Definition: types.hxx:22
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static SVL_DLLPUBLIC sal_Int32 ConvertPrecisionToDbase(sal_Int32 _nLen, sal_Int32 _nScale)
#define SCERR_EXPORT_DATA
Definition: scerrors.hxx:54
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
SC_DLLPUBLIC void ApplyPatternAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScPatternAttr &rAttr)
Definition: document.cxx:4786
SvNumFormatType
void AddDays(sal_Int32 nAddDays)
sal_Int32 GetMaxNumberStringLen(sal_uInt16 &nPrecision, SCTAB nTab, SCCOL nCol, SCROW nRowStart, SCROW nRowEnd) const
Maximum string length of numerical cells of a column, e.g.
Definition: documen4.cxx:597
bool removeFinalSlash()
SAL_DLLPRIVATE ErrCode DBaseExport(const OUString &rFullFileName, rtl_TextEncoding eCharSet, bool &bHasMemo)
Definition: docsh8.cxx:730
bool KillFile(const INetURLObject &rURL)
sal_Int32 GetMaxStringLen(SCTAB nTab, SCCOL nCol, SCROW nRowStart, SCROW nRowEnd, rtl_TextEncoding eCharSet) const
Maximum string length of a column, e.g.
Definition: documen4.cxx:588
SCCOL Col() const
Definition: address.hxx:267
#define SCERR_EXPORT_CONNECT
Definition: scerrors.hxx:53
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
CellType meType
Definition: cellvalue.hxx:106
OUString GenerateFormat(sal_uInt32 nIndex, LanguageType eLnge=LANGUAGE_DONTKNOW, bool bThousand=false, bool IsRed=false, sal_uInt16 nPrecision=0, sal_uInt16 nLeadingCnt=1)
void SetState(sal_uLong nVal, sal_uLong nNewRange=0)
Definition: progress.hxx:79
sal_Int32 SCROW
Definition: types.hxx:18
Reference< XMultiServiceFactory > getProcessServiceFactory()
Any makeAny(Color const &value)
static SAL_DLLPRIVATE bool IsDocument(const INetURLObject &rURL)
Definition: docsh8.cxx:204
#define ERRCODE_NONE
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
#define SCERR_IMPORT_CONNECT
Definition: scerrors.hxx:26
#define SAL_INFO(area, stream)
OUString aName
INetProtocol GetProtocol() const
void * p
Reference< XComponentContext > getProcessComponentContext()
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
#define SCWARN_IMPORT_COLUMN_OVERFLOW
Definition: scerrors.hxx:64
static bool isAsciiNumeric(const OUString &rStr)
css::uno::Reference< css::ucb::XCommandInfo > getCommands()
sal_uInt32 GetEntryKey(const OUString &sStr, LanguageType eLnge=LANGUAGE_DONTKNOW)
void disposeComponent(css::uno::Reference< TYPE > &_rxComp)
#define SAL_WARN(area, stream)
css::uno::Any executeCommand(const OUString &rCommandName, const css::uno::Any &rCommandArgument)
Reference< XSingleServiceFactory > xFactory
static void GetString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, const Color **ppColor, SvNumberFormatter &rFormatter, const ScDocument &rDoc, bool bNullVals=true, bool bFormula=false, bool bUseStarFormat=false)
Definition: cellform.cxx:33
const char *const aFieldNames[]
const Date & GetNullDate() const
#define SCERR_EXPORT_ENCODING
Definition: scerrors.hxx:55
#define SC_SERVICE_ROWSET
Definition: dpobject.cxx:97
#define SCWARN_EXPORT_DATALOST
Definition: scerrors.hxx:76
LanguageType GetLanguage() const
sal_Int16 SCTAB
Definition: types.hxx:23
bool SetSmartURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void GetFormatSpecialInfo(bool &bThousand, bool &IsRed, sal_uInt16 &nPrecision, sal_uInt16 &nLeadingCnt) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
Detailed information on single string value.
Definition: dbdocutl.hxx:37
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
static OUString GetTextString(const rtl_TextEncoding nEnc)