[Libreoffice-commits] core.git: 2 commits - sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Tue Feb 5 08:06:02 PST 2013
sc/source/ui/unoobj/exceldetect.cxx | 41 +++++++++++++++-
sc/source/ui/unoobj/scdetect.cxx | 92 ------------------------------------
2 files changed, 40 insertions(+), 93 deletions(-)
New commits:
commit f81b1c6e9d1cc6b5d14e61805f0837b961323f15
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Feb 5 11:00:00 2013 -0500
Remove the Excel 4.0/95/97 detection bits from ScFilterDetect.
We still need to leave the MS Excel 4.0 filter name there as it's
used for Excel 1.0/2.0/3.0 file formats. In the future we might move
these to ScExcelBiffDetect as well...
Change-Id: I8422e7470fbb0a14c219b7f67e3dfd4a34131eba
diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx
index 6bacac2..a550698 100644
--- a/sc/source/ui/unoobj/scdetect.cxx
+++ b/sc/source/ui/unoobj/scdetect.cxx
@@ -94,13 +94,6 @@ static const sal_Char pFilterAscii[] = "Text - txt - csv (StarCalc)";
static const sal_Char pFilterLotus[] = "Lotus";
static const sal_Char pFilterQPro6[] = "Quattro Pro 6.0";
static const sal_Char pFilterExcel4[] = "MS Excel 4.0";
-static const sal_Char pFilterEx4Temp[] = "MS Excel 4.0 Vorlage/Template";
-static const sal_Char pFilterExcel5[] = "MS Excel 5.0/95";
-static const sal_Char pFilterEx5Temp[] = "MS Excel 5.0/95 Vorlage/Template";
-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 pFilterExcelXML[] = "MS Excel 2003 XML";
static const sal_Char pFilterDBase[] = "dBase";
static const sal_Char pFilterDif[] = "DIF";
@@ -455,81 +448,7 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream )
// 0-length stream as that would create the compound
// document header on the stream and effectively write to
// disk!
- SotStorageRef aStorage;
if (nSize > 0)
- aStorage = new SotStorage ( pStream, false );
- if ( aStorage.Is() && !aStorage->GetError() )
- {
- // Excel-5: detect through contained streams
- // there are some "excel" formats from 3rd party vendors that need to be distinguished
- String aStreamName(RTL_CONSTASCII_USTRINGPARAM("Workbook"));
- sal_Bool bExcel97Stream = ( aStorage->IsStream( aStreamName ) );
-
- aStreamName = String(RTL_CONSTASCII_USTRINGPARAM("Book"));
- sal_Bool bExcel5Stream = ( aStorage->IsStream( aStreamName ) );
- if ( bExcel97Stream || bExcel5Stream )
- {
- if ( bExcel97Stream )
- {
- String aOldName;
- sal_Bool bIsCalcFilter = sal_True;
- if ( pPreselectedFilter )
- {
- // cross filter; now this should be a type detection only, not a filter detection
- // we can simulate it by preserving the preselected filter if the type matches
- // example: Excel filters for Writer
- aOldName = pPreselectedFilter->GetFilterName();
- bIsCalcFilter = pPreselectedFilter->GetServiceName() == "com.sun.star.sheet.SpreadsheetDocument";
- }
-
- if ( aOldName.EqualsAscii(pFilterEx97Temp) || !bIsCalcFilter )
- {
- // Excel 97 template selected -> keep selection
- }
- else if ( bExcel5Stream &&
- ( aOldName.EqualsAscii(pFilterExcel5) || aOldName.EqualsAscii(pFilterEx5Temp) ||
- aOldName.EqualsAscii(pFilterExcel95) || aOldName.EqualsAscii(pFilterEx95Temp) ) )
- {
- // dual format file and Excel 5 selected -> keep selection
- }
- else
- {
- // else use Excel 97 filter
- pFilter = aMatcher.GetFilter4FilterName( rtl::OUString(pFilterExcel97) );
- }
- }
- else if ( bExcel5Stream )
- {
- String aOldName;
- sal_Bool bIsCalcFilter = sal_True;
- if ( pPreselectedFilter )
- {
- // cross filter; now this should be a type detection only, not a filter detection
- // we can simulate it by preserving the preselected filter if the type matches
- // example: Excel filters for Writer
- aOldName = pPreselectedFilter->GetFilterName();
- bIsCalcFilter = pPreselectedFilter->GetServiceName() == "com.sun.star.sheet.SpreadsheetDocument";
- }
-
- if ( aOldName.EqualsAscii(pFilterExcel95) || aOldName.EqualsAscii(pFilterEx95Temp) ||
- aOldName.EqualsAscii(pFilterEx5Temp) || !bIsCalcFilter )
- {
- // Excel 95 oder Vorlage (5 oder 95) eingestellt -> auch gut
- }
- else if ( aOldName.EqualsAscii(pFilterEx97Temp) )
- {
- // auto detection has found template -> return Excel5 template
- pFilter = aMatcher.GetFilter4FilterName( rtl::OUString(pFilterEx5Temp) );
- }
- else
- {
- // sonst wird als Excel 5-Datei erkannt
- pFilter = aMatcher.GetFilter4FilterName( rtl::OUString(pFilterExcel5) );
- }
- }
- }
- }
- else if (nSize > 0)
{
SvStream &rStr = *pStream;
@@ -710,16 +629,7 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream )
}
else if( nMuster & M_ENDE )
{ // Format detected
- if ( pFilterName[nFilter] == pFilterExcel4 && pPreselectedFilter &&
- ( (pPreselectedFilter)->GetFilterName().EqualsAscii(pFilterEx4Temp) || pPreselectedFilter->GetTypeName().EqualsAscii("calc_MS_Excel_40") ) )
- {
- // Excel 4 erkannt, Excel 4 Vorlage eingestellt -> auch gut
- // oder Excel 4 Filter anderer Applikation (simulated type detection!)
- }
- else
- { // gefundenen Filter einstellen
- pFilter = aMatcher.GetFilter4FilterName( rtl::OUString::createFromAscii(pFilterName[ nFilter ]) );
- }
+ pFilter = aMatcher.GetFilter4FilterName(OUString::createFromAscii(pFilterName[nFilter]));
bSync = false; // leave inner loop
nFilter = nFilterCount; // leave outer loop
}
commit ca1e8922842254ffdfb186e087bde29a6a8c5062
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Feb 5 10:54:32 2013 -0500
Implement detection for Excel 4.0 format.
Change-Id: Ic0f5c585386f602bd51e006770b30cbb190a531e
diff --git a/sc/source/ui/unoobj/exceldetect.cxx b/sc/source/ui/unoobj/exceldetect.cxx
index 2e0eae2..4119b1d 100644
--- a/sc/source/ui/unoobj/exceldetect.cxx
+++ b/sc/source/ui/unoobj/exceldetect.cxx
@@ -74,6 +74,41 @@ bool hasStream(const uno::Reference<io::XInputStream>& xInStream, const OUString
return xStorage->IsStream(rName);
}
+bool isExcel40(const uno::Reference<io::XInputStream>& xInStream)
+{
+ SfxMedium aMedium;
+ aMedium.UseInteractionHandler(true);
+ aMedium.setStreamToLoadFrom(xInStream, true);
+ SvStream* pStream = aMedium.GetInStream();
+ if (!pStream)
+ return false;
+
+ pStream->Seek(STREAM_SEEK_TO_END);
+ sal_Size nSize = pStream->Tell();
+ pStream->Seek(0);
+
+ if (nSize < 4)
+ return false;
+
+ sal_uInt16 nBofId, nBofSize;
+ *pStream >> nBofId >> nBofSize;
+
+ if (nBofId != 0x0409)
+ // This ID signifies Excel 4.0 format. It must be 0x0409.
+ return false;
+
+ if (nBofSize < 4 || 16 < nBofSize)
+ // BOF record must be sized between 4 and 16 for Excel 4.0 stream.
+ return false;
+
+ sal_Size nPos = pStream->Tell();
+ if (nSize - nPos < nBofSize)
+ // BOF record doesn't have required bytes.
+ return false;
+
+ return true;
+}
+
bool isTemplate(const OUString& rType)
{
return rType.indexOf("_VorlageTemplate") != -1;
@@ -131,9 +166,11 @@ OUString ScExcelBiffDetect::detect( uno::Sequence<beans::PropertyValue>& lDescri
if (aType == "calc_MS_Excel_40" || aType == "calc_MS_Excel_40_VorlageTemplate")
{
// See if this stream is a Excel 4.0 stream.
+ if (!isExcel40(xInStream))
+ return OUString();
- // TODO: Implement this.
- return OUString();
+ aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 4.0 Vorlage/Template") : OUString("MS Excel 4.0");
+ return aType;
}
// failed!
More information about the Libreoffice-commits
mailing list