12#include <com/sun/star/io/XInputStream.hpp>
13#include <com/sun/star/ucb/ContentCreationException.hpp>
14#include <com/sun/star/uno/XComponentContext.hpp>
30 return "com.sun.star.comp.calc.ExcelBiffFormatDetector";
40 return {
"com.sun.star.frame.ExtendedTypeDetection" };
45bool hasStream(
const uno::Reference<io::XInputStream>& xInStream,
const OUString& rName)
54 sal_uInt64
const nSize = pStream->
TellEnd();
66 if (!xStorage.
is() || xStorage->GetError())
68 return xStorage->IsStream(rName);
70 catch (
const css::ucb::ContentCreationException &)
82bool isExcel40(
const uno::Reference<io::XInputStream>& xInStream)
91 sal_uInt64
const nSize = pStream->
TellEnd();
97 sal_uInt16 nBofId, nBofSize;
111 if (nBofSize < 4 || 16 < nBofSize)
115 sal_uInt64
const nPos = pStream->
Tell();
116 if (nSize - nPos < nBofSize)
123bool isTemplate(std::u16string_view rType)
125 return rType.find(u
"_VorlageTemplate") != std::u16string_view::npos;
134 aMediaDesc[MediaDescriptor::PROP_TYPENAME] >>= aType;
140 uno::Reference<io::XInputStream> xInStream(aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM], uno::UNO_QUERY);
145 if (aType ==
"calc_MS_Excel_97" || aType ==
"calc_MS_Excel_97_VorlageTemplate")
148 if (!hasStream(xInStream,
"Workbook"))
152 aMediaDesc[MediaDescriptor::PROP_FILTERNAME] <<= isTemplate(aType) ? OUString(
"MS Excel 97 Vorlage/Template") : OUString(
"MS Excel 97");
155 else if (aType ==
"calc_MS_Excel_95" || aType ==
"calc_MS_Excel_95_VorlageTemplate")
158 if (!hasStream(xInStream,
"Book"))
161 aMediaDesc[MediaDescriptor::PROP_FILTERNAME] <<= isTemplate(aType) ? OUString(
"MS Excel 95 Vorlage/Template") : OUString(
"MS Excel 95");
164 else if (aType ==
"calc_MS_Excel_5095" || aType ==
"calc_MS_Excel_5095_VorlageTemplate")
167 if (!hasStream(xInStream,
"Book"))
170 aMediaDesc[MediaDescriptor::PROP_FILTERNAME] <<= isTemplate(aType) ? OUString(
"MS Excel 5.0/95 Vorlage/Template") : OUString(
"MS Excel 5.0/95");
173 else if (aType ==
"calc_MS_Excel_40" || aType ==
"calc_MS_Excel_40_VorlageTemplate")
176 if (!isExcel40(xInStream))
179 aMediaDesc[MediaDescriptor::PROP_FILTERNAME] <<= isTemplate(aType) ? OUString(
"MS Excel 4.0 Vorlage/Template") : OUString(
"MS Excel 4.0");
186 aMediaDesc >> lDescriptor;
190extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
192 css::uno::Sequence<css::uno::Any>
const &)
virtual OUString SAL_CALL detect(css::uno::Sequence< css::beans::PropertyValue > &lDescriptor) override
virtual sal_Bool SAL_CALL supportsService(const OUString &aName) override
virtual OUString SAL_CALL getImplementationName() override
virtual ~ScExcelBiffDetect() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void setStreamToLoadFrom(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bIsReadOnly)
void UseInteractionHandler(bool)
virtual sal_uInt64 TellEnd()
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
#define TOOLS_WARN_EXCEPTION(area, stream)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_calc_ExcelBiffFormatDetector_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)