26#include <com/sun/star/container/XIndexAccess.hpp>
27#include <com/sun/star/container/XNamed.hpp>
28#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
29#include <osl/diagnose.h>
30#include <rtl/ustrbuf.hxx>
34#include <oox/token/namespaces.hxx>
35#include <oox/token/tokens.hxx>
36#include <document.hxx>
50 mnState( XML_visible )
76 static const sal_Int32 spnStates[] = { XML_visible, XML_hidden, XML_veryHidden };
87 return aIndexName.first;
104 return pSheetInfo ? pSheetInfo->
maRelId : OUString();
116 return pSheetInfo ? pSheetInfo->
maCalcName : OUString();
121 if( !sSheetNameRef.startsWith(
"#") )
124 sal_Int32 nSepPos = sSheetNameRef.lastIndexOf(
'!' );
132 if (nSepPos < sSheetNameRef.getLength() - 1)
137 sSheetNameRef = sSheetNameRef.replaceAt( nSepPos, 1, rtl::OUStringChar(
'.' ) );
140 OUString aSheetName = sSheetNameRef.copy( 1, nSepPos - 1 );
142 if( !aCalcName.isEmpty() )
143 sSheetNameRef = sSheetNameRef.replaceAt( 1, nSepPos - 1, aCalcName );
156 bool bIsQuoted = pSheetInfo->maName != rWorksheetName;
157 return bIsQuoted ? pSheetInfo->maCalcQuotedName : pSheetInfo->maCalcName;
166OUString lclQuoteName( std::u16string_view rName )
168 OUStringBuffer
aBuffer( rName );
170 for( sal_Int32 nPos =
aBuffer.getLength() - 1; nPos >= 0; --nPos )
171 if( aBuffer[nPos] ==
'\'' )
174 return aBuffer.insert( 0,
'\'' ).append(
'\'' ).makeStringAndClear();
181 maCalcName( rCalcName ),
182 maCalcQuotedName( lclQuoteName( rCalcName ) ),
183 mnCalcSheet( nCalcSheet )
192 Reference< XSpreadsheets > xSheets(
getDocument()->getSheets(), UNO_SET_THROW );
193 Reference< XIndexAccess > xSheetsIA( xSheets, UNO_QUERY_THROW );
194 sal_Int16 nCalcSheet = -1;
195 OUString aSheetName = rPreferredName.isEmpty() ?
ScResId(STR_TABLE_DEF) : rPreferredName;
196 if( nSheetPos < xSheetsIA->getCount() )
198 nCalcSheet =
static_cast< sal_Int16
>( nSheetPos );
200 Reference< XNamed > xSheetName( xSheetsIA->getByIndex( nSheetPos ), UNO_QUERY_THROW );
201 if( xSheetName->getName() != aSheetName )
204 xSheetName->setName( aSheetName );
209 nCalcSheet =
static_cast< sal_Int16
>( xSheetsIA->getCount() );
212 xSheets->insertNewByName( aSheetName, nCalcSheet );
220 OSL_FAIL(
"WorksheetBuffer::createSheet - cannot insert or rename worksheet" );
227 sal_Int32 nWorksheet =
static_cast< sal_Int32
>(
maSheetInfos.size() );
229 auto xSheetInfo = std::make_shared<SheetInfo>( rModel, aIndexName.first, aIndexName.second );
242 if ( aSheetInfo->mnCalcSheet == nActiveSheet)
243 rDoc.
SetVisible( aSheetInfo->mnCalcSheet,
true );
245 rDoc.
SetVisible( aSheetInfo->mnCalcSheet, aSheetInfo->mnState == XML_visible );
Accessor class to ScDocument.
SCTAB getSheetCount() const
SC_DLLPUBLIC void SetVisible(SCTAB nTab, bool bVisible)
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
std::optional< OUString > getXString(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
static OUString getUnusedName(const css::uno::Reference< css::container::XNameAccess > &rxNameAccess, const OUString &rSuggestedName, sal_Unicode cSeparator)
Helper class to provide access to global workbook data.
ScDocument & getScDocument()
ScDocumentImport & getDocImport()
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
void convertSheetNameRef(OUString &sSheetNameRef) const
Converts sSheetNameRef (e.g.
RefVector< SheetInfo > maSheetInfos
OUString getWorksheetRelId(sal_Int32 nWorksheet) const
Returns the OOXML relation identifier of the specified worksheet.
OUString getCalcSheetName(sal_Int32 nWorksheet) const
Returns the finalized name of the specified worksheet.
IndexNamePair createSheet(const OUString &rPreferredName, sal_Int32 nSheetPos)
Creates a new sheet in the Calc document.
sal_Int32 getWorksheetCount() const
Returns the number of original sheets contained in the workbook.
sal_Int16 getCalcSheetIndex(sal_Int32 nWorksheet) const
Returns the Calc index of the specified worksheet.
::std::pair< sal_Int16, OUString > IndexNamePair
void importSheet(const AttributeList &rAttribs)
Imports the attributes of a sheet element.
RefMap< OUString, SheetInfo, IgnoreCaseCompare > maSheetInfosByName
sal_Int16 insertEmptySheet(const OUString &rPreferredName)
Inserts a new empty sheet into the document.
sal_Int32 getAllSheetCount() const
Returns the number of all sheets, workbook + dummy ones (pivot table cache records )
WorksheetBuffer(const WorkbookHelper &rHelper)
void finalizeImport(sal_Int16 nActiveSheet)
void insertSheet(const SheetInfoModel &rModel)
Creates a new sheet in the Calc document and inserts the related SheetInfo.
#define STATIC_ARRAY_SELECT(array, index, def)
OUString ScResId(TranslateId aId)
Contains data from the 'sheet' element describing a sheet in the workbook.
SheetInfoModel()
Visibility state.
OUString maName
Relation identifier for the sheet substream.
sal_Int32 mnState
Sheet identifier.
sal_Int32 mnSheetId
Original name of the sheet.
SheetInfo(const SheetInfoModel &rModel, sal_Int16 nCalcSheet, const OUString &rCalcName)
std::unique_ptr< char[]> aBuffer