/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
ScVbaWorkbooks::ScVbaWorkbooks( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaWorkbooks_BASE( xParent, xContext, VbaDocumentsBase::EXCEL_DOCUMENT )
{
} // XEnumerationAccess
uno::Type
ScVbaWorkbooks::getElementType()
{ return cppu::UnoType<excel::XWorkbook>::get();
}
uno::Reference< container::XEnumeration >
ScVbaWorkbooks::createEnumeration()
{ // #FIXME it's possible the WorkBookEnumImpl here doesn't reflect // the state of this object ( although it should ) would be // safer to create an enumeration based on this objects state // rather than one effectively based of the desktop component
uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); returnnew WorkBookEnumImpl( mxParent, mxContext, xEnumerationAccess->createEnumeration() );
}
bool
ScVbaWorkbooks::isTextFile( std::u16string_view sType )
{ // will return true if the file is // a) a variant of a text file // b) a csv file // c) unknown // returning true basically means treat this like a csv file return sType == u"generic_Text" || sType.empty();
}
bool
ScVbaWorkbooks::isSpreadSheetFile( std::u16string_view sType )
{ // include calc_QPro etc. ? ( not for the moment anyway ) return o3tl::starts_with( sType, u"calc_MS" )
|| o3tl::starts_with( sType, u"MS Excel" )
|| o3tl::starts_with( sType, u"calc8" )
|| o3tl::starts_with( sType, u"calc_StarOffice" );
}
// #TODO# #FIXME# can any of the unused params below be used?
uno::Any SAL_CALL
ScVbaWorkbooks::Open( const OUString& rFileName, const uno::Any& /*UpdateLinks*/, const uno::Any& ReadOnly, const uno::Any& Format, const uno::Any& /*Password*/, const uno::Any& /*WriteResPassword*/, const uno::Any& /*IgnoreReadOnlyRecommended*/, const uno::Any& /*Origin*/, const uno::Any& Delimiter, const uno::Any& /*Editable*/, const uno::Any& /*Notify*/, const uno::Any& /*Converter*/, const uno::Any& /*AddToMru*/ )
{ // we need to detect if this is a URL, if not then assume it's a file path
OUString aURL;
INetURLObject aObj;
aObj.SetURL( rFileName ); bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid; if ( bIsURL )
aURL = rFileName; else
osl::FileBase::getFileURLFromSystemPath( rFileName, aURL );
uno::Sequence< beans::PropertyValue > sProps;
OUString sType = getFileFilterType( aURL ); // A text file means it needs to be processed as a csv file if ( isTextFile( sType ) )
{ // Values for format // 1 Tabs // 2 Commas // 3 Spaces // 4 Semicolons // 5 Nothing // 6 Custom character (see the Delimiter argument // no format means use the current delimiter
sal_Int16 const delims[] { 0 /*default not used*/, 9/*tab*/, 44/*comma*/, 32/*space*/, 59/*semicolon*/ };
if ( Format.hasValue() )
{
Format >>= nFormat; // val of nFormat overwritten if extracted // validate param if ( nFormat < 1 || nFormat > 6 ) throw uno::RuntimeException(u"Illegal value for Format"_ustr );
}
sal_Int16 nDelim = getCurrentDelim();
if ( nFormat > 0 && nFormat < CUSTOM_CHAR )
{
nDelim = delims[ nFormat ];
} elseif ( nFormat > CUSTOM_CHAR )
{ // Need to check Delimiter param if ( !Delimiter.hasValue() ) throw uno::RuntimeException(u"Expected value for Delimiter"_ustr );
OUString sStr;
Delimiter >>= sStr; if ( sStr.isEmpty() ) throw uno::RuntimeException(u"Incorrect value for Delimiter"_ustr );
nDelim = sStr[0];
}
getCurrentDelim() = nDelim; //set new current
sFormat = OUString::number( nDelim ) + ",34,0,1";
sProps = { comphelper::makePropertyValue(u"FilterOptions"_ustr, sFormat),
comphelper::makePropertyValue(u"FilterName"_ustr, SC_TEXT_CSV_FILTER_NAME), // Ensure WORKAROUND_CSV_TXT_BUG_i60158 gets called in typedetection.cxx so // csv is forced for deep detected 'writerxxx' types
comphelper::makePropertyValue(
u"DocumentService"_ustr, u"com.sun.star.sheet.SpreadsheetDocument"_ustr) };
} elseif ( !isSpreadSheetFile( sType ) ) throw uno::RuntimeException(u"Bad Format"_ustr );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.