summaryrefslogtreecommitdiff
path: root/sc/source/ui/unoobj/exceldetect.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-02-05 10:54:32 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-02-05 11:07:16 -0500
commitca1e8922842254ffdfb186e087bde29a6a8c5062 (patch)
tree1b89bafcdd16acbacad492844314c3c49fc21ba5 /sc/source/ui/unoobj/exceldetect.cxx
parent5753df3c6f75e4efb5ecf54e552c84c40577e31d (diff)
Implement detection for Excel 4.0 format.
Change-Id: Ic0f5c585386f602bd51e006770b30cbb190a531e
Diffstat (limited to 'sc/source/ui/unoobj/exceldetect.cxx')
-rw-r--r--sc/source/ui/unoobj/exceldetect.cxx41
1 files changed, 39 insertions, 2 deletions
diff --git a/sc/source/ui/unoobj/exceldetect.cxx b/sc/source/ui/unoobj/exceldetect.cxx
index 2e0eae259a96..4119b1d6592b 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!