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>
35#include <osl/file.hxx>
44getWorkbook(
const uno::Reference< uno::XComponentContext >& xContext,
45 const uno::Reference< sheet::XSpreadsheetDocument > &xDoc,
46 const uno::Reference< XHelperInterface >& xParent )
49 uno::Reference< frame::XModel >
xModel( xDoc, uno::UNO_QUERY );
60 return uno::Any( uno::Reference< excel::XWorkbook > (pWb) );
69 WorkBookEnumImpl(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ) {}
71 virtual uno::Any SAL_CALL nextElement( )
override
73 uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
90uno::Reference< container::XEnumeration >
97 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
98 return new WorkBookEnumImpl(
mxParent,
mxContext, xEnumerationAccess->createEnumeration() );
104 uno::Reference< sheet::XSpreadsheetDocument > xDoc( aSource, uno::UNO_QUERY_THROW );
111 uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc;
112 sal_Int32 nWorkbookType = 0;
113 OUString aTemplateFileName;
119 xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW );
121 uno::Reference< sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_SET_THROW );
122 uno::Reference< container::XIndexAccess > xSheetsIA( xSheets, uno::UNO_QUERY_THROW );
123 while( xSheetsIA->getCount() > 1 )
125 uno::Reference< container::XNamed > xSheetName( xSheetsIA->getByIndex( xSheetsIA->getCount() - 1 ), uno::UNO_QUERY_THROW );
126 xSheets->removeByName( xSheetName->getName() );
129 else if(
Template >>= aTemplateFileName )
132 xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW );
137 xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW );
142 throw uno::RuntimeException();
147 if (!xSpreadDoc.is())
151 uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY );
186 uno::Reference< document::XTypeDetection > xTypeDetect(
mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.TypeDetection",
mxContext), uno::UNO_QUERY_THROW );
188 OUString
sType = xTypeDetect->queryTypeByDescriptor( aMediaDesc,
true );
194ScVbaWorkbooks::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& )
200 bool bIsURL = aObj.
GetProtocol() != INetProtocol::NotValid;
204 osl::FileBase::getFileURLFromSystemPath( rFileName,
aURL );
206 uno::Sequence< beans::PropertyValue > sProps;
220 sal_Int16
const delims[] { 0 , 9, 44, 32, 59 };
223 sal_Int16 nFormat = 0;
229 if ( nFormat < 1 || nFormat > 6 )
230 throw uno::RuntimeException(
"Illegal value for Format" );
237 nDelim = delims[ nFormat ];
243 throw uno::RuntimeException(
"Expected value for Delimiter" );
246 if ( sStr.isEmpty() )
247 throw uno::RuntimeException(
"Incorrect value for Delimiter" );
255 sFormat = OUString::number( nDelim ) +
",34,0,1";
262 "DocumentService", OUString(
"com.sun.star.sheet.SpreadsheetDocument")) };
265 throw uno::RuntimeException(
"Bad Format" );
267 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( openDocument( rFileName,
ReadOnly, sProps ), uno::UNO_QUERY_THROW );
269 uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY );
278 return "ScVbaWorkbooks";
281css::uno::Sequence<OUString>
284 static uno::Sequence< OUString >
const sNames
286 "ooo.vba.excel.Workbooks"
unotools::WeakReference< AnimationNode > mxParent
INetProtocol GetProtocol() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
ScVbaWorkbooks(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Type SAL_CALL getElementType() override
static bool isSpreadSheetFile(std::u16string_view rString)
virtual void SAL_CALL Close() override
virtual OUString getServiceImplName() override
static bool isTextFile(std::u16string_view rString)
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
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
static sal_Int16 & getCurrentDelim()
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &Template) override
virtual css::uno::Sequence< OUString > getServiceNames() override
OUString getFileFilterType(const OUString &rString)
css::uno::Type const & get()
constexpr OUStringLiteral SC_TEXT_CSV_FILTER_NAME
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
void setUpDocumentModules(const uno::Reference< sheet::XSpreadsheetDocument > &xDoc)
VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument(const css::uno::Reference< css::frame::XModel > &xModel)
Reference< XModel > xModel
static uno::Any getWorkbook(const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< sheet::XSpreadsheetDocument > &xDoc, const uno::Reference< XHelperInterface > &xParent)
const sal_Int16 CUSTOM_CHAR
cppu::ImplInheritanceHelper< VbaDocumentsBase, ov::excel::XWorkbooks > ScVbaWorkbooks_BASE