summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-09-14 02:44:36 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-09-14 06:14:37 +0200
commit57f6d49d8e83e39b7d83b9c2e48900538bf88f05 (patch)
tree561ca67fe075f6f7e12d0283bc4e24d181c682b9 /oox
parent0e916b4143b2c46fec6df25cce6f14b595d5b023 (diff)
introduce a special vba export debug mode
In that mode we can write back existing files as part of the vba stream. That allows us to create files that contain to some part out of existing VBA streams. So we have streams that we know are correct and streams that are new from us. Change-Id: I1be04207f887146d9824f97d17866fda440f93a7
Diffstat (limited to 'oox')
-rw-r--r--oox/source/ole/vbaexport.cxx83
1 files changed, 71 insertions, 12 deletions
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index a0fb91a384d8..d31c1e9d61fb 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -40,6 +40,10 @@
#endif
#define VBA_EXPORT_DEBUG 0
+#define VBA_USE_ORIGINAL_WM_STREAM 0
+#define VBA_USE_ORIGINAL_DIR_STREAM 0
+#define VBA_USE_ORIGINAL_PROJECT_STREAM 0
+#define VBA_USE_ORIGINAL_VBA_PROJECT 0
namespace {
@@ -772,6 +776,12 @@ void exportPROJECTwmStream(SvStream& rStrm, const css::uno::Sequence<OUString>&
}
+void addFileStreamToSotStream(const OUString& rPath, SotStorageStream* pStream)
+{
+ SvFileStream aFileStream(rPath, STREAM_READWRITE);
+ pStream->WriteStream(aFileStream);
+}
+
void VbaExport::exportVBA(SotStorage* pRootStorage)
{
css::uno::Reference<css::container::XNameContainer> xNameContainer = getBasicLibrary();
@@ -784,35 +794,84 @@ void VbaExport::exportVBA(SotStorage* pRootStorage)
// start here with the VBA export
SotStorage* pVBAStream = pRootStorage->OpenSotStorage("VBA", STREAM_READWRITE);
SotStorageStream* pDirStream = pVBAStream->OpenSotStream("dir", STREAM_READWRITE);
+
+ SotStorageStream* pVBAProjectStream = pVBAStream->OpenSotStream("_VBA_PROJECT", STREAM_READWRITE);
+ SotStorageStream* pPROJECTStream = pRootStorage->OpenSotStream("PROJECT", STREAM_READWRITE);
+ SotStorageStream* pPROJECTwmStream = pRootStorage->OpenSotStream("PROJECTwm", STREAM_READWRITE);
+
+#if VBA_USE_ORIGINAL_WM_STREAM
+ OUString aProjectwmPath = "/home/moggi/Documents/testfiles/vba/PROJECTwm";
+ addFileStreamToSotStream(aProjectwmPath, pPROJECTwmStream);
+#else
+ exportPROJECTwmStream(*pPROJECTwmStream, aElementNames);
+#endif
+
+#if VBA_USE_ORIGINAL_DIR_STREAM
+ OUString aDirPath = "/home/moggi/Documents/testfiles/vba/VBA/dir";
+ addFileStreamToSotStream(aDirPath, pDirStream);
+#else
std::vector<SotStorageStream*> aModuleStreams;
+ exportDirStream(*pDirStream, xNameContainer);
aModuleStreams.reserve(n);
for (sal_Int32 i = 0; i < n; ++i)
{
aModuleStreams.push_back(pVBAStream->OpenSotStream(aElementNames[i], STREAM_READWRITE));
}
- SotStorageStream* pVBAProjectStream = pVBAStream->OpenSotStream("_VBA_PROJECT", STREAM_READWRITE);
- SotStorageStream* pPROJECTStream = pRootStorage->OpenSotStream("PROJECT", STREAM_READWRITE);
- SotStorageStream* pPROJECTwmStream = pRootStorage->OpenSotStream("PROJECTwm", STREAM_READWRITE);
+#endif
+
+#if VBA_USE_ORIGINAL_PROJECT_STREAM
+ OUString aProjectPath = "/home/moggi/Documents/testfiles/vba/PROJECT";
+ addFileStreamToSotStream(aProjectPath, pPROJECTStream);
+#else
+ exportPROJECTStream(*pPROJECTStream, xNameContainer, getProjectName());
+#endif
+
+#if VBA_USE_ORIGINAL_VBA_PROJECT
+ OUString a_VBA_ProjectPath = "/home/moggi/Documents/testfiles/vba/VBA/_VBA_PROJECT";
+ addFileStreamToSotStream(a_VBA_ProjectPath, pVBAProjectStream);
+#else
+ exportVBAProjectStream(*pVBAProjectStream);
+#endif
+#if VBA_USE_ORIGINAL_DIR_STREAM
+ OUString aModule1Path = "/home/moggi/Documents/testfiles/vba/VBA/Module1";
+ OUString aSheet1Path = "/home/moggi/Documents/testfiles/vba/VBA/Sheet1";
+ OUString aSheet2Path = "/home/moggi/Documents/testfiles/vba/VBA/Sheet2";
+ OUString aSheet3Path = "/home/moggi/Documents/testfiles/vba/VBA/Sheet3";
+ OUString aWorkbookPath = "/home/moggi/Documents/testfiles/vba/VBA/ThisWorkbook";
+ SotStorageStream* pModule1Stream = pVBAStream->OpenSotStream("Module1", STREAM_READWRITE);
+ SotStorageStream* pSheet1Stream = pVBAStream->OpenSotStream("Sheet1", STREAM_READWRITE);
+ SotStorageStream* pSheet2Stream = pVBAStream->OpenSotStream("Sheet2", STREAM_READWRITE);
+ SotStorageStream* pSheet3Stream = pVBAStream->OpenSotStream("Sheet3", STREAM_READWRITE);
+ SotStorageStream* pWorkbookStream = pVBAStream->OpenSotStream("ThisWorkbook", STREAM_READWRITE);
+ addFileStreamToSotStream(aModule1Path, pModule1Stream);
+ addFileStreamToSotStream(aSheet1Path, pSheet1Stream);
+ addFileStreamToSotStream(aSheet2Path, pSheet2Stream);
+ addFileStreamToSotStream(aSheet3Path, pSheet3Stream);
+ addFileStreamToSotStream(aWorkbookPath, pWorkbookStream);
+
+ pModule1Stream->Commit();
+ pSheet1Stream->Commit();
+ pSheet2Stream->Commit();
+ pSheet3Stream->Commit();
+ pWorkbookStream->Commit();
+#else
- // export
- exportDirStream(*pDirStream, xNameContainer);
+ css::uno::Reference<css::script::vba::XVBAModuleInfo> xModuleInfo(xNameContainer, css::uno::UNO_QUERY);
for (sal_Int32 i = 0; i < n; ++i)
{
css::uno::Any aCode = xNameContainer->getByName(aElementNames[i]);
+ css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(aElementNames[i]);
OUString aSourceCode;
aCode >>= aSourceCode;
exportModuleStream(*aModuleStreams[i], aSourceCode, aElementNames[i]);
+ aModuleStreams[i]->Commit();
}
- exportVBAProjectStream(*pVBAProjectStream);
- exportPROJECTStream(*pPROJECTStream, xNameContainer, getProjectName());
- exportPROJECTwmStream(*pPROJECTwmStream, aElementNames);
+
+#endif
pVBAProjectStream->Commit();
- for(sal_Int32 i = 0; i < n; i++)
- {
- aModuleStreams[i]->Commit();
- }
+
pDirStream->Commit();
pVBAStream->Commit();
pPROJECTStream->Commit();