29#include <svx/svxids.hrc>
39#include <document.hxx>
48#include <unonames.hxx>
85 ImportTyp( rImpData.mrDoc, rImpData.meTextEnc ),
87 maStrm(
rStrm, GetRoot() ),
89 maScOleSize(
ScAddress::INITIALIZE_INVALID ),
90 pColOutlineBuff(nullptr),
91 pRowOutlineBuff(nullptr),
93 mpLastFormula(nullptr),
98 mbBiff2HasXfsValid(false),
99 mbFuzzing(
utl::ConfigManager::IsFuzzing())
147 std::pair<LastFormulaMapType::iterator, bool> r =
152 it->second.mnCol = nCol;
153 it->second.mnRow = nRow;
154 it->second.mpCell = pCell;
155 it->second.mfValue = fVal;
156 it->second.mnXF = nXF;
163 sal_uInt16 nRecommendReadOnly, nPasswordHash;
167 if((nRecommendReadOnly == 0) && (nPasswordHash == 0))
174 if( nRecommendReadOnly != 0 )
175 pShell->SetLoadReadonly(
true );
176 if( nPasswordHash != 0 )
177 pShell->SetModifyPasswordHash( nPasswordHash );
183 sal_uInt16 nXFIdx = 0;
204 nXFIdx = ::extract_value< sal_uInt16 >( nFlags1, 0, 6 );
229 if( (aXclUsedArea.GetColCount() > 1) && (aXclUsedArea.GetRowCount() > 1) )
233 --aXclUsedArea.maLast.mnRow;
243 sal_uInt32 nXclRow1 = 0, nXclRow2 = 0;
248 if( (nXclRow1 < nXclRow2) && (aXclUsedArea.
GetColCount() > 1) &&
255 aXclUsedArea.
maFirst.
mnRow =
static_cast< sal_uInt16
>( nXclRow1 );
396 sal_uInt16 nRow, nRowHeight;
418 sal_uInt8 nLevel = ::extract_value< sal_uInt8 >( nGrbit, 0, 3 );
431 if( nSubType == 0x0020 )
433 else if( nSubType == 0x0040 )
456 OUString aUrl, aTabName;
473 sal_uInt16 nColMic, nColMac;
479 OSL_ENSURE(
aIn.
GetRecLeft() ==
static_cast<std::size_t
>(nColMac - nColMic) * 3 + 2,
480 "ImportExcel::Columndefault - wrong record size" );
485 nColMac =
static_cast<sal_uInt16
>(
rD.
MaxCol());
487 for( sal_uInt16 nCol = nColMic ; nCol <= nColMac ; nCol++ )
516 std::unique_ptr<ScTokenArray> pResult;
526 SAL_WARN_IF(!pResult,
"sc",
"*ImportExcel::Array25(): ScTokenArray is NULL!");
562 if( ( nOpt & 0x0001 ) || ( ( nOpt & 0xFFFE ) == 0x0000 ) )
566 else if( nOpt & 0x0010 )
579 sal_uInt16 nColWidth;
595 sal_uInt16 nDefHeight;
597 nDefHeight &= 0x7FFF;
642 SAL_WARN(
"sc",
"*ImportExcel::DefColWidth(): pColRowBuff is NULL!");
656 sal_uInt16 nColFirst, nColLast, nColWidth, nXF;
669 nColLast =
static_cast<sal_uInt16
>(
rD.
MaxCol());
673 sal_uInt8 nLevel = ::extract_value< sal_uInt8 >( nOpt, 8, 3 );
697 sal_uInt16 nGrbit = 0;
712 OSL_ENSURE( !
rD.
HasTable( nScTab ),
"ImportExcel::Boundsheet - sheet exists already" );
716 if( ( nGrbit & 0x0001 ) || ( nGrbit & 0x0002 ) )
730 sal_uInt16 nUICountry, nDocCountry;
740 eLanguage = ::msfilter::ConvertCountryToLanguage(
static_cast< ::
msfilter::CountryId >( nUICountry ) );
795 SAL_WARN(
"sc",
"*ImportExcel::Standardwidth(): pColRowBuff is NULL!");
823 std::unique_ptr<ScTokenArray> pResult;
836 SAL_WARN(
"sc",
"+ImportExcel::Shrfmla(): ScTokenArray is NULL!");
981 if( rAddrConv.
ConvertRange( aScRange, aXclRange, nScTab, nScTab,
true ) )
984 if (!bTooSlowForFuzzing)
1003 sal_uInt16 nRow, nRowHeight, nGrbit, nXF;
1016 nRowHeight = nRowHeight & 0x7FFF;
1023 sal_uInt8 nLevel = ::extract_value< sal_uInt8 >( nGrbit, 0, 3 );
1033 sal_uInt16 nSubType;
1038 OSL_ENSURE( nSubType != 0x0100,
"*ImportExcel::Bof3(): Biff3 as Workbook?!" );
1039 if( nSubType == 0x0100 )
1041 else if( nSubType == 0x0020 )
1043 else if( nSubType == 0x0040 )
1051 sal_uInt16 nFirstRow, nLastRow, nFormLen;
1061 std::unique_ptr<ScTokenArray> pResult;
1071 SAL_WARN_IF(!pResult,
"sc",
"+ImportExcel::Array34(): ScTokenArray is NULL!");
1084 sal_uInt16 nFlags, nDefHeight;
1090 SAL_WARN(
"sc",
"*ImportExcel::Defrowheight345(): pColRowBuff is NULL!");
1112 nLastRow = std::min<sal_uInt16>(nLastRow,
MAXROW_30 / 2);
1117 if( nFirstCol && nFirstRow )
1121 sal_uInt16 nCol = nFirstCol - 1;
1122 sal_uInt16 nRow = nFirstRow - 1;
1124 switch (aTabOpParam.
meMode)
1128 static_cast<SCCOL>(nFirstCol),
1129 static_cast<SCROW>(nFirstRow - 1), nTab,
false,
1132 static_cast<SCCOL>(nLastCol),
1133 static_cast<SCROW>(nFirstRow - 1), nTab,
false,
1136 static_cast<SCROW>(nInpRow), nTab,
false,
false,
1142 static_cast<SCCOL>(nFirstCol - 1),
1143 static_cast<SCROW>(nFirstRow), nTab,
false,
false,
1146 static_cast<SCCOL>(nFirstCol - 1),
1147 static_cast<SCROW>(nLastRow), nTab,
false,
false,
1150 static_cast<SCROW>(nInpRow), nTab,
false,
false,
1156 static_cast<SCCOL>(nFirstCol - 1),
1157 static_cast<SCROW>(nFirstRow - 1), nTab,
false,
1160 static_cast<SCROW>(nInpRow), nTab,
false,
false,
1163 static_cast<SCROW>(nInpRow2), nTab,
false,
false,
1169 ScRange aTabOpRange(nCol, nRow, nTab, nLastCol, nLastRow, nTab);
1182 sal_uInt16 nSubType;
1187 if( nSubType == 0x0100 )
1189 else if( nSubType == 0x0020 )
1191 else if( nSubType == 0x0040 )
1200 sal_uInt16 nSubType, nVers;
1209 case 0x0005: eDatei =
Biff5W;
break;
1210 case 0x0006: eDatei =
Biff5V;
break;
1211 case 0x0020: eDatei =
Biff5C;
break;
1212 case 0x0040: eDatei =
Biff5M4;
break;
1214 default: eDatei =
Biff5;
break;
1275 pDocObj->UpdateAllRowHeights();
1288 rxBuffer->Convert();
1320 pDocShell->SetVisArea(
GetDoc().GetMMRect(
1342 for(
SCTAB n = 0 ;
n < nLast ;
n++ )
1366 for(
SCTAB n = 0 ;
n < nLast ;
n++ )
1371 bool bRowVirgin =
true;
1372 bool bColVirgin =
true;
1376 if(
p->aStart.Col() == 0 &&
p->aEnd.Col() ==
rD.
MaxCol() && bRowVirgin )
1382 if(
p->aStart.Row() == 0 &&
p->aEnd.Row() ==
rD.
MaxRow() && bColVirgin )
bool ValidColRow(SCCOL nCol, SCROW nRow, SCCOL nMaxCol, SCROW nMaxRow)
bool ValidRow(SCROW nRow, SCROW nMaxRow)
LastFormulaMapType maLastFormulaCells
std::unique_ptr< ScTokenArray > ErrorToFormula(bool bErrOrVal, sal_uInt8 nError, double &rVal)
sal_uInt16 ReadXFIndex(const ScAddress &rScPos, bool bBiff2)
sal_uInt16 mnLastRecId
Current XF identifier from IXFE record.
XclImpOutlineBuffer * pRowOutlineBuff
bool mbBiff2HasXfsValid
Select XF formatting or direct formatting in BIFF2.
ImportExcel(XclImpRootData &rImpData, SvStream &rStrm)
ScfUInt32Vec maSheetOffsets
std::unique_ptr< XclImpOutlineListBuffer > pOutlineListBuffer
bool mbFuzzing
False = mbBiff2HasXfs is undetermined yet.
std::unique_ptr< ExcelToSc > pFormConv
Visible range if embedded.
virtual void PostDocLoad()
XclImpOutlineBuffer * pColOutlineBuff
std::vector< std::unique_ptr< XclImpOutlineDataBuffer > > XclImpOutlineListBuffer
XclImpColRowSettings * pColRowBuff
LastFormula * mpLastFormula
void SetLastFormula(SCCOL nCol, SCROW nRow, double fVal, sal_uInt16 nXF, ScFormulaCell *pCell)
True if fuzzing filter.
virtual ~ImportExcel() override
ImportTyp(ScDocument &, rtl_TextEncoding eSrc)
void SetFormulaRegexEnabled(bool bVal)
void SetIgnoreCase(bool bVal)
void SetLookUpColRowNames(bool bVal)
void SetFormulaWildcardsEnabled(bool bVal)
void SetDate(sal_uInt16 nD, sal_uInt16 nM, sal_Int16 nY)
Accessor class to ScDocument.
void setMatrixCells(const ScRange &rRange, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGrammar)
void setFormulaCell(const ScAddress &rPos, const OUString &rFormula, formula::FormulaGrammar::Grammar eGrammar, const double *pResult=nullptr)
void setTableOpCells(const ScRange &rRange, const ScTabOpParam &rParam)
void setNumericCell(const ScAddress &rPos, double fVal)
bool ValidRow(SCROW nRow) const
SC_DLLPUBLIC SCCOL MaxCol() const
SC_DLLPUBLIC void SetVisibleTab(SCTAB nTab)
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
SC_DLLPUBLIC void AddPrintRange(SCTAB nTab, const ScRange &rNew)
Adds a new print ranges.
void SetSrcCharSet(rtl_TextEncoding eNew)
SC_DLLPUBLIC void EnsureTable(SCTAB nTab)
SC_DLLPUBLIC SCROW MaxRow() const
SC_DLLPUBLIC void ClearPrintRanges(SCTAB nTab)
Removes all print ranges.
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
SC_DLLPUBLIC void SetPrintEntireSheet(SCTAB nTab)
Marks the specified sheet to be printed completely.
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
SC_DLLPUBLIC const ScViewOptions & GetViewOptions() const
SC_DLLPUBLIC void SetViewOptions(const ScViewOptions &rOpt)
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
SC_DLLPUBLIC void SetRepeatRowRange(SCTAB nTab, std::optional< ScRange > oNew)
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
SC_DLLPUBLIC void SetExtDocOptions(std::unique_ptr< ScExtDocOptions > pNewOptions)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
SC_DLLPUBLIC void SetRepeatColRange(SCTAB nTab, std::optional< ScRange > oNew)
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
SC_DLLPUBLIC void SetVisible(SCTAB nTab, bool bVisible)
SC_DLLPUBLIC SCTAB GetTableCount() const
const ScExtDocSettings & GetDocSettings() const
ScExtTabSettings & GetOrCreateTabSettings(SCTAB nTab)
void SetChanged(bool bChanged)
If set to true, the data will be copied to the view data after import.
const ScRange * First(SCTAB nTab)
void ExtendTo(const ScRange &rRange)
void Set(const ScAddress &rAdr, bool bNewRelCol, bool bNewRelRow, bool bNewRelTab)
void WrapReference(const ScAddress &rPos, SCCOL nMaxCol, SCROW nMaxRow)
void SetObjMode(ScVObjType eObj, ScVObjMode eMode)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemSet & GetItemSet() const
Provides functions to convert Excel cell addresses to Calc cell addresses.
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 SetDefWidth(sal_uInt16 nDefWidth, bool bStdWidthRec=false)
void SetHeight(SCROW nRow, sal_uInt16 nHeight)
void SetDefaultXF(SCCOL nScCol1, SCCOL nScCol2, sal_uInt16 nXFIndex)
void HideColRange(SCCOL nCol1, SCCOL nCol2)
void SetDefHeight(sal_uInt16 nDefHeight, sal_uInt16 nFlags)
void SetRowSettings(SCROW nRow, sal_uInt16 nHeight, sal_uInt16 nFlags)
void SetWidthRange(SCCOL nCol1, SCCOL nCol2, sal_uInt16 nWidth)
void ReadPasswordHash(XclImpStream &rStrm)
void ReadDocProtect(XclImpStream &rStrm)
document structure protection flag
void ReadWinProtect(XclImpStream &rStrm)
document windows properties protection flag
void Finalize()
Sets the view settings at the document.
void ReadWindow1(XclImpStream &rStrm)
Reads a WINDOW1 record.
const XclFontData & GetAppFontData() const
Returns the application font data of this file, needed i.e.
Stores all data of an Excel font and provides import of FONT records.
ScRange GetUsedArea(SCTAB nScTab) const
Returns the used area in the sheet with the passed index.
void ConvertObjects()
Inserts all objects into the Calc document.
void SetButtonMode(bool bRightOrUnder)
void SetLevelRange(SCSIZE nF, SCSIZE nL, sal_uInt8 nVal, bool bCollapsed)
void SetLevel(SCSIZE nIndex, sal_uInt8 nVal, bool bCollapsed)
XclImpOutlineBfrRef mxRowOutlineBuff
XclImpColRowSettings * GetColRowBuff() const
XclImpOutlineDataBuffer(const XclImpRoot &rRoot, SCTAB nScTab)
XclImpOutlineBuffer * GetColOutline() const
XclImpOutlineBuffer * GetRowOutline() const
XclImpColRowSettRef mxColRowBuff
XclImpOutlineBfrRef mxColOutlineBuff
virtual ~XclImpOutlineDataBuffer() override
void SetFitToPages(bool bFitToPages)
Sets or clears the fit-to-pages setting (contained in WSBOOL record).
Access to global data from other classes.
ScRangeListTabs & GetPrintAreaBuffer() const
Returns the buffer that contains all print areas in the document.
XclImpAddressConverter & GetAddressConverter() const
Returns the address converter.
XclImpXFBuffer & GetXFBuffer() const
Returns the cell formatting attributes buffer.
void FinalizeTable()
Is called when import filter stops importing a single sheet (all BIFF versions).
ScRangeListTabs & GetTitleAreaBuffer() const
Returns the buffer that contains all print titles in the document.
XclImpXFRangeBuffer & GetXFRangeBuffer() const
Returns the buffer of XF index ranges for a sheet.
ScDocumentImport & GetDocImport()
XclImpFontBuffer & GetFontBuffer() const
Returns the font buffer.
XclImpDocProtectBuffer & GetDocProtectBuffer() const
Returns the document protection options.
XclImpDocViewSettings & GetDocViewSettings() const
Returns the view settings of the entire document.
void InitializeTable(SCTAB nScTab)
Is called when import filter starts importing a single sheet (all BIFF versions).
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
XclImpPageSettings & GetPageSettings() const
Returns the page settings of the current sheet.
XclImpSheetProtectBuffer & GetSheetProtectBuffer() const
Returns the sheet protection options of the current sheet.
XclImpObjectManager & GetObjectManager() const
Returns the drawing object manager.
void SetCodePage(sal_uInt16 nCodePage)
Sets a code page read from a CODEPAGE record for byte string import.
void ReadProtect(XclImpStream &rStrm, SCTAB nTab)
void ReadPasswordHash(XclImpStream &rStrm, SCTAB nTab)
sal_uInt16 GetRecId() const
Returns the current record ID.
void EnableDecryption(bool bEnable=true)
Switches usage of current decryption algorithm on/off.
void DisableDecryption()
Switches usage of current decryption algorithm off.
std::size_t GetRecLeft()
Returns remaining data size of the whole record without record headers.
void Ignore(std::size_t nBytes)
Seeks forward inside the current record.
OUString ReadByteString(bool b16BitLen)
Reads 8/16 bit string length, character array and returns the string.
static void SetToDocument(ScDocumentImport &rDoc, const ScAddress &rPos, const XclImpRoot &rRoot, const XclImpString &rString, sal_uInt16 nXFIndex)
This class represents an unformatted or formatted string and provides importing from stream.
bool IsRich() const
Returns true, if the string contains formatting information.
void Read(XclImpStream &rStrm, XclStrFlags nFlags=XclStrFlags::NONE)
Reads a complete string from the passed stream.
void ReadFormats(XclImpStream &rStrm)
Reads and appends the formatting information (run count and runs) from stream.
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.
XclImpXF * GetXF(sal_uInt16 nXFIndex)
Returns the object that stores all contents of an XF record.
void SetBoolXF(const ScAddress &rScPos, sal_uInt16 nXFIndex)
Inserts a new XF index for boolean cells.
void SetBlankXF(const ScAddress &rScPos, sal_uInt16 nXFIndex)
Inserts a new XF index for blank cells.
void SetXF(const ScAddress &rScPos, sal_uInt16 nXFIndex)
Inserts a new XF index.
void SetRowDefXF(SCROW nScRow, sal_uInt16 nXFIndex)
Inserts a new XF index for all cells in a row.
void SetMerge(SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2)
Inserts a complete merged cell range.
static void ApplyPatternForBiff2CellFormat(const XclImpRoot &rRoot, const ScAddress &rScPos, sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3)
Converts formatting information from BIFF2 cell record data directly.
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
ScModelObj * GetDocModelObj() const
Returns the object model of the Calc document.
const OUString & GetDocUrl() const
Returns the document URL of the imported/exported file.
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
const ScAddress & GetScMaxPos() const
Returns the highest possible cell address in a Calc document.
rtl_TextEncoding GetTextEncoding() const
Returns the text encoding to import/export byte strings.
void SetDocLanguage(LanguageType eLang)
Sets the document language.
tools::Long GetCharWidth() const
Returns the width of the '0' character (default font) for the current printer (twips).
SfxMedium & GetMedium() const
Returns the medium to import from.
void SetTextEncoding(rtl_TextEncoding eTextEnc)
Sets the text encoding to import/export byte strings.
XclTracer & GetTracer() const
Returns the filter tracer.
void SetUILanguage(LanguageType eLang)
Sets the UI language, i.e.
SCTAB GetCurrScTab() const
Returns the current Calc sheet index.
ScStyleSheetPool & GetStyleSheetPool() const
Returns the style sheet pool of the Calc document.
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
RootData & GetOldRoot() const
Returns old RootData struct.
void IncCurrScTab()
Increases the current Calc sheet index by 1.
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
void TraceInvalidRow(sal_uInt32 nRow, sal_uInt32 nMaxrow)
#define LANGUAGE_DONTKNOW
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::shared_ptr< T > make_shared(Args &&... args)
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
OUString ScResId(TranslateId aId)
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_FIRSTPAGENO(177)
std::unique_ptr< ExtNameBuff > pExtNameBuff
XclImpColRowSettings * pColRowBuff
ExcelToSc * pFmlaConverter
std::unique_ptr< SharedFormulaBuffer > pShrfmlaBuff
std::unique_ptr< ExtSheetBuffer > pExtSheetBuff
Extended settings for the document, used in import/export filters.
SCTAB mnDisplTab
Index of displayed sheet.
Extended settings for a sheet, used in import/export filters.
ScRange maUsedArea
Used area in the sheet (columns/rows only).
Parameter for data table aka multiple operations.
ScRefAddress aRefFormulaEnd
ScRefAddress aRefFormulaCell
A 2D cell address struct with Excel column and row indexes.
sal_uInt16 mnHeight
String with styles (bold, italic).
Stores global buffers and data needed for Excel import filter.
A 2D cell range address struct with Excel column and row indexes.
sal_uInt16 GetColCount() const
void Read(XclImpStream &rStrm, bool bCol16Bit=true)
constexpr OUStringLiteral SC_UNO_APPLYFMDES
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
const sal_uInt16 EXC_WSBOOL_ROWBELOW
const sal_uInt16 EXC_WSBOOL_FITTOPAGE
const sal_uInt16 EXC_WSBOOL_COLBELOW
XclStrFlags
Flags used to specify import/export mode of strings.
@ EightBitLength
Always use UCS-2 characters (default: try to compress). BIFF8 only.
const sal_uInt16 EXC_ROW_USEDEFXF
const sal_uInt16 EXC_ID2_LABEL
const sal_uInt16 EXC_TABLEOP_ROW
const sal_uInt16 EXC_ID4_FORMULA
const sal_uInt8 EXC_BOOLERR_BOOL
const sal_uInt16 EXC_ROW_COLLAPSED
const sal_uInt16 EXC_ROW_XFMASK
const sal_uInt16 EXC_ID2_FORMULA
const sal_uInt16 EXC_ID2_DIMENSIONS
const sal_uInt16 EXC_DEFROW_UNSYNCED
const sal_uInt16 EXC_TABLEOP_BOTH
const sal_uInt16 EXC_COLINFO_COLLAPSED
const sal_uInt16 EXC_ID3_FORMULA
const sal_uInt16 EXC_ID2_NUMBER
const sal_uInt16 EXC_ID2_BOOLERR
const sal_uInt16 EXC_COLINFO_HIDDEN
const sal_uInt16 EXC_ID2_BLANK