summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorDaniel Rentz [dr] <daniel.rentz@oracle.com>2010-12-17 14:40:47 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-12-04 07:17:06 +0000
commitc40fa0a254530945db54bac192c7a52400238988 (patch)
tree28e7a8ec13f5a03d988dce5b5967fbf29ffd285e /sc/source
parent7766710bfdbf62f0692e8fe16fbd394a70d94087 (diff)
dr78: #i71453# BIFF2: use formatting information from cell records
if XF records are missing Conflicts: sc/source/filter/excel/excform.cxx sc/source/filter/excel/impop.cxx sc/source/filter/inc/imp_op.hxx
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/filter/excel/excform.cxx4
-rw-r--r--sc/source/filter/excel/impop.cxx59
-rw-r--r--sc/source/filter/excel/xistyle.cxx22
-rw-r--r--sc/source/filter/inc/imp_op.hxx8
-rw-r--r--sc/source/filter/inc/xistyle.hxx5
5 files changed, 74 insertions, 24 deletions
diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx
index 416d46f63314..c6d4b4b3a93b 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -82,8 +82,6 @@ void ImportExcel::Formula25()
bShrFmla = nFlag0 & 0x08; // shared or not shared
}
- nLastXF = nXF;
-
Formula( aXclPos, nXF, nFormLen, fCurVal, bShrFmla );
}
@@ -105,8 +103,6 @@ void ImportExcel::Formula4()
aIn.Ignore( 1 );
aIn >> nFormLen;
- nLastXF = nXF;
-
Formula( aXclPos, nXF, nFormLen, fCurVal, false );
}
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index c79b47489c80..5483235481a2 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -122,11 +122,13 @@ ImportExcel::ImportExcel( XclImpRootData& rImpData, SvStream& rStrm ):
XclImpRoot( rImpData ),
maStrm( rStrm, GetRoot() ),
aIn( maStrm ),
- maScOleSize( ScAddress::INITIALIZE_INVALID )
+ maScOleSize( ScAddress::INITIALIZE_INVALID ),
+ mnLastRefIdx( 0 ),
+ mnIxfeIndex( 0 ),
+ mbBiff2HasXfs( false ),
+ mbBiff2HasXfsValid( false )
{
- mnLastRefIdx = 0;
nBdshtTab = 0;
- nIxfeIndex = 0; // zur Sicherheit auf 0
// Root-Daten fuellen - nach new's ohne Root als Parameter
pExcRoot = &GetOldRoot();
@@ -192,17 +194,40 @@ void ImportExcel::ReadFileSharing()
}
}
-sal_uInt16 ImportExcel::ReadXFIndex( bool bBiff2 )
+sal_uInt16 ImportExcel::ReadXFIndex( const ScAddress& rScPos, bool bBiff2 )
{
sal_uInt16 nXFIdx = 0;
if( bBiff2 )
{
- sal_uInt8 nXFIdx2 = 0;
- maStrm >> nXFIdx2;
- maStrm.Ignore( 2 );
- nXFIdx = nXFIdx2 & 0x3F;
- if( nXFIdx == 63 )
- nXFIdx = nIxfeIndex;
+ /* #i71453# On first call, check if the file contains XF records (by
+ trying to access the first XF with index 0). If there are no XFs,
+ the explicit formatting information contained in each cell record
+ will be used instead. */
+ if( !mbBiff2HasXfsValid )
+ {
+ mbBiff2HasXfsValid = true;
+ mbBiff2HasXfs = GetXFBuffer().GetXF( 0 ) != 0;
+ }
+ // read formatting information (includes the XF identifier)
+ sal_uInt8 nFlags1, nFlags2, nFlags3;
+ maStrm >> nFlags1 >> nFlags2 >> nFlags3;
+ /* If the file contains XFs, extract and set the XF identifier,
+ otherwise get the explicit formatting. */
+ if( mbBiff2HasXfs )
+ {
+ nXFIdx = ::extract_value< sal_uInt16 >( nFlags1, 0, 6 );
+ /* If the identifier is equal to 63, then the real identifier is
+ contained in the preceding IXFE record (stored in mnBiff2XfId). */
+ if( nXFIdx == 63 )
+ nXFIdx = mnIxfeIndex;
+ }
+ else
+ {
+ /* Let the XclImpXF class do the conversion of the imported
+ formatting. The XF buffer is empty, therefore will not do any
+ conversion based on the XF index later on. */
+ XclImpXF::ApplyPatternForBiff2CellFormat( GetRoot(), rScPos, nFlags1, nFlags2, nFlags3 );
+ }
}
else
aIn >> nXFIdx;
@@ -257,7 +282,7 @@ void ImportExcel::ReadBlank()
ScAddress aScPos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScPos, aXclPos, GetCurrScTab(), true ) )
{
- sal_uInt16 nXFIdx = ReadXFIndex( maStrm.GetRecId() == EXC_ID2_BLANK );
+ sal_uInt16 nXFIdx = ReadXFIndex( aScPos, maStrm.GetRecId() == EXC_ID2_BLANK );
GetXFRangeBuffer().SetBlankXF( aScPos, nXFIdx );
}
@@ -271,7 +296,7 @@ void ImportExcel::ReadInteger()
ScAddress aScPos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScPos, aXclPos, GetCurrScTab(), true ) )
{
- sal_uInt16 nXFIdx = ReadXFIndex( true );
+ sal_uInt16 nXFIdx = ReadXFIndex( aScPos, true );
sal_uInt16 nValue;
maStrm >> nValue;
@@ -288,7 +313,7 @@ void ImportExcel::ReadNumber()
ScAddress aScPos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScPos, aXclPos, GetCurrScTab(), true ) )
{
- sal_uInt16 nXFIdx = ReadXFIndex( maStrm.GetRecId() == EXC_ID2_NUMBER );
+ sal_uInt16 nXFIdx = ReadXFIndex( aScPos, maStrm.GetRecId() == EXC_ID2_NUMBER );
double fValue;
maStrm >> fValue;
@@ -311,7 +336,7 @@ void ImportExcel::ReadLabel()
0x0204 2-7 2 byte 16-bit length, byte string
0x0204 8 2 byte 16-bit length, unicode string */
bool bBiff2 = maStrm.GetRecId() == EXC_ID2_LABEL;
- sal_uInt16 nXFIdx = ReadXFIndex( bBiff2 );
+ sal_uInt16 nXFIdx = ReadXFIndex( aScPos, bBiff2 );
XclStrFlags nFlags = (bBiff2 && (GetBiff() <= EXC_BIFF5)) ? EXC_STR_8BITLENGTH : EXC_STR_DEFAULT;
XclImpString aString;
@@ -336,7 +361,7 @@ void ImportExcel::ReadBoolErr()
ScAddress aScPos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScPos, aXclPos, GetCurrScTab(), true ) )
{
- sal_uInt16 nXFIdx = ReadXFIndex( maStrm.GetRecId() == EXC_ID2_BOOLERR );
+ sal_uInt16 nXFIdx = ReadXFIndex( aScPos, maStrm.GetRecId() == EXC_ID2_BOOLERR );
sal_uInt8 nValue, nType;
maStrm >> nValue >> nType;
@@ -361,7 +386,7 @@ void ImportExcel::ReadRk()
ScAddress aScPos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScPos, aXclPos, GetCurrScTab(), true ) )
{
- sal_uInt16 nXFIdx = ReadXFIndex( false );
+ sal_uInt16 nXFIdx = ReadXFIndex( aScPos, false );
sal_Int32 nRk;
maStrm >> nRk;
@@ -625,7 +650,7 @@ void ImportExcel::Codepage( void )
void ImportExcel::Ixfe( void )
{
- aIn >> nIxfeIndex;
+ maStrm >> mnIxfeIndex;
}
diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx
index dd24da424aee..dddd2538ba8f 100644
--- a/sc/source/filter/excel/xistyle.cxx
+++ b/sc/source/filter/excel/xistyle.cxx
@@ -1338,6 +1338,28 @@ void XclImpXF::ApplyPatternToAttrList(
}
}
+/*static*/ void XclImpXF::ApplyPatternForBiff2CellFormat( const XclImpRoot& rRoot,
+ const ScAddress& rScPos, sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 )
+{
+ /* Create an XF object and let it do the work. We will have access to its
+ private members here. */
+ XclImpXF aXF( rRoot );
+
+ // no used flags available in BIFF2 (always true)
+ aXF.SetAllUsedFlags( true );
+
+ // set the attributes
+ aXF.maProtection.FillFromXF2( nFlags1 );
+ aXF.maAlignment.FillFromXF2( nFlags3 );
+ aXF.maBorder.FillFromXF2( nFlags3 );
+ aXF.maArea.FillFromXF2( nFlags3 );
+ aXF.mnXclNumFmt = ::extract_value< sal_uInt16 >( nFlags2, 0, 6 );
+ aXF.mnXclFont = ::extract_value< sal_uInt16 >( nFlags2, 6, 2 );
+
+ // write the attributes to the cell
+ aXF.ApplyPattern( rScPos.Col(), rScPos.Row(), rScPos.Col(), rScPos.Row(), rScPos.Tab() );
+}
+
void XclImpXF::SetUsedFlags( sal_uInt8 nUsedFlags )
{
/* Notes about finding the mb***Used flags:
diff --git a/sc/source/filter/inc/imp_op.hxx b/sc/source/filter/inc/imp_op.hxx
index ebbeeb705b3c..edd3adcc2451 100644
--- a/sc/source/filter/inc/imp_op.hxx
+++ b/sc/source/filter/inc/imp_op.hxx
@@ -109,8 +109,10 @@ protected:
XclImpOutlineListBuffer* pOutlineListBuffer;
sal_Int16 mnLastRefIdx;
- sal_uInt16 nIxfeIndex; // merkt sich Angabe im IXFE-Record
- sal_uInt16 nLastXF; // letzter XF in Formula-Record
+ sal_uInt16 mnIxfeIndex; /// Current XF identifier from IXFE record.
+ bool mbBiff2HasXfs; /// Select XF formatting or direct formatting in BIFF2.
+ bool mbBiff2HasXfsValid; /// False = mbBiff2HasXfs is undetermined yet.
+
SCTAB nBdshtTab; // Counter fuer Boundsheet
ScFormulaCell* pLastFormCell; // fuer String-Records
@@ -120,7 +122,7 @@ protected:
// Record-Funktionen
void ReadFileSharing();
- sal_uInt16 ReadXFIndex( bool bBiff2 );
+ sal_uInt16 ReadXFIndex( const ScAddress& rScPos, bool bBiff2 );
void ReadDimensions();
void ReadBlank();
diff --git a/sc/source/filter/inc/xistyle.hxx b/sc/source/filter/inc/xistyle.hxx
index 89f0f578f236..82c30fb58f6c 100644
--- a/sc/source/filter/inc/xistyle.hxx
+++ b/sc/source/filter/inc/xistyle.hxx
@@ -416,6 +416,11 @@ public:
::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2,
sal_uInt32 nForceScNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND);
+ /** Converts formatting information from BIFF2 cell record data directly. */
+ static void ApplyPatternForBiff2CellFormat(
+ const XclImpRoot& rRoot, const ScAddress& rScPos,
+ sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 );
+
private:
void ReadXF2( XclImpStream& rStrm );
void ReadXF3( XclImpStream& rStrm );