1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
31 #include <sal/config.h>
33 #include <sfx2/docfile.hxx>
35 #include "qproform.hxx"
37 #include "qprostyle.hxx"
40 #include "scerrors.hxx"
41 #include "docpool.hxx"
42 #include "patattr.hxx"
44 #include "document.hxx"
47 #include <tools/stream.hxx>
49 FltError
ScQProReader::readSheet( SCTAB nTab
, ScDocument
* pDoc
, ScQProStyle
*pStyle
)
51 FltError eRet
= eERR_OK
;
52 sal_uInt8 nCol
, nDummy
;
55 bool bEndOfSheet
= false;
58 fprintf( stderr
, "Read sheet (%d)\n", nTab
);
61 while( eERR_OK
== eRet
&& !bEndOfSheet
&& nextRecord() )
65 case 0x000f:{ // Label cell
67 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nDummy
;
68 readString( aLabel
, getLength() - 7 );
70 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
71 pDoc
->PutCell( nCol
, nRow
, nTab
, ScBaseCell::CreateTextCell( aLabel
, pDoc
), (BOOL
) TRUE
);
75 case 0x00cb: // End of sheet
79 case 0x000c: // Blank cell
80 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
;
82 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
85 case 0x000d:{ // Integer cell
87 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
;
88 ScValueCell
* pInteger
= new ScValueCell( ( double ) nValue
);
90 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
91 pDoc
->PutCell(nCol
,nRow
, nTab
,pInteger
,(BOOL
) TRUE
);
95 case 0x000e:{ // Floating point cell
97 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
;
98 ScValueCell
* pFloat
= new ScValueCell( nValue
);
100 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
101 pDoc
->PutCell( nCol
, nRow
, nTab
, pFloat
, (BOOL
) TRUE
);
105 case 0x0010:{ // Formula cell
107 sal_uInt16 nState
, nLen
;
108 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
>> nState
>> nLen
;
109 ScAddress
aAddr( nCol
, nRow
, nTab
);
110 const ScTokenArray
*pArray
;
111 QProToSc
aConv( *mpStream
, aAddr
);
112 if (ConvOK
!= aConv
.Convert( pArray
, nLen
))
116 ScFormulaCell
*pFormula
= new ScFormulaCell( pDoc
, aAddr
, pArray
);
117 nStyle
= nStyle
>> 3;
118 pFormula
->AddRecalcMode( RECALCMODE_ONLOAD_ONCE
);
119 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
120 pDoc
->PutCell( nCol
, nRow
, nTab
, pFormula
, ( BOOL
) TRUE
);
129 FltError
ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium
&rMedium
, ScDocument
*pDoc
)
131 FltError eRet
= eERR_OK
;
132 ScQProReader
aReader( rMedium
);
133 eRet
= aReader
.import( pDoc
);
137 ScQProReader::ScQProReader( SfxMedium
&rMedium
):
138 ScBiffReader( rMedium
)
142 FltError
ScQProReader::import( ScDocument
*pDoc
)
144 FltError eRet
= eERR_OK
;
146 sal_uInt16 i
= 1, j
= 1;
153 ScQProStyle
*pStyleElement
= new ScQProStyle
;
155 while( nextRecord() && eRet
== eERR_OK
)
159 case 0x0000: // Begginning of file
160 *mpStream
>> nVersion
;
163 case 0x00ca: // Beginning of sheet
169 aName
.Append( sal_Unicode( 'A' + nTab
) );
171 pDoc
->RenameTab( nTab
, aName
, FALSE
, FALSE
);
173 pDoc
->InsertTab( nTab
, aName
);
175 eRet
= readSheet( nTab
, pDoc
, pStyleElement
);
180 case 0x0001: // End of file
184 case 0x00ce:{ // Attribute cell
185 sal_uInt8 nFormat
, nAlign
, nFont
;
187 *mpStream
>> nFormat
>> nAlign
>> nColor
>> nFont
;
188 pStyleElement
->setAlign( i
, nAlign
);
189 pStyleElement
->setFont( i
, nFont
);
194 case 0x00cf:{ // Font description
195 sal_uInt16 nPtSize
, nFontAttr
;
197 *mpStream
>> nPtSize
>> nFontAttr
;
198 pStyleElement
->setFontRecord( j
, nFontAttr
, nPtSize
);
199 readString( aLabel
, getLength() - 4 );
200 pStyleElement
->setFontType( j
, aLabel
);
206 pDoc
->CalcAfterLoad();
207 delete pStyleElement
;
211 bool ScQProReader::recordsLeft()
213 bool bValue
= ScBiffReader::recordsLeft();
217 bool ScQProReader::nextRecord()
219 bool bValue
= ScBiffReader::nextRecord();
223 void ScQProReader::readString( String
&rString
, sal_uInt16 nLength
)
225 sal_Char
* pText
= new sal_Char
[ nLength
+ 1 ];
226 mpStream
->Read( pText
, nLength
);
227 pText
[ nLength
] = 0;
228 rString
= String( pText
, mpStream
->GetStreamCharSet() );