summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2013-04-24 17:59:49 +0100
committerNoel Power <noel.power@suse.com>2013-05-07 09:56:26 +0100
commitd6bafb1a5b73daab714851449a54b69611c6dffa (patch)
tree30fcfdc575592af0416638bc71e4ea478d2271f5
parent1e41fa0424d00ea9bd340db47a1f6f68b1521d12 (diff)
add Workbook.Save method
has limited support for paramaters ( only FileName and Format are processed ) Change-Id: I669f264679101ab3697dfaa3a3fb3b2d75f5a14b
-rw-r--r--oovbaapi/ooo/vba/excel/XWorkbook.idl6
-rw-r--r--sc/source/ui/vba/vbaworkbook.cxx92
-rw-r--r--sc/source/ui/vba/vbaworkbook.hxx2
3 files changed, 100 insertions, 0 deletions
diff --git a/oovbaapi/ooo/vba/excel/XWorkbook.idl b/oovbaapi/ooo/vba/excel/XWorkbook.idl
index 76eaf2aadf6e..852ac691e54b 100644
--- a/oovbaapi/ooo/vba/excel/XWorkbook.idl
+++ b/oovbaapi/ooo/vba/excel/XWorkbook.idl
@@ -52,6 +52,12 @@ interface XWorkbook
any Colors( [in] any Index ) raises (com::sun::star::script::BasicErrorException);
void SaveCopyAs( [in] string Filename );
void Protect( [in] any Password );
+ void SaveAs( [in] any FileName, [in] any FileFormat, [in] any Password,
+ [in] any WriteResPassword, [in] any ReadOnlyRecommended,
+ [in] any CreateBackup, [in] any AccessMode,
+ [in] any ConflictResolution, [in] any AddToMru,
+ [in] any TextCodepage, [in] any TextVisualLayout,
+ [in] any Local );
};
}; }; };
diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx
index 96aa20574b0b..2df0bde72982 100644
--- a/sc/source/ui/vba/vbaworkbook.cxx
+++ b/sc/source/ui/vba/vbaworkbook.cxx
@@ -30,6 +30,7 @@
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <ooo/vba/excel/XlFileFormat.hpp>
+#include <ooo/vba/excel/XApplication.hpp>
#include "scextopt.hxx"
#include "vbaworksheet.hxx"
@@ -93,6 +94,48 @@ ScVbaWorkbook::Colors( const ::uno::Any& Index ) throw (::script::BasicErrorExce
return aRet;
}
+bool ScVbaWorkbook::setFilterPropsFromFormat( sal_Int32 nFormat, uno::Sequence< beans::PropertyValue >& rProps )
+{
+ bool bRes = false;
+ for ( sal_Int32 index = 0; index < rProps.getLength(); ++index )
+ {
+ if ( rProps[ index ].Name == "FilterName" )
+ {
+ switch( nFormat )
+ {
+ case excel::XlFileFormat::xlCSV:
+ rProps[ index ].Value = uno::Any( OUString("Text - txt - csv (StarCalc)") );
+ break;
+ case excel::XlFileFormat::xlDBF4:
+ rProps[ index ].Value = uno::Any( OUString("DBF") );
+ break;
+ case excel::XlFileFormat::xlDIF:
+ rProps[ index ].Value = uno::Any( OUString("DIF") );
+ break;
+ case excel::XlFileFormat::xlWK3:
+ rProps[ index ].Value = uno::Any( OUString("Lotus") );
+ break;
+ case excel::XlFileFormat::xlExcel4Workbook:
+ rProps[ index ].Value = uno::Any( OUString("MS Excel 4.0") );
+ break;
+ case excel::XlFileFormat::xlExcel5:
+ rProps[ index ].Value = uno::Any( OUString("MS Excel 5.0/95") );
+ break;
+ case excel::XlFileFormat::xlHtml:
+ rProps[ index ].Value = uno::Any( OUString("HTML (StarCalc)") );
+ break;
+ case excel::XlFileFormat::xlExcel9795:
+ default:
+ rProps[ index ].Value = uno::Any( OUString("MS Excel 97") );
+ break;
+ }
+ bRes = true;
+ break;
+ }
+ }
+ return bRes;
+}
+
::sal_Int32 SAL_CALL
ScVbaWorkbook::getFileFormat( ) throw (::uno::RuntimeException)
{
@@ -262,6 +305,55 @@ ScVbaWorkbook::SaveCopyAs( const OUString& sFileName ) throw ( uno::RuntimeExcep
xStor->storeToURL( aURL, storeProps );
}
+void SAL_CALL
+ScVbaWorkbook::SaveAs( const uno::Any& FileName, const uno::Any& FileFormat, const uno::Any& /*Password*/, const uno::Any& /*WriteResPassword*/, const uno::Any& /*ReadOnlyRecommended*/, const uno::Any& /*CreateBackup*/, const uno::Any& /*AccessMode*/, const uno::Any& /*ConflictResolution*/, const uno::Any& /*AddToMru*/, const uno::Any& /*TextCodepage*/, const uno::Any& /*TextVisualLayout*/, const uno::Any& /*Local*/ )
+{
+ OUString sFileName;
+ FileName >>= sFileName;
+ OUString sURL;
+ osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
+ // detect if there is no path if there is no path then we need
+ // to use the current current folder
+ INetURLObject aURL( sURL );
+ sURL = aURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ if( sURL.isEmpty() )
+ {
+ // need to add cur dir ( of this workbook ) or else the 'Work' dir
+ sURL = getModel()->getURL();
+
+ if ( sURL.isEmpty() )
+ {
+ // not path available from 'this' document
+ // need to add the 'document'/work directory then
+ uno::Reference< excel::XApplication > xApplication ( Application(),uno::UNO_QUERY_THROW );
+ OUString sWorkPath = xApplication->getDefaultFilePath();
+ OUString sWorkURL;
+ osl::FileBase::getFileURLFromSystemPath( sWorkPath, sWorkURL );
+ aURL.SetURL( sWorkURL );
+ }
+ else
+ {
+ aURL.SetURL( sURL );
+ aURL.Append( sFileName );
+ }
+ sURL = aURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
+
+ }
+
+ sal_Int32 nFileFormat = excel::XlFileFormat::xlExcel9795;
+ FileFormat >>= nFileFormat;
+
+ uno::Sequence< beans::PropertyValue > storeProps(1);
+ storeProps[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
+
+ setFilterPropsFromFormat( nFileFormat, storeProps );
+
+ uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
+ OUString sFilterName;
+ storeProps[0].Value >>= sFilterName;
+ xStor->storeAsURL( sURL, storeProps );
+}
+
css::uno::Any SAL_CALL
ScVbaWorkbook::Styles( const uno::Any& Item ) throw (uno::RuntimeException)
{
diff --git a/sc/source/ui/vba/vbaworkbook.hxx b/sc/source/ui/vba/vbaworkbook.hxx
index 7288d2aa1d1b..c2e367a27747 100644
--- a/sc/source/ui/vba/vbaworkbook.hxx
+++ b/sc/source/ui/vba/vbaworkbook.hxx
@@ -29,6 +29,7 @@ typedef cppu::ImplInheritanceHelper1< VbaDocumentBase, ov::excel::XWorkbook > Sc
class ScVbaWorkbook : public ScVbaWorkbook_BASE
{
static css::uno::Sequence< sal_Int32 > ColorData;
+ bool setFilterPropsFromFormat( sal_Int32 nFormat, css::uno::Sequence< css::beans::PropertyValue >& rProps );
void initColorData( const css::uno::Sequence< sal_Int32 >& sColors );
void init();
@@ -50,6 +51,7 @@ public:
virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException);
virtual void SAL_CALL Activate() throw (css::uno::RuntimeException);
virtual void SAL_CALL Protect( const css::uno::Any & aPassword ) throw (css::uno::RuntimeException);
+ virtual void SAL_CALL SaveAs( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& CreateBackup, const css::uno::Any& AccessMode, const css::uno::Any& ConflictResolution, const css::uno::Any& AddToMru, const css::uno::Any& TextCodepage, const css::uno::Any& TextVisualLayout, const css::uno::Any& Local );
virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException);
virtual css::uno::Any SAL_CALL Styles( const css::uno::Any& Item ) throw (css::uno::RuntimeException);