28 #include <document.hxx>
46 void lclFillAddress(
ScAddress& rScPos, sal_uInt16 nXclCol, sal_uInt32 nXclRow,
SCTAB nScTab )
48 rScPos.
SetCol( static_cast< SCCOL >( nXclCol ) );
49 rScPos.
SetRow( static_cast< SCROW >( nXclRow ) );
66 bool bValid = bValidCol && bValidRow;
67 if( !bValid && bWarn )
72 static_cast< SCCOL >( rXclPos.
mnCol ), static_cast< SCROW >( rXclPos.
mnRow ), 0 ),
maMaxPos );
82 lclFillAddress( rScPos, rXclPos.
mnCol, rXclPos.
mnRow, nScTab );
115 nXclCol2 = ::std::min( nXclCol2,
mnMaxCol );
116 nXclRow2 = ::std::min( nXclRow2,
mnMaxRow );
118 lclFillAddress( rScRange.
aEnd, nXclCol2, nXclRow2, nScTab2 );
129 for(
const auto& rXclRange : rXclRanges )
132 if(
ConvertRange( aScRange, rXclRange, nScTab, nScTab, bWarn ) )
141 std::unique_ptr<EditTextObject> lclCreateTextObject(
const XclImpRoot& rRoot,
144 std::unique_ptr<EditTextObject> pTextObj;
148 bool bFirstEscaped = pFirstFont && pFirstFont->
HasEscapement();
150 if( rString.
IsRich() || bFirstEscaped )
164 XclFormatRunVec::const_iterator aIt = rFormats.begin();
165 XclFormatRunVec::const_iterator aEnd = rFormats.end();
172 sal_Int32 nLen = rString.
GetText().getLength();
173 for( sal_Int32 nChar = 0; nChar < nLen; ++nChar )
176 if( nChar >= aNextRun.
mnChar )
182 aItemSet.ClearItem();
197 if( rString.
GetText()[ nChar ] ==
'\n' )
227 if (rString.
GetText().isEmpty())
230 ::std::unique_ptr< EditTextObject > pTextObj( lclCreateTextObject( rRoot, rString,
XclFontItemType::Editeng, nXFIndex ) );
239 if (aStr.indexOf(
'\n') != -1 || aStr.indexOf(
'\r') != -1)
286 OUStringBuffer aReadFont;
287 OUStringBuffer aReadStyle;
288 sal_uInt16 nReadHeight = 0;
292 enum XclHFParserState
302 const sal_Unicode* pNull = pChar + rHFString.getLength();
349 if( (pNull - pChar >= 2) && (*(pChar + 1) ==
'&') && (*(pChar + 2) ==
'F') )
385 aReadFont.setLength(0);
386 aReadStyle.setLength(0);
390 if( (
'0' <= *pChar) && (*pChar <=
'9') )
392 nReadHeight = *pChar -
'0';
409 eState = xlPSFontStyle;
412 aReadFont.append(*pChar);
425 if( !aReadFont.isEmpty() )
431 aReadStyle.append(*pChar);
440 if( (
'0' <= *pChar) && (*pChar <=
'9') )
442 if( nReadHeight != 0xFFFF )
445 nReadHeight += (*pChar -
'0');
446 if( nReadHeight > 1600 )
447 nReadHeight = 0xFFFF;
452 if( (nReadHeight != 0) && (nReadHeight != 0xFFFF) )
482 rItemSet.
Put( aHFItem );
495 sal_uInt16 nMaxHt =
maInfos[ ePortion ].mnMaxLineHt;
496 return (nMaxHt == 0) ?
mxFontData->mnHeight : nMaxHt;
501 sal_uInt16& rnMaxHt =
maInfos[ ePortion ].mnMaxLineHt;
502 rnMaxHt = ::std::max( rnMaxHt,
mxFontData->mnHeight );
540 OUString sString(
maCurrText.makeStringAndClear());
590 void lclAppendUrlChar( OUString& rUrl,
sal_Unicode cChar )
595 case '#': rUrl +=
"%23";
break;
596 case '%': rUrl +=
"%25";
break;
597 default: rUrl += OUStringChar( cChar );
604 OUString& rUrl, OUString& rTabName,
bool& rbSameWb,
605 const XclImpRoot& rRoot,
const OUString& rEncodedUrl )
614 } eState = xlUrlInit;
616 bool bEncoded =
true;
621 if (!aDosBase.isEmpty() && aDosBase.match(
":\\", 1))
622 cCurrDrive = aDosBase[0];
642 eState = xlUrlSheetName;
646 eState = xlUrlFileName;
650 lclAppendUrlChar( rUrl, *pChar );
671 lclAppendUrlChar( rUrl, *pChar );
676 rUrl +=
"<NULL-DRIVE!>";
682 lclAppendUrlChar( rUrl, cCurrDrive );
702 sal_Int32 nLen = *++pChar;
703 for( sal_Int32 nChar = 0; (nChar < nLen) && *(pChar + 1); ++nChar )
704 lclAppendUrlChar( rUrl, *++pChar );
710 eState = xlUrlFileName;
713 lclAppendUrlChar( rUrl, *pChar );
724 case ']': eState = xlUrlSheetName;
break;
725 default: lclAppendUrlChar( rUrl, *pChar );
733 rTabName += OUStringChar( *pChar );
739 lclAppendUrlChar( rUrl, *pChar );
748 OUString& rUrl,
bool& rbSameWb,
const XclImpRoot& rRoot,
const OUString& rEncodedUrl )
752 DecodeUrl( aUrl, aTabName, rbSameWb, rRoot, rEncodedUrl );
754 OSL_ENSURE( aTabName.isEmpty(),
"XclImpUrlHelper::DecodeUrl - sheet name ignored" );
760 if( (nPos > 0) && (nPos + 1 < rEncUrl.getLength()) )
762 rApplic = rEncUrl.copy( 0, nPos );
763 rTopic = rEncUrl.copy( nPos + 1 );
801 OSL_FAIL(
"XclImpCachedValue::XclImpCachedValue - unknown data type" );
837 const size_t nMinRecordSize = 1;
841 SAL_WARN(
"sc",
"Parsing error: " << nMaxRows <<
842 " max possible rows, but " <<
mnScRows <<
" claimed, truncating");
848 maValueList.push_back( std::make_unique<XclImpCachedValue>( rStrm ) );
862 XclImpValueList::const_iterator itValue =
maValueList.begin();
867 switch( (*itValue)->GetType() )
871 xScMatrix->PutEmpty( nScCol, nScRow );
874 xScMatrix->PutDouble( (*itValue)->GetValue(), nScCol, nScRow );
877 xScMatrix->PutString(rPool.
intern((*itValue)->GetString()), nScCol, nScRow);
880 xScMatrix->PutBoolean( (*itValue)->GetBool(), nScCol, nScRow );
883 xScMatrix->PutError( (*itValue)->GetScError(), nScCol, nScRow );
886 OSL_FAIL(
"XclImpCachedMatrix::CreateScMatrix - unknown value type" );
887 xScMatrix->PutEmpty( nScCol, nScRow );
ScAddress maMaxPos
Tracer for invalid addresses.
virtual ~XclImpCachedValue()
Matrix data type that can store values of mixed types.
const sal_Unicode EXC_URLSTART_SELF
Encoded URL.
Use edit engine Which-IDs (EE_CHAR_*).
sal_uInt16 mnMaxLineHt
Height of previous lines in twips.
const sal_Unicode EXC_URL_PARENTDIR
Directory name delimiter.
static std::unique_ptr< EditTextObject > CreateTextObject(const XclImpRoot &rRoot, const XclImpString &rString)
Returns a new edit engine text object.
static bool DecodeLink(OUString &rApplic, OUString &rTopic, const OUString &rEncUrl)
Decodes the passed URL to OLE or DDE link components.
const XclImpFont * GetFont(sal_uInt16 nXFIndex) const
Returns the Excel font used in the specified XF record.
SharedString intern(const OUString &rStr)
void InsertLineBreak()
Inserts a line break and adjusts the current selection object.
Contains all XF records occurred in the file.
SCSIZE mnScCols
List of cached cell values.
XclImpHFPortionInfo()
Maximum font height for the current text line.
Stores all data of an Excel font and provides import of FONT records.
const SfxItemSet & GetEmptyItemSet() const
XclFontDataPtr mxFontData
Current text to insert into edit engine.
void SetAttribs()
Sets the font attributes at the current selection.
sal_uInt16 mnMaxCol
Default maximum position.
void ResetFontData()
Resets font data to application default font.
void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)
sal_uInt16 GetMaxLineHeight(XclImpHFPortion ePortion) const
Returns the maximum line height of the specified portion.
This struct helps reading and writing Excel fonts.
sal_uInt8 mnType
Boolean value or Excel error code.
void ConvertRangeList(ScRangeList &rScRanges, const XclRangeList &rXclRanges, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell range list to a Calc cell range list.
const XclFormatRunVec & GetFormats() const
Returns the formatting run vector.
Use Calc Which-IDs (ATTR_*).
bool IsRich() const
Returns true, if the string contains formatting information.
const sal_uInt8 EXC_CACHEDVAL_ERROR
const sal_Unicode EXC_URLSTART_ENCODED
Accessor class to ScDocument.
bool HasEscapement() const
Returns true, if the font contains superscript or subscript.
static void SetToDocument(ScDocumentImport &rDoc, const ScAddress &rPos, const XclImpRoot &rRoot, const XclImpString &rString, sal_uInt16 nXFIndex)
virtual ~XclImpHFConverter() override
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
void FillToItemSet(SfxItemSet &rItemSet, XclFontItemType eType, sal_uInt16 nFontIdx, bool bSkipPoolDefs=false) const
Fills all font properties from a FONT record to the item set.
void setEditCell(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
void SetNewPortion(XclImpHFPortion eNew)
Changes current header/footer portion to eNew.
void SetLeftArea(const EditTextObject &rNew)
const sal_uInt16 EXC_FONTESC_SUB
sal_uInt32 mnMaxRow
Maximum column index, as 16-bit value.
const sal_Unicode EXC_DDE_DELIM
Sheet name starts here (BIFF4).
const sal_uInt16 EXC_FONT_APP
void SetText(const OUString &rStr)
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
void SetCenterArea(const EditTextObject &rNew)
ScMatrixRef CreateScMatrix(svl::SharedStringPool &rPool) const
Creates a new ScMatrix object and fills it with the contained values.
void UpdateMaxLineHeight(XclImpHFPortion ePortion)
Updates the maximum line height of the specified portion, using the current font size.
ExcelToSc & GetOldFmlaConverter() const
Returns the old formula converter.
void push_back(const ScRange &rRange)
void ParseString(const OUString &rHFString)
Parses the passed string and creates three new edit engine text objects.
const sal_uInt16 EXC_FONTESC_NONE
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
::std::vector< XclFormatRun > XclFormatRunVec
A vector with all formatting runs for a rich-string.
XclImpXFBuffer & GetXFBuffer() const
Returns the cell formatting attributes buffer.
const XclFontData & GetFontData() const
Returns read-only access to font data.
ScHeaderEditEngine & GetHFEditEngine() const
Returns the edit engine for import/export of headers/footers.
const sal_Unicode EXC_URLSTART_SELFENCODED
Reference to own workbook.
double mfValue
Cached value is a string.
SCSIZE mnScRows
Number of cached columns.
XclFontItemType
Enumerates different types of Which-IDs for font items.
ESelection maSel
Edit engine text object.
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
ESelection & GetCurrSel()
Returns the current selection.
ScTokenArrayPtr mxTokArr
Cached value is a double.
bool ConvertAddress(ScAddress &rScPos, const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell address to a Calc cell address.
bool mbColTrunc
Maximum row index.
void UpdateCurrMaxLineHeight()
Updates the current maximum line height, using the current font size.
OUStringBuffer maCurrText
Edit engine text objects for all portions.
const sal_Unicode EXC_URL_DOSDRIVE
Reference to own workbook (BIFF5/BIFF7).
A 2D cell range address list with Excel column and row indexes.
std::unique_ptr< EditTextObject > CreateTextObject()
XclImpHFPortion meCurrObj
Font data of current text.
const sal_uInt8 EXC_CACHEDVAL_BOOL
bool CheckAddress(const XclAddress &rXclPos, bool bWarn)
Checks if the passed Excel cell address is valid.
void SetRightArea(const EditTextObject &rNew)
const sal_Unicode EXC_URL_SUBDIR
Root directory of current drive.
std::vector< XclImpHFPortionInfo > maInfos
The header/footer edit engine.
A 2D cell address struct with Excel column and row indexes.
XclImpCachedMatrix(XclImpStream &rStrm)
sal_uInt8 mnBoolErr
Cached value is a formula or error code or Boolean.
const sal_uInt8 EXC_FONTUNDERL_SINGLE
const sal_uInt8 EXC_CACHEDVAL_EMPTY
ScAddress CreateValidAddress(const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Returns a valid cell address by moving it into allowed dimensions.
std::unique_ptr< ScTokenArray > GetBoolErr(XclBoolError)
const sal_uInt8 EXC_CACHEDVAL_DOUBLE
const sal_uInt16 EXC_FONTESC_SUPER
const XclImpRoot & GetRoot() const
Returns the filter root data.
std::size_t GetRecLeft()
Returns remaining data size of the whole record without record headers.
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
OUString ReadUniString(sal_uInt16 nChars, sal_uInt8 nFlags)
Reads ext.
const sal_Unicode EXC_URL_RAW
Parent directory.
ScEditEngineDefaulter & GetEditEngine() const
Returns the edit engine for import/export of rich strings etc.
const OUString & GetText() const
Returns the pure text data of the string.
XclImpHFPortionInfo::EditTextObjectRef & GetCurrObj()
Returns the current edit engine text object.
const sal_uInt8 EXC_CACHEDVAL_STRING
void Ignore(std::size_t nBytes)
Seeks forward inside the current record.
XclImpCachedValue(const XclImpCachedValue &)=delete
delete copy constructor
XclImpHFPortionInfo & GetCurrInfo()
Returns the current edit engine text object.
void setStringCell(const ScAddress &rPos, const OUString &rStr)
XclImpFontBuffer & GetFontBuffer() const
Returns the font buffer.
XclImpHFPortion
Enumerates the supported header/footer portions.
void FillToItemSet(SfxItemSet &rItemSet, sal_uInt16 nWhichId) const
Creates a ScPageHFItem and inserts it into the passed item set.
void QuickSetAttribs(const SfxItemSet &rSet, const ESelection &rSel)
Stores the data of all fonts occurred in an Excel file.
sal_uInt16 GetFontIndex(sal_uInt16 nXFIndex) const
Returns the index to the Excel font used in the specified XF record.
bool mbRowTrunc
Flag for "columns truncated" warning box.
const sal_uInt8 EXC_FONTUNDERL_NONE
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Base class for import/export address converters.
void InsertField(const SvxFieldItem &rFieldItem)
Inserts the passed text field and adjusts the current selection object.
bool ConvertRange(ScRange &rScRange, const XclRange &rXclRange, SCTAB nScTab1, SCTAB nScTab2, bool bWarn)
Converts the passed Excel cell range to a Calc cell range.
void TraceInvalidAddress(const ScAddress &rPos, const ScAddress &rMaxPos)
const sal_Unicode EXC_URL_DRIVEROOT
DOS drive letter or UNC server name.
#define SAL_WARN(area, stream)
const OUString & GetBasePath() const
Returns the base path of the imported/exported file.
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
XclImpAddressConverter(const XclImpRoot &rRoot)
void QuickInsertText(const OUString &rText, const ESelection &rSel)
sal_Int32 GetTotalHeight() const
Returns the total height of the converted header or footer in twips.
XclImpValueList maValueList
void CreateCurrObject()
Creates the edit engine text object of current portion from edit engine.
This class is used to import record oriented streams.
XclImpHFConverter(const XclImpHFConverter &)=delete
delete copy constructor
const sal_uInt8 EXC_FONTUNDERL_DOUBLE
Access to global data from other classes.
FormulaError GetScError() const
Returns the cached Calc error code, if this value has Error type, else 0.
This class represents an unformatted or formatted string and provides importing from stream...
sal_Int32 mnHeight
Edit engine selection.
SC_DLLPUBLIC ScFieldEditEngine & GetEditEngine()
void InsertText()
Inserts maCurrText into edit engine and adjusts the current selection object.
A 2D cell range address struct with Excel column and row indexes.
static void DecodeUrl(OUString &rUrl, OUString &rTabName, bool &rbSameWb, const XclImpRoot &rRoot, const OUString &rEncodedUrl)
Decodes an encoded external document URL with optional sheet name.