diff options
author | Eike Rathke <erack@apache.org> | 2011-09-09 17:51:55 +0000 |
---|---|---|
committer | Eike Rathke <erack@apache.org> | 2011-09-09 17:51:55 +0000 |
commit | a64aab01698ed00dc503b8f78703f5e294b4a8ed (patch) | |
tree | 8a39c5f4cc6f5c29d6d79f04b793625252cbabd8 /sc | |
parent | 48eb74b2dbf62e95f32fd0cdcaa2c3e884282f47 (diff) |
calc67: #i117735# use calc FormatDetector for XLS again, handle Excel 2003 XML directly in XLS detection
# User Niklas Nebel <nn@openoffice.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/unoobj/scdetect.cxx | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx index 1407c12e2618..77792e2b7b5b 100644 --- a/sc/source/ui/unoobj/scdetect.cxx +++ b/sc/source/ui/unoobj/scdetect.cxx @@ -117,6 +117,7 @@ static const sal_Char __FAR_DATA pFilterExcel95[] = "MS Excel 95"; static const sal_Char __FAR_DATA pFilterEx95Temp[] = "MS Excel 95 Vorlage/Template"; static const sal_Char __FAR_DATA pFilterExcel97[] = "MS Excel 97"; static const sal_Char __FAR_DATA pFilterEx97Temp[] = "MS Excel 97 Vorlage/Template"; +static const sal_Char __FAR_DATA pFilterExcelXML[] = "MS Excel 2003 XML"; static const sal_Char __FAR_DATA pFilterDBase[] = "dBase"; static const sal_Char __FAR_DATA pFilterDif[] = "DIF"; static const sal_Char __FAR_DATA pFilterSylk[] = "SYLK"; @@ -159,6 +160,35 @@ static sal_Bool lcl_MayBeAscii( SvStream& rStream ) return nMask != 0; } +static const SfxFilter* lcl_DetectExcelXML( SvStream& rStream, SfxFilterMatcher& rMatcher ) +{ + const SfxFilter* pFound = NULL; + rStream.Seek(STREAM_SEEK_TO_BEGIN); + + const size_t nBufSize = 4000; + sal_uInt8 aBuffer[ nBufSize ]; + sal_uLong nBytesRead = rStream.Read( aBuffer, nBufSize ); + sal_uLong nXMLStart = 0; + + // Skip UTF-8 BOM if present. + // No need to handle UTF-16 etc (also rejected in XMLFilterDetect). + if ( nBytesRead >= 3 && aBuffer[0] == 0xEF && aBuffer[1] == 0xBB && aBuffer[2] == 0xBF ) + nXMLStart = 3; + + if ( nBytesRead >= nXMLStart + 5 && rtl_compareMemory( aBuffer+nXMLStart, "<?xml", 5 ) == 0 ) + { + // Be consistent with XMLFilterDetect service: Check for presence of "Workbook" in XML file. + + rtl::OString aTryStr( "Workbook" ); + rtl::OString aFileString(reinterpret_cast<const sal_Char*>(aBuffer), nBytesRead); + + if (aFileString.indexOf(aTryStr) >= 0) + pFound = rMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterExcelXML) ); + } + + return pFound; +} + static sal_Bool lcl_MayBeDBase( SvStream& rStream ) { // Look for dbf marker, see connectivity/source/inc/dbase/DTable.hxx @@ -754,7 +784,11 @@ static sal_Bool lcl_IsAnyXMLFilter( const SfxFilter* pFilter ) } else if ( bIsXLS && bMaybeText ) { - pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterAscii) ); + // Detect Excel 2003 XML here only if XLS was preselected. + // The configured detection for Excel 2003 XML is still in XMLFilterDetect. + pFilter = lcl_DetectExcelXML( rStr, aMatcher ); + if (!pFilter) + pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterAscii) ); bFakeXLS = true; } else if ( aHeader.CompareTo( "{\\rtf", 5 ) == COMPARE_EQUAL ) |