From 9f1cc58c20ee365ff2a158ad69c1091e6ad11ac6 Mon Sep 17 00:00:00 2001 From: Muthu Subramanian K Date: Fri, 15 Oct 2010 14:38:54 +0530 Subject: Merging sc-xml-with-xls-ext.diff from patches. These changes allow xml files with .xls extensions to be opened in calc. --- sc/source/ui/unoobj/scdetect.cxx | 77 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx index 71881493eb2f..15f6a39db04a 100644 --- a/sc/source/ui/unoobj/scdetect.cxx +++ b/sc/source/ui/unoobj/scdetect.cxx @@ -116,6 +116,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 pFilter2003XML[] = "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"; @@ -439,7 +440,8 @@ static BOOL lcl_IsAnyXMLFilter( const SfxFilter* pFilter ) bool bIsXLS = false; SvStream* pStream = aMedium.GetInStream(); const SfxFilter* pPreselectedFilter = pFilter; - if ( pPreselectedFilter && pPreselectedFilter->GetName().SearchAscii("Excel") != STRING_NOTFOUND ) + if ( ( pPreselectedFilter && pPreselectedFilter->GetName().SearchAscii("Excel") != STRING_NOTFOUND ) || + ( !aPreselectedFilterName.Len() && pPreselectedFilter->GetFilterName().EqualsAscii( pFilterAscii ) ) ) bIsXLS = true; pFilter = 0; if ( pStream ) @@ -722,52 +724,51 @@ static BOOL lcl_IsAnyXMLFilter( const SfxFilter* pFilter ) // without the preselection other filters (Writer) take precedence // DBase can't be detected reliably, so it also needs preselection bool bMaybeText = lcl_MayBeAscii( rStr ); - if ( pPreselectedFilter->GetFilterName().EqualsAscii(pFilterAscii) && bMaybeText ) + + // get file header + rStr.Seek( 0 ); + const int nTrySize = 80; + ByteString aHeader; + for ( int j = 0; j < nTrySize && !rStr.IsEof(); j++ ) { - // Text filter is accepted if preselected - pFilter = pPreselectedFilter; + sal_Char c; + rStr >> c; + aHeader += c; } - else + aHeader += '\0'; + + if ( HTMLParser::IsHTMLFormat( aHeader.GetBuffer() ) ) { - // get file header - rStr.Seek( 0 ); - const int nTrySize = 80; - ByteString aHeader; - for ( int j = 0; j < nTrySize && !rStr.IsEof(); j++ ) + // test for HTML + if ( pPreselectedFilter->GetName().EqualsAscii(pFilterHtml) ) { - sal_Char c; - rStr >> c; - aHeader += c; + pFilter = pPreselectedFilter; } - aHeader += '\0'; - - if ( HTMLParser::IsHTMLFormat( aHeader.GetBuffer() ) ) + else { - // test for HTML - if ( pPreselectedFilter->GetName().EqualsAscii(pFilterHtml) ) - { - pFilter = pPreselectedFilter; - } - else - { - pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterHtmlWeb) ); - if ( bIsXLS ) - bFakeXLS = true; - } + pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterHtmlWeb) ); + if ( bIsXLS ) + bFakeXLS = true; } - else if ( bIsXLS && bMaybeText ) - { + } + else if ( aHeader.CompareTo( "{\\rtf", 5 ) == COMPARE_EQUAL ) + { + // test for RTF + pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterRtf) ); + } + else if ( bIsXLS && bMaybeText ) + { + aHeader.EraseLeadingChars(); + if( aHeader.CompareTo( "GetName().EqualsAscii(pFilterDBase) && lcl_MayBeDBase( rStr ) ) - pFilter = pPreselectedFilter; + bFakeXLS = true; } + else if ( pPreselectedFilter->GetName().EqualsAscii(pFilterDBase) && lcl_MayBeDBase( rStr ) ) + pFilter = pPreselectedFilter; + else if ( pPreselectedFilter->GetFilterName().EqualsAscii(pFilterAscii) && bMaybeText ) + pFilter = pPreselectedFilter; } } } -- cgit v1.2.3