22 #include <sfx2/sfxsids.hrc>
27 #include <com/sun/star/packages/XPackageEncryption.hpp>
28 #include <com/sun/star/ucb/ContentCreationException.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <osl/diagnose.h>
35 #include <document.hxx>
57 for (
const auto & aElement : aElements)
59 OUString sStreamFullName = sPrefix.getLength() ? sPrefix +
"/" + aElement.GetName() : aElement.GetName();
60 if (aElement.IsStorage())
71 sal_Int32 nStreamSize = rStream->
GetSize();
72 uno::Sequence< sal_Int8 > oData;
73 oData.realloc(nStreamSize);
74 sal_Int32 nReadBytes = rStream->ReadBytes(oData.getArray(), nStreamSize);
75 if (nStreamSize == nReadBytes)
76 aStreamsData[sStreamFullName] <<= oData;
89 uno::Reference< packages::XPackageEncryption > xPackageEncryption(
90 xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
91 "com.sun.star.comp.oox.crypto.DRMDataSpace", aArguments, xComponentContext), uno::UNO_QUERY);
93 if (!xPackageEncryption.is())
104 if (!xPackageEncryption->readEncryptionInfo(aStreams))
111 if (!rContentStream.
is())
116 rNewStorageStrm = std::make_shared<SvMemoryStream>();
121 if (!xPackageEncryption->decrypt(xInputStream, xDecryptedStream))
127 rNewStorageStrm->Seek(0);
130 aNewStorage =
new SotStorage(*rNewStorageStrm);
133 uno::Sequence<beans::NamedValue> aEncryptionData = xPackageEncryption->createEncryptionData(
"");
136 catch (
const std::exception&)
147 OSL_ENSURE( pDocument,
"::ScImportExcel - no document" );
154 OSL_FAIL(
"::ScImportExcel - wrong file format specification" );
160 OSL_ENSURE( pMedStrm,
"::ScImportExcel - medium without input stream" );
169 std::shared_ptr<SvStream> aNewStorageStrm;
172 xRootStrg =
new SotStorage( pMedStrm,
false );
200 xStrgStrm = xWorkbookStrm;
201 eBiff = eWorkbookBiff;
207 xStrgStrm = xBookStrm;
211 pBookStrm = xStrgStrm.
get();
219 pBookStrm = pMedStrm;
229 eBiff, rMedium, xRootStrg, *pDocument,
231 std::unique_ptr< ImportExcel > xFilter;
238 xFilter.reset(
new ImportExcel( aImpData, *pBookStrm ) );
241 xFilter.reset(
new ImportExcel8( aImpData, *pBookStrm ) );
253 SvStream* pMedStrm,
bool bBiff8, rtl_TextEncoding eNach )
255 uno::Reference< packages::XPackageEncryption > xPackageEncryption;
256 uno::Sequence< beans::NamedValue > aEncryptionData;
257 const SfxUnoAnyItem* pEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(rMedium.
GetItemSet(), SID_ENCRYPTIONDATA,
false);
258 SvStream* pOriginalMediaStrm = pMedStrm;
259 std::shared_ptr<SvStream> pMediaStrm;
260 if (pEncryptionDataItem && (pEncryptionDataItem->
GetValue() >>= aEncryptionData))
265 if (sCryptoType.getLength())
270 xPackageEncryption.set(
271 xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
272 "com.sun.star.comp.oox.crypto." + sCryptoType,
aArguments, xComponentContext), uno::UNO_QUERY);
274 if (xPackageEncryption.is())
277 pMediaStrm = std::make_shared<SvMemoryStream>();
278 pMedStrm = pMediaStrm.get();
291 OUString aStrmName, aClipName, aClassName;
296 aClassName =
"Microsoft Excel 97-Tabelle";
302 aClassName =
"Microsoft Excel 5.0-Tabelle";
309 xStrgStrm->SetBufferSize( 0x8000 );
316 eRet = aFilter.
Write();
321 eRet = aFilter.
Write();
329 xRootStrg->
SetClass( aGlobName, nClip, aClassName );
334 if (xPackageEncryption.is())
339 xPackageEncryption->setupEncryption(aEncryptionData);
342 uno::Sequence<beans::NamedValue> aStreams = xPackageEncryption->encrypt(xInputStream);
345 for (
const beans::NamedValue & aStreamData : std::as_const(aStreams))
354 OUString sPathElem = aStreamData.Name.getToken(0, L
'/', idx);
355 if (!sPathElem.isEmpty())
359 sFileName = sPathElem;
366 }
while (pStorage && idx >= 0);
380 uno::Sequence<sal_Int8> aStreamContent;
381 aStreamData.Value >>= aStreamContent;
382 size_t nBytesWritten = pStream->WriteBytes(aStreamContent.getConstArray(), aStreamContent.getLength());
383 if (nBytesWritten != static_cast<size_t>(aStreamContent.getLength()))
389 xEncryptedRootStrg->
Commit();
405 OSL_ENSURE( pDocument,
"::ScExportExcel5 - no document" );
410 OSL_ENSURE( pMedStrm,
"::ScExportExcel5 - medium without output stream" );
435 catch (
const std::range_error&)
451 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
452 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
470 catch (
const css::ucb::ContentCreationException&)
473 catch (
const std::out_of_range&)
std::vector< SvStorageInfo > SvStorageInfoList
static ErrCode lcl_ExportExcelBiff(SfxMedium &rMedium, ScDocument *pDocument, SvStream *pMedStrm, bool bBiff8, rtl_TextEncoding eNach)
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
XclBiff
An enumeration for all Excel file format types (BIFF types).
Stores global buffers and data needed for Excel export filter.
Stores global buffers and data needed for Excel import filter.
void FillInfoList(SvStorageInfoList *) const
static tools::SvRef< SotStorage > lcl_DRMDecrypt(const SfxMedium &rMedium, const tools::SvRef< SotStorage > &rStorage, std::shared_ptr< SvStream > &rNewStorageStrm)
#define SCWARN_IMPORT_RANGE_OVERFLOW
sal_uInt32 GetSize() const
sal_uInt64 Seek(sal_uInt64 nPos)
css::uno::Sequence< css::beans::NamedValue > getAsConstNamedValueList() const
constexpr OUStringLiteral EXC_STREAM_BOOK
static bool IsStorageFile(OUString const &rFileName)
constexpr OUStringLiteral EXC_STREAM_WORKBOOK
SotStorage * OpenSotStorage(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE, bool transacted=true)
Sequence< PropertyValue > aArguments
MS Excel 8.0 (97), 9.0 (2000), 10.0 (XP), 11.0 (2003)
rtl_TextEncoding utl_getWinTextEncodingFromLangStr(const OUString &sLanguage, bool bOEM)
#define SCERR_IMPORT_INTERNAL
#define MSO_EXCEL5_CLASSID
void SetLookUpColRowNames(bool bVal)
SvStream * GetOutStream()
const css::uno::Any & GetValue() const
#define ERRCODE_IO_CANTWRITE
void SetInsertingFromOtherDoc(bool bVal)
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
#define SCWARN_EXPORT_MAXROW
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
MS Excel 5.0, MS Excel 7.0 (95)
void EnableExecuteLink(bool bVal)
#define ERRCODE_IO_GENERAL
SAL_DLLPUBLIC_EXPORT bool TestImportCalcRTF(SvStream &rStream)
void SetClass(const SvGlobalName &rClass, SotClipboardFormatId bOriginalClipFormat, const OUString &rUserTypeName)
SAL_DLLPUBLIC_EXPORT bool TestImportXLS(SvStream &rStream)
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
static SC_DLLPUBLIC void Init()
DLL-init/exit-code must be linked to the DLL only.
static void lcl_getListOfStreams(SotStorage *pStorage, comphelper::SequenceAsHashMap &aStreamsData, const OUString &sPrefix)
SfxItemSet * GetItemSet() const
void SetBufferSize(sal_uInt16 m_nBufSize)
SAL_DLLPUBLIC_EXPORT bool TestImportDIF(SvStream &rStream)
#define SCERR_IMPORT_OPEN
#define SCERR_IMPORT_UNKNOWN_BIFF
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Reference< XComponentContext > getProcessComponentContext()
#define SCERR_IMPORT_FORMAT
const ScDocument & GetDocument() const
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
OUString utl_getLocaleForGlobalDefaultEncoding()
static XclBiff DetectBiffVersion(SvStream &rStrm)
Detects the BIFF version of the passed workbook stream.