20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/container/XEnumerationAccess.hpp>
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <com/sun/star/document/XTypeDetection.hpp>
33 #include <osl/file.hxx>
34 #include <rtl/ref.hxx>
42 getWorkbook(
const uno::Reference< uno::XComponentContext >& xContext,
43 const uno::Reference< sheet::XSpreadsheetDocument > &xDoc,
44 const uno::Reference< XHelperInterface >& xParent )
47 uno::Reference< frame::XModel >
xModel( xDoc, uno::UNO_QUERY );
51 uno::Reference< excel::XWorkbook > xWb(
getVBADocument( xModel ), uno::UNO_QUERY );
58 return uno::Any( uno::Reference< excel::XWorkbook > (pWb) );
67 WorkBookEnumImpl(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ) {}
69 virtual uno::Any SAL_CALL nextElement( )
override
71 uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
88 uno::Reference< container::XEnumeration >
95 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
96 return new WorkBookEnumImpl(
mxParent,
mxContext, xEnumerationAccess->createEnumeration() );
102 uno::Reference< sheet::XSpreadsheetDocument > xDoc( aSource, uno::UNO_QUERY_THROW );
109 uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc;
110 sal_Int32 nWorkbookType = 0;
111 OUString aTemplateFileName;
112 if( Template >>= nWorkbookType )
117 xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW );
119 uno::Reference< sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_SET_THROW );
120 uno::Reference< container::XIndexAccess > xSheetsIA( xSheets, uno::UNO_QUERY_THROW );
121 while( xSheetsIA->getCount() > 1 )
123 uno::Reference< container::XNamed > xSheetName( xSheetsIA->getByIndex( xSheetsIA->getCount() - 1 ), uno::UNO_QUERY_THROW );
124 xSheets->removeByName( xSheetName->getName() );
127 else if( Template >>= aTemplateFileName )
130 xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW );
135 xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW );
140 throw uno::RuntimeException();
145 if( xSpreadDoc.is() )
163 return sType ==
u"generic_Text" || sType.empty();
170 return sType.startsWith(
"calc_MS" )
171 || sType.startsWith(
"MS Excel" )
172 || sType.startsWith(
"calc8" )
173 || sType.startsWith(
"calc_StarOffice" );
179 uno::Reference< document::XTypeDetection > xTypeDetect(
mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.TypeDetection",
mxContext), uno::UNO_QUERY_THROW );
180 uno::Sequence< beans::PropertyValue > aMediaDesc(1);
181 aMediaDesc[ 0 ].Name =
"URL";
182 aMediaDesc[ 0 ].Value <<= rFileName;
183 OUString
sType = xTypeDetect->queryTypeByDescriptor( aMediaDesc,
true );
189 ScVbaWorkbooks::Open(
const OUString& rFileName,
const uno::Any& ,
const uno::Any& ReadOnly,
const uno::Any& Format,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& Delimiter,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
195 bool bIsURL = aObj.
GetProtocol() != INetProtocol::NotValid;
199 osl::FileBase::getFileURLFromSystemPath( rFileName, aURL );
201 uno::Sequence< beans::PropertyValue > sProps(0);
217 sProps[ nIndex ].Name =
"FilterOptions";
218 sal_Int16
const delims[] { 0 , 9, 44, 32, 59 };
221 sal_Int16 nFormat = 0;
227 if ( nFormat < 1 || nFormat > 6 )
228 throw uno::RuntimeException(
"Illegal value for Format" );
235 nDelim = delims[ nFormat ];
241 throw uno::RuntimeException(
"Expected value for Delimiter" );
244 if ( sStr.isEmpty() )
245 throw uno::RuntimeException(
"Incorrect value for Delimiter" );
253 sFormat = OUString::number( nDelim ) +
",34,0,1";
254 sProps[ nIndex++ ].Value <<= sFormat;
255 sProps[ nIndex ].Name =
"FilterName";
259 sProps[ nIndex ].Name =
"DocumentService";
260 sProps[ nIndex ].Value <<= OUString(
"com.sun.star.sheet.SpreadsheetDocument");
263 throw uno::RuntimeException(
"Bad Format" );
265 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( openDocument( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW );
267 uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY );
276 return "ScVbaWorkbooks";
279 css::uno::Sequence<OUString>
282 static uno::Sequence< OUString >
const sNames
284 "ooo.vba.excel.Workbooks"
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
ScVbaWorkbooks(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
void setUpDocumentModules(const uno::Reference< sheet::XSpreadsheetDocument > &xDoc)
WeakReference< XInterface > mxParent
virtual css::uno::Sequence< OUString > getServiceNames() override
const sal_Int16 CUSTOM_CHAR
virtual OUString getServiceImplName() override
static sal_Int16 & getCurrentDelim()
virtual void SAL_CALL Close() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &Template) override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
css::uno::Type const & get()
static uno::Any getWorkbook(const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< sheet::XSpreadsheetDocument > &xDoc, const uno::Reference< XHelperInterface > &xParent)
virtual css::uno::Any SAL_CALL Open(const OUString &Filename, const css::uno::Any &UpdateLinks, const css::uno::Any &ReadOnly, const css::uno::Any &Format, const css::uno::Any &Password, const css::uno::Any &WriteResPassword, const css::uno::Any &IgnoreReadOnlyRecommended, const css::uno::Any &Origin, const css::uno::Any &Delimiter, const css::uno::Any &Editable, const css::uno::Any &Notify, const css::uno::Any &Converter, const css::uno::Any &AddToMru) override
uno::Reference< XHelperInterface > getVBADocument(const uno::Reference< frame::XModel > &xModel)
INetProtocol GetProtocol() const
#define SC_TEXT_CSV_FILTER_NAME
OUString getFileFilterType(const OUString &rString)
bool SetURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Reference< XModel > xModel
static bool isSpreadSheetFile(const OUString &rString)
cppu::ImplInheritanceHelper< VbaDocumentsBase, ov::excel::XWorkbooks > ScVbaWorkbooks_BASE
static bool isTextFile(std::u16string_view rString)