diff options
author | Eike Rathke <erack@redhat.com> | 2012-04-10 23:50:29 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-04-10 23:50:29 +0200 |
commit | 684cf5cca6ea6c8fc2743f1622f624f668db9e84 (patch) | |
tree | d190d957b21ecac67c68ced3c87b005b39c009b2 | |
parent | 5a5f77c3b57fb1c91a178190c1db12606295bf17 (diff) |
resolved fdo#48516 use "max columns exceeded" message if appropriate
In CSV import, instead of SCWARN_IMPORT_RANGE_OVERFLOW use
SCWARN_IMPORT_ROW_OVERFLOW and SCWARN_IMPORT_COLUMN_OVERFLOW that already
existed, additionally introduced SCWARN_IMPORT_CELL_OVERFLOW if single field
data exceeds STRING_MAXLEN.
Row overflow takes precedence over column overflow that takes precedence over
cell overflow.
-rw-r--r-- | sc/inc/scerrors.hxx | 5 | ||||
-rw-r--r-- | sc/source/ui/dbgui/csvgrid.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 16 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 70 | ||||
-rw-r--r-- | sc/source/ui/inc/impex.hxx | 13 | ||||
-rw-r--r-- | sc/source/ui/src/scerrors.src | 4 |
6 files changed, 77 insertions, 36 deletions
diff --git a/sc/inc/scerrors.hxx b/sc/inc/scerrors.hxx index fc6b9cbfbe4d..ea7e590543fc 100644 --- a/sc/inc/scerrors.hxx +++ b/sc/inc/scerrors.hxx @@ -60,9 +60,10 @@ // ERRCODE_CLASS_IMPORT - does not display "Read-Error" in MsgBox #define SCWARN_IMPORT_RANGE_OVERFLOW ( 1 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) -#define SCWARN_IMPORT_ROW_OVERFLOW ( 2 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) -#define SCWARN_IMPORT_COLUMN_OVERFLOW ( 3 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) +#define SCWARN_IMPORT_ROW_OVERFLOW ( 2 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) +#define SCWARN_IMPORT_COLUMN_OVERFLOW ( 3 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) #define SCWARN_IMPORT_SHEET_OVERFLOW ( 4 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) +#define SCWARN_IMPORT_CELL_OVERFLOW ( 5 | ERRCODE_CLASS_IMPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) // ERRCODE_CLASS_EXPORT - does not display "Write-Error" in MsgBox #define SCWARN_EXPORT_NONCONVERTIBLE_CHARS ( 1 | ERRCODE_CLASS_EXPORT | ERRCODE_WARNING_MASK | ERRCODE_AREA_SC ) diff --git a/sc/source/ui/dbgui/csvgrid.cxx b/sc/source/ui/dbgui/csvgrid.cxx index 09d3651e6fde..68c6fd9dca38 100644 --- a/sc/source/ui/dbgui/csvgrid.cxx +++ b/sc/source/ui/dbgui/csvgrid.cxx @@ -750,7 +750,10 @@ void ScCsvGrid::ImplSetTextLineSep( { // scan for next cell text bool bIsQuoted = false; - pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText, cTextSep, pSepChars, bMergeSep, bIsQuoted ); + bool bOverflowCell = false; + pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText, + cTextSep, pSepChars, bMergeSep, bIsQuoted, bOverflowCell ); + /* TODO: signal overflow somewhere in UI */ // update column width sal_Int32 nWidth = Max( CSV_MINCOLWIDTH, aCellText.Len() + sal_Int32( 1 ) ); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 3e931c457d63..57e2ee4196ad 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1170,7 +1170,8 @@ sal_Bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) } FltError eError = eERR_OK; - sal_Bool bOverflow = false; + bool bOverflowRow, bOverflowCol, bOverflowCell; + bOverflowRow = bOverflowCol = bOverflowCell = false; if( ! rMedium.IsStorage() ) { @@ -1186,7 +1187,9 @@ sal_Bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) eError = bRet ? eERR_OK : SCERR_IMPORT_CONNECT; aDocument.StartAllListeners(); aDocument.SetDirty(); - bOverflow = aImpEx.IsOverflow(); + bOverflowRow = aImpEx.IsOverflowRow(); + bOverflowCol = aImpEx.IsOverflowCol(); + bOverflowCell = aImpEx.IsOverflowCell(); } else { @@ -1199,10 +1202,13 @@ sal_Bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) if (!GetError()) SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )); } - else if ( bOverflow ) + else if (!GetError() && (bOverflowRow || bOverflowCol || bOverflowCell)) { - if (!GetError()) - SetError(SCWARN_IMPORT_RANGE_OVERFLOW, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )); + // precedence: row, column, cell + FltError nWarn = (bOverflowRow ? SCWARN_IMPORT_ROW_OVERFLOW : + (bOverflowCol ? SCWARN_IMPORT_COLUMN_OVERFLOW : + SCWARN_IMPORT_CELL_OVERFLOW)); + SetError( nWarn, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )); } bSetColWidths = sal_True; bSetSimpleTextColWidths = sal_True; diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 7f0b829e2d47..a8790bb61013 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -118,7 +118,8 @@ ScImportExport::ScImportExport( ScDocument* p ) nSizeLimit( 0 ), cSep( '\t' ), cStr( '"' ), bFormulas( false ), bIncludeFiltered( true ), bAll( true ), bSingle( true ), bUndo( false ), - bOverflow( false ), mbApi( true ), mExportTextOptions() + bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), + mbApi( true ), mExportTextOptions() { pUndoDoc = NULL; pExtOptions = NULL; @@ -133,7 +134,8 @@ ScImportExport::ScImportExport( ScDocument* p, const ScAddress& rPt ) nSizeLimit( 0 ), cSep( '\t' ), cStr( '"' ), bFormulas( false ), bIncludeFiltered( true ), bAll( false ), bSingle( true ), bUndo( pDocSh != NULL ), - bOverflow( false ), mbApi( true ), mExportTextOptions() + bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), + mbApi( true ), mExportTextOptions() { pUndoDoc = NULL; pExtOptions = NULL; @@ -149,7 +151,8 @@ ScImportExport::ScImportExport( ScDocument* p, const ScRange& r ) nSizeLimit( 0 ), cSep( '\t' ), cStr( '"' ), bFormulas( false ), bIncludeFiltered( true ), bAll( false ), bSingle( false ), bUndo( pDocSh != NULL ), - bOverflow( false ), mbApi( true ), mExportTextOptions() + bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), + mbApi( true ), mExportTextOptions() { pUndoDoc = NULL; pExtOptions = NULL; @@ -166,7 +169,8 @@ ScImportExport::ScImportExport( ScDocument* p, const String& rPos ) nSizeLimit( 0 ), cSep( '\t' ), cStr( '"' ), bFormulas( false ), bIncludeFiltered( true ), bAll( false ), bSingle( true ), bUndo( pDocSh != NULL ), - bOverflow( false ), mbApi( true ), mExportTextOptions() + bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), + mbApi( true ), mExportTextOptions() { pUndoDoc = NULL; pExtOptions = NULL; @@ -849,9 +853,7 @@ bool ScImportExport::Text2Doc( SvStream& rStrm ) while( *p && *p != cSep ) p++; if (!lcl_appendLineData( aCell, q, p)) - { - /* TODO: warning at UI, data truncated */ - } + bOverflowCell = true; // display warning on import if( *p ) p++; } @@ -866,7 +868,12 @@ bool ScImportExport::Text2Doc( SvStream& rStrm ) pDoc->SetString( nCol, nRow, aRange.aStart.Tab(), aCell ); } else // zuviele Spalten/Zeilen - bOverflow = true; // beim Import Warnung ausgeben + { + if (!ValidRow(nRow)) + bOverflowRow = true; // display warning on import + if (!ValidCol(nCol)) + bOverflowCol = true; // display warning on import + } ++nCol; } ++nRow; @@ -1144,7 +1151,8 @@ static bool lcl_PutString( } -String lcl_GetFixed( const rtl::OUString& rLine, sal_Int32 nStart, sal_Int32 nNext, bool& rbIsQuoted ) +String lcl_GetFixed( const rtl::OUString& rLine, sal_Int32 nStart, sal_Int32 nNext, + bool& rbIsQuoted, bool& rbOverflowCell ) { sal_Int32 nLen = rLine.getLength(); if (nNext > nLen) @@ -1161,13 +1169,27 @@ String lcl_GetFixed( const rtl::OUString& rLine, sal_Int32 nStart, sal_Int32 nNe rbIsQuoted = (pStr[nStart] == sal_Unicode('"') && pStr[nSpace-1] == sal_Unicode('"')); if (rbIsQuoted) { - OSL_ENSURE( nSpace - nStart - 3 <= STRING_MAXLEN, "lcl_GetFixed: line doesn't fit into data"); - return rLine.copy(nStart+1, nSpace-nStart-2); + bool bFits = (nSpace - nStart - 3 <= STRING_MAXLEN); + OSL_ENSURE( bFits, "lcl_GetFixed: line doesn't fit into data"); + if (bFits) + return rLine.copy(nStart+1, nSpace-nStart-2); + else + { + rbOverflowCell = true; + return rLine.copy(nStart+1, STRING_MAXLEN); + } } else { - OSL_ENSURE( nSpace - nStart <= STRING_MAXLEN, "lcl_GetFixed: line doesn't fit into data"); - return rLine.copy(nStart, nSpace-nStart); + bool bFits = (nSpace - nStart <= STRING_MAXLEN); + OSL_ENSURE( bFits, "lcl_GetFixed: line doesn't fit into data"); + if (bFits) + return rLine.copy(nStart, nSpace-nStart); + else + { + rbOverflowCell = true; + return rLine.copy(nStart, STRING_MAXLEN); + } } } @@ -1271,13 +1293,13 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) if (nFmt != SC_COL_SKIP) // sonst auch nCol nicht hochzaehlen { if (nCol > MAXCOL) - bOverflow = true; // display warning on import + bOverflowCol = true; // display warning on import else if (!bDetermineRange) { sal_Int32 nStart = pColStart[i]; sal_Int32 nNext = ( i+1 < nInfoCount ) ? pColStart[i+1] : nLineLen; bool bIsQuoted = false; - aCell = lcl_GetFixed( aLine, nStart, nNext, bIsQuoted ); + aCell = lcl_GetFixed( aLine, nStart, nNext, bIsQuoted, bOverflowCell ); if (bIsQuoted && bQuotedAsText) nFmt = SC_COL_TEXT; @@ -1302,7 +1324,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) while (*p && nCol <= MAXCOL+1) { bool bIsQuoted = false; - p = ScImportExport::ScanNextFieldFromString( p, aCell, cStr, pSeps, bMerge, bIsQuoted ); + p = ScImportExport::ScanNextFieldFromString( p, aCell, + cStr, pSeps, bMerge, bIsQuoted, bOverflowCell ); sal_uInt8 nFmt = SC_COL_STANDARD; for ( i=nInfoStart; i<nInfoCount; i++ ) @@ -1317,7 +1340,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) if ( nFmt != SC_COL_SKIP ) { if (nCol > MAXCOL) - bOverflow = true; // display warning on import + bOverflowCol = true; // display warning on import else if (!bDetermineRange) { if (bIsQuoted && bQuotedAsText) @@ -1346,7 +1369,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) ++nRow; if ( nRow > MAXROW ) { - bOverflow = true; // display warning on import + bOverflowRow = true; // display warning on import break; // for } } @@ -1399,7 +1422,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p, - String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted ) + String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted, + bool& rbOverflowCell ) { rbIsQuoted = false; rField.Erase(); @@ -1427,9 +1451,7 @@ const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p if (p > p1) { if (!lcl_appendLineData( rField, p1, p)) - { - /* TODO: warning at UI, data truncated */ - } + rbOverflowCell = true; } if( *p ) p++; @@ -1440,9 +1462,7 @@ const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p while ( *p && !ScGlobal::UnicodeStrChr( pSeps, *p ) ) p++; if (!lcl_appendLineData( rField, p0, p)) - { - /* TODO: warning at UI, data truncated */ - } + rbOverflowCell = true; if( *p ) p++; } diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx index 7db910d1ea34..03aff6878f2f 100644 --- a/sc/source/ui/inc/impex.hxx +++ b/sc/source/ui/inc/impex.hxx @@ -71,7 +71,9 @@ class SC_DLLPUBLIC ScImportExport bool bAll; // keine Selektion bool bSingle; // Einfachselektion bool bUndo; // Mit Undo? - bool bOverflow; // zuviele Zeilen/Spalten + bool bOverflowRow; // too many rows + bool bOverflowCol; // too many columns + bool bOverflowCell; // too much data for a cell bool mbApi; ScExportTextOptions mExportTextOptions; @@ -112,7 +114,8 @@ public: static bool IsFormatSupported( sal_uLong nFormat ); static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p, - String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted ); + String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, + bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell ); static void WriteUnicodeOrByteString( SvStream& rStrm, const String& rString, bool bZero = false ); static void WriteUnicodeOrByteEndl( SvStream& rStrm ); static inline bool IsEndianSwap( const SvStream& rStrm ); @@ -146,7 +149,11 @@ public: bool ExportData( const String& rMimeType, ::com::sun::star::uno::Any & rValue ); - bool IsOverflow() const { return bOverflow; } // nach dem Importieren + // after import + bool IsOverflowRow() const { return bOverflowRow; } + bool IsOverflowCol() const { return bOverflowCol; } + bool IsOverflowCell() const { return bOverflowCell; } + bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; } const String& GetNonConvertibleChars() const { return aNonConvertibleChars; } diff --git a/sc/source/ui/src/scerrors.src b/sc/source/ui/src/scerrors.src index f77dcf006393..ae3ebd129a23 100644 --- a/sc/source/ui/src/scerrors.src +++ b/sc/source/ui/src/scerrors.src @@ -134,6 +134,10 @@ Resource RID_ERRHDLSC { Text [ en-US ] = "Not all sheets have been loaded because the maximum number of sheets was exceeded.\n\nPlease be warned that re-saving this document will permanently delete those sheets that have not been loaded!" ; }; + String SCWARN_IMPORT_CELL_OVERFLOW & ERRCODE_RES_MASK + { + Text [ en-US ] = "The data could not be loaded completely because the maximum number of characters per cell was exceeded." ; + }; String SCWARN_IMPORT_OPEN_FM3 & ERRCODE_RES_MASK { Text [ en-US ] = "Corresponding FM3-File could not be opened." ; |