22 #include <com/sun/star/util/XProtectable.hpp>
23 #include <com/sun/star/sheet/XNamedRanges.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
25 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <com/sun/star/frame/XStorable.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <ooo/vba/excel/XlFileFormat.hpp>
29 #include <ooo/vba/excel/XApplication.hpp>
38 #include <osl/file.hxx>
53 std::copy(sColors.begin(), sColors.end(),
ColorData.begin());
60 sal_Int32 nLen = xIndexAccess->getCount();
63 uno::Sequence< sal_Int32 > dDefaultColors( nLen );
64 sal_Int32* pDest = dDefaultColors.getArray();
66 xIndexAccess->getByIndex(
index ) >>= *pDest;
74 if ( Index.hasValue() )
87 auto pProp = std::find_if(rProps.begin(), rProps.end(),
88 [](
const beans::PropertyValue& rProp) {
return rProp.Name ==
"FilterName"; });
89 bool bRes = pProp != rProps.end();
94 case excel::XlFileFormat::xlCSV:
97 case excel::XlFileFormat::xlDBF4:
98 pProp->Value <<= OUString(
"DBF");
100 case excel::XlFileFormat::xlDIF:
101 pProp->Value <<= OUString(
"DIF");
103 case excel::XlFileFormat::xlWK3:
104 pProp->Value <<= OUString(
"Lotus");
106 case excel::XlFileFormat::xlExcel4Workbook:
107 pProp->Value <<= OUString(
"MS Excel 4.0");
109 case excel::XlFileFormat::xlExcel5:
110 pProp->Value <<= OUString(
"MS Excel 5.0/95");
112 case excel::XlFileFormat::xlHtml:
113 pProp->Value <<= OUString(
"HTML (StarCalc)");
115 case excel::XlFileFormat::xlExcel9795:
117 pProp->Value <<= OUString(
"MS Excel 97");
127 sal_Int32 aFileFormat = 0;
128 OUString aFilterName;
129 uno::Sequence< beans::PropertyValue > aArgs = getModel()->getArgs();
133 if ( aArgs[0].
Name ==
"FilterName" ) {
134 aArgs[0].Value >>= aFilterName;
136 aArgs[1].Value >>= aFilterName;
140 aFileFormat = excel::XlFileFormat::xlCSV;
143 if ( aFilterName ==
"DBF" ) {
144 aFileFormat = excel::XlFileFormat::xlDBF4;
147 if ( aFilterName ==
"DIF" ) {
148 aFileFormat = excel::XlFileFormat::xlDIF;
151 if ( aFilterName ==
"Lotus" ) {
152 aFileFormat = excel::XlFileFormat::xlWK3;
155 if ( aFilterName ==
"MS Excel 4.0" ) {
156 aFileFormat = excel::XlFileFormat::xlExcel4Workbook;
159 if ( aFilterName ==
"MS Excel 5.0/95" ) {
160 aFileFormat = excel::XlFileFormat::xlExcel5;
163 if ( aFilterName ==
"MS Excel 97" ) {
164 aFileFormat = excel::XlFileFormat::xlExcel9795;
167 if (aFilterName ==
"HTML (StarCalc)") {
168 aFileFormat = excel::XlFileFormat::xlHtml;
171 if ( aFilterName ==
"calc_StarOffice_XML_Calc_Template" ) {
172 aFileFormat = excel::XlFileFormat::xlTemplate;
175 if (aFilterName ==
"StarOffice XML (Calc)") {
176 aFileFormat = excel::XlFileFormat::xlWorkbookNormal;
178 if ( aFilterName ==
"calc8" ) {
179 aFileFormat = excel::XlFileFormat::xlWorkbookNormal;
190 uno::Reference< frame::XModel >
xModel = getModel();
195 ScVbaWorkbook::ScVbaWorkbook(
const css::uno::Reference< ov::XHelperInterface >& xParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::frame::XModel >
const & xModel ) :
ScVbaWorkbook_BASE( xParent, xContext, xModel )
201 uno::Reference< uno::XComponentContext>
const & xContext ) :
ScVbaWorkbook_BASE( args, xContext )
206 uno::Reference< excel::XWorksheet >
210 uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
211 uno::Reference< sheet::XSpreadsheet > xSheet( xView->getActiveSheet(), uno::UNO_SET_THROW );
214 if( xWorksheet.is() )
return xWorksheet;
228 uno::Reference< frame::XModel >
xModel( getModel() );
229 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
230 uno::Reference<container::XIndexAccess > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
232 if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
237 return xWorkSheets->Item( aIndex,
uno::Any() );
244 if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
246 return xWindows->Item( aIndex,
uno::Any() );
264 uno::Reference< util::XProtectable > xProt( getModel(), uno::UNO_QUERY_THROW );
265 return xProt->isProtected();
270 uno::Reference< frame::XModel >
xModel( getModel(), uno::UNO_SET_THROW );
277 uno::Reference< frame::XModel >
xModel( getModel(), uno::UNO_SET_THROW );
286 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( getModel(), uno::UNO_QUERY );
289 uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
290 return xDocProps->getAuthor();
295 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( getModel(), uno::UNO_QUERY );
298 uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
299 xDocProps->setAuthor( _author );
306 osl::FileBase::getFileURLFromSystemPath( sFileName, aURL );
307 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
308 uno::Sequence< beans::PropertyValue > storeProps(1);
309 storeProps[0].Name =
"FilterName";
310 storeProps[0].Value <<= OUString(
"MS Excel 97" );
311 xStor->storeToURL( aURL, storeProps );
315 ScVbaWorkbook::SaveAs(
const uno::Any& FileName,
const uno::Any& FileFormat,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
318 FileName >>= sFileName;
320 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
328 sURL = getModel()->getURL();
330 if ( sURL.isEmpty() )
334 uno::Reference< excel::XApplication > xApplication (
Application(),uno::UNO_QUERY_THROW );
335 OUString sWorkPath = xApplication->getDefaultFilePath();
337 osl::FileBase::getFileURLFromSystemPath( sWorkPath, sWorkURL );
349 sal_Int32 nFileFormat = excel::XlFileFormat::xlExcel9795;
350 FileFormat >>= nFileFormat;
352 uno::Sequence< beans::PropertyValue > storeProps(1);
353 storeProps[0].Name =
"FilterName" ;
357 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
358 xStor->storeAsURL( sURL, storeProps );
361 css::uno::Any SAL_CALL
367 uno::Reference< XCollection > dStyles =
new ScVbaStyles( uno::Reference< XHelperInterface >(),
mxContext, getModel() );
369 return dStyles->Item( Item,
uno::Any() );
370 return uno::makeAny( dStyles );
376 uno::Reference< frame::XModel >
xModel( getModel(), uno::UNO_SET_THROW );
377 uno::Reference< beans::XPropertySet > xProps( xModel, uno::UNO_QUERY_THROW );
378 uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue(
"NamedRanges"), uno::UNO_QUERY_THROW );
379 uno::Reference< XCollection > xNames(
new ScVbaNames(
this,
mxContext, xNamedRanges, xModel ) );
381 return xNames->Item( aIndex,
uno::Any() );
388 return "ScVbaWorkbook";
391 uno::Sequence< OUString >
396 "ooo.vba.excel.Workbook"
404 uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY_THROW );
405 return xModelProp->getPropertyValue(
"CodeName").get< OUString >();
411 if (isUnoTunnelId<ScVbaWorksheet>(rId))
413 return sal::static_int_cast<sal_Int64>(
reinterpret_cast<sal_IntPtr
>(
this));
418 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
420 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
virtual css::uno::Any SAL_CALL Windows(const css::uno::Any &aIndex) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_ScVbaWorkbook_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
void RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const &xWorkbook)
virtual OUString SAL_CALL getAuthor() override
ScVbaWorkbook(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::frame::XModel > const &xModel)
virtual css::uno::Sequence< OUString > getServiceNames() override
Sequence< OUString > aServiceNames
virtual void SAL_CALL ResetColors() override
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
virtual css::uno::Any SAL_CALL Sheets(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL Worksheets(const css::uno::Any &aIndex) override
uno::Reference< XHelperInterface > getUnoSheetModuleObj(const uno::Reference< table::XCellRange > &xRange)
virtual void SAL_CALL setPrecisionAsDisplayed(sal_Bool _precisionAsDisplayed) override
virtual void SAL_CALL Activate() override
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) override
virtual ::sal_Int32 SAL_CALL getFileFormat() override
void SetCalcAsShown(bool bVal)
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
virtual ::sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
bool Append(OUString const &rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
cppu::ImplInheritanceHelper< VbaDocumentBase, ov::excel::XWorkbook > ScVbaWorkbook_BASE
virtual void SAL_CALL Protect(const css::uno::Any &aPassword) override
static css::uno::Sequence< sal_Int32 > ColorData
virtual css::uno::Any SAL_CALL Names(const css::uno::Any &aIndex) override
virtual void SAL_CALL Protect(const css::uno::Any &aPassword)
virtual css::uno::Any SAL_CALL Styles(const css::uno::Any &Item) override
virtual void SAL_CALL Activate() override
virtual css::uno::Any SAL_CALL Colors(const css::uno::Any &Index) override
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static void initColorData(const css::uno::Sequence< sal_Int32 > &sColors)
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
static bool setFilterPropsFromFormat(sal_Int32 nFormat, css::uno::Sequence< css::beans::PropertyValue > &rProps)
bool IsCalcAsShown() const
virtual void SAL_CALL SaveCopyAs(const OUString &Filename) override
#define SC_TEXT_CSV_FILTER_NAME
const ScDocument & GetDocument() const
uno::Reference< frame::XModel > getCurrentExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
virtual void SAL_CALL setAuthor(const OUString &_author) override
virtual OUString getServiceImplName() override
bool SetURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Reference< XModel > xModel
virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet() override
virtual sal_Bool SAL_CALL getProtectStructure() override
virtual sal_Bool SAL_CALL getPrecisionAsDisplayed() override
static css::uno::Reference< css::container::XIndexAccess > getDefaultPalette()
virtual OUString SAL_CALL getCodeName() override