22#include <sfx2/sfxsids.hrc>
28#include <com/sun/star/document/UpdateDocMode.hpp>
29#include <com/sun/star/packages/XPackageEncryption.hpp>
30#include <com/sun/star/ucb/ContentCreationException.hpp>
31#include <com/sun/star/uno/XComponentContext.hpp>
35#include <osl/diagnose.h>
37#include <document.hxx>
59 for (
const auto & aElement : aElements)
61 OUString sStreamFullName =
sPrefix.size() ? OUString::Concat(
sPrefix) +
"/" + aElement.GetName() : aElement.GetName();
62 if (aElement.IsStorage())
73 sal_Int32 nStreamSize = rStream->GetSize();
74 uno::Sequence< sal_Int8 > oData;
75 oData.realloc(nStreamSize);
76 sal_Int32 nReadBytes = rStream->ReadBytes(oData.getArray(), nStreamSize);
77 if (nStreamSize == nReadBytes)
78 aStreamsData[sStreamFullName] <<= oData;
91 uno::Reference< packages::XPackageEncryption > xPackageEncryption(
92 xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
93 "com.sun.star.comp.oox.crypto.DRMDataSpace",
aArguments, xComponentContext), uno::UNO_QUERY);
95 if (!xPackageEncryption.is())
106 if (!xPackageEncryption->readEncryptionInfo(aStreams))
113 if (!rContentStream.
is())
118 rNewStorageStrm = std::make_shared<SvMemoryStream>();
123 if (!xPackageEncryption->decrypt(xInputStream, xDecryptedStream))
129 rNewStorageStrm->Seek(0);
132 aNewStorage =
new SotStorage(*rNewStorageStrm);
135 uno::Sequence<beans::NamedValue> aEncryptionData = xPackageEncryption->createEncryptionData(
"");
138 catch (
const std::exception&)
149 OSL_ENSURE( pDocument,
"::ScImportExcel - no document" );
156 OSL_FAIL(
"::ScImportExcel - wrong file format specification" );
162 OSL_ENSURE( pMedStrm,
"::ScImportExcel - medium without input stream" );
171 std::shared_ptr<SvStream> aNewStorageStrm;
174 xRootStrg =
new SotStorage( pMedStrm,
false );
175 if( xRootStrg->GetError() )
202 xStrgStrm = xWorkbookStrm;
203 eBiff = eWorkbookBiff;
209 xStrgStrm = xBookStrm;
213 pBookStrm = xStrgStrm.
get();
221 pBookStrm = pMedStrm;
231 eBiff, rMedium, xRootStrg, *pDocument,
233 std::unique_ptr< ImportExcel > xFilter;
240 xFilter.reset(
new ImportExcel( aImpData, *pBookStrm ) );
243 xFilter.reset(
new ImportExcel8( aImpData, *pBookStrm ) );
255 SvStream* pMedStrm,
bool bBiff8, rtl_TextEncoding eNach )
257 uno::Reference< packages::XPackageEncryption > xPackageEncryption;
258 uno::Sequence< beans::NamedValue > aEncryptionData;
260 SvStream* pOriginalMediaStrm = pMedStrm;
261 std::shared_ptr<SvStream> pMediaStrm;
262 if (pEncryptionDataItem && (pEncryptionDataItem->
GetValue() >>= aEncryptionData))
267 if (sCryptoType.getLength())
272 xPackageEncryption.set(
273 xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
274 "com.sun.star.comp.oox.crypto." + sCryptoType,
aArguments, xComponentContext), uno::UNO_QUERY);
276 if (xPackageEncryption.is())
279 pMediaStrm = std::make_shared<SvMemoryStream>();
280 pMedStrm = pMediaStrm.get();
293 OUString aStrmName, aClipName, aClassName;
298 aClassName =
"Microsoft Excel 97-Tabelle";
304 aClassName =
"Microsoft Excel 5.0-Tabelle";
311 xStrgStrm->SetBufferSize( 0x8000 );
318 eRet = aFilter.
Write();
323 eRet = aFilter.
Write();
331 xRootStrg->SetClass( aGlobName, nClip, aClassName );
336 if (xPackageEncryption.is())
341 xPackageEncryption->setupEncryption(aEncryptionData);
344 uno::Sequence<beans::NamedValue> aStreams = xPackageEncryption->encrypt(xInputStream);
347 for (
const beans::NamedValue & aStreamData : std::as_const(aStreams))
356 OUString sPathElem = aStreamData.Name.getToken(0, L
'/',
idx);
357 if (!sPathElem.isEmpty())
361 sFileName = sPathElem;
365 pStorage = pStorage->OpenSotStorage(sPathElem);
368 }
while (pStorage &&
idx >= 0);
382 uno::Sequence<sal_Int8> aStreamContent;
383 aStreamData.Value >>= aStreamContent;
384 size_t nBytesWritten = pStream->WriteBytes(aStreamContent.getConstArray(), aStreamContent.getLength());
385 if (nBytesWritten !=
static_cast<size_t>(aStreamContent.getLength()))
391 xEncryptedRootStrg->Commit();
407 OSL_ENSURE( pDocument,
"::ScExportExcel5 - no document" );
412 OSL_ENSURE( pMedStrm,
"::ScExportExcel5 - medium without output stream" );
428 aDocument.SetInsertingFromOtherDoc(
true);
437 catch (
const std::range_error&)
454 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
455 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
457 xDocShell->DoInitNew();
458 xDocShell->SetInitialLinkUpdate(&aMedium);
474 catch (
const css::ucb::ContentCreationException&)
477 catch (
const std::out_of_range&)
480 xDocShell->DoClose();
494 aDocument.SetInsertingFromOtherDoc(
true);
static SC_DLLPUBLIC void Init()
DLL-init/exit-code must be linked to the DLL only.
void SetLookUpColRowNames(bool bVal)
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
void EnableExecuteLink(bool bVal)
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
void SetInsertingFromOtherDoc(bool bVal)
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemSet & GetItemSet() const
SvStream * GetOutStream()
const css::uno::Any & GetValue() const
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
void FillInfoList(SvStorageInfoList *) const
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
static bool IsStorageFile(OUString const &rFileName)
SotStorage * OpenSotStorage(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE, bool transacted=true)
void SetBufferSize(sal_uInt16 m_nBufSize)
sal_uInt64 Seek(sal_uInt64 nPos)
static XclBiff DetectBiffVersion(SvStream &rStrm)
Detects the BIFF version of the passed workbook stream.
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
css::uno::Sequence< css::beans::NamedValue > getAsConstNamedValueList() const
#define MSO_EXCEL5_CLASSID
UNOTOOLS_DLLPUBLIC OUString utl_getLocaleForGlobalDefaultEncoding()
#define ERRCODE_IO_GENERAL
#define ERRCODE_IO_CANTWRITE
SAL_DLLPUBLIC_EXPORT bool TestImportDIF(SvStream &rStream)
SAL_DLLPUBLIC_EXPORT bool TestImportXLS(SvStream &rStream)
static tools::SvRef< SotStorage > lcl_DRMDecrypt(const SfxMedium &rMedium, const tools::SvRef< SotStorage > &rStorage, std::shared_ptr< SvStream > &rNewStorageStrm)
static void lcl_getListOfStreams(SotStorage *pStorage, comphelper::SequenceAsHashMap &aStreamsData, std::u16string_view sPrefix)
SAL_DLLPUBLIC_EXPORT bool TestImportCalcRTF(SvStream &rStream)
static ErrCode lcl_ExportExcelBiff(SfxMedium &rMedium, ScDocument *pDocument, SvStream *pMedStrm, bool bBiff8, rtl_TextEncoding eNach)
Sequence< PropertyValue > aArguments
Reference< XComponentContext > getProcessComponentContext()
#define SCERR_IMPORT_FORMAT
#define SCWARN_IMPORT_RANGE_OVERFLOW
#define SCERR_IMPORT_OPEN
#define SCERR_IMPORT_INTERNAL
#define SCWARN_EXPORT_MAXROW
#define SCERR_IMPORT_UNKNOWN_BIFF
std::vector< SvStorageInfo > SvStorageInfoList
Stores global buffers and data needed for Excel export filter.
Stores global buffers and data needed for Excel import filter.
UNOTOOLS_DLLPUBLIC rtl_TextEncoding utl_getWinTextEncodingFromLangStr(const OUString &sLanguage, bool bOEM=false)
constexpr OUStringLiteral EXC_STREAM_WORKBOOK
constexpr OUStringLiteral EXC_STREAM_BOOK
XclBiff
An enumeration for all Excel file format types (BIFF types).
@ EXC_BIFF_UNKNOWN
MS Excel 8.0 (97), 9.0 (2000), 10.0 (XP), 11.0 (2003)
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)