summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2011-11-24 22:21:41 +0100
committerEike Rathke <erack@redhat.com>2011-11-25 01:01:15 +0100
commita185c4c15b16a9db61019aa0c94f3e67ca81699d (patch)
treef62051a1370986b6eff60ae95ed08721b9297bf9 /sc
parentf37a539b79f601e047fefee06357b5538c6c81b0 (diff)
calc67: #i117735# use calc FormatDetector for XLS again, handle Excel 2003 XML directly in XLS detection
# Original author: Niklas Nebel <nn@openoffice.org> * found as LGPLv3-only fix at svn rev 1167327 (http://svn.apache.org/viewvc?view=revision&revision=1167327)
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/unoobj/scdetect.cxx38
1 files changed, 37 insertions, 1 deletions
diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx
index 1132a767157d..1fe317cbefdf 100644
--- a/sc/source/ui/unoobj/scdetect.cxx
+++ b/sc/source/ui/unoobj/scdetect.cxx
@@ -117,6 +117,7 @@ static const sal_Char pFilterExcel95[] = "MS Excel 95";
static const sal_Char pFilterEx95Temp[] = "MS Excel 95 Vorlage/Template";
static const sal_Char pFilterExcel97[] = "MS Excel 97";
static const sal_Char pFilterEx97Temp[] = "MS Excel 97 Vorlage/Template";
+static const sal_Char __FAR_DATA pFilterExcelXML[] = "MS Excel 2003 XML";
static const sal_Char pFilter2003XML[] = "MS Excel 2003 XML";
static const sal_Char pFilterDBase[] = "dBase";
static const sal_Char pFilterDif[] = "DIF";
@@ -160,6 +161,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
@@ -734,7 +764,13 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream )
if( aHeader.CompareTo( "<?xml", 5 ) == COMPARE_EQUAL )
pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilter2003XML) );
else
- 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 ( pPreselectedFilter->GetName().EqualsAscii(pFilterDBase) && lcl_MayBeDBase( rStr ) )