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