diff options
author | Noel Power <noel.power@suse.com> | 2013-04-24 17:59:49 +0100 |
---|---|---|
committer | Noel Power <noel.power@suse.com> | 2013-05-09 14:11:20 +0100 |
commit | 569c019883f0c1bb624d2dddb12914facd30e82b (patch) | |
tree | f39f5d50e0955c72d57de64f971d72e049411f4e /sc | |
parent | b2d1526203adfe462e744e8b14dabbd4fddf0406 (diff) |
add Workbook.Save method
has limited support for paramaters ( only FileName and Format are processed )
Change-Id: I669f264679101ab3697dfaa3a3fb3b2d75f5a14b
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/vba/vbaworkbook.cxx | 92 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaworkbook.hxx | 2 |
2 files changed, 94 insertions, 0 deletions
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); |