1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: qpro.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <sal/config.h>
36 #include <sfx2/docfile.hxx>
38 #include "qproform.hxx"
40 #include "qprostyle.hxx"
43 #include "scerrors.hxx"
44 #include "docpool.hxx"
45 #include "patattr.hxx"
47 #include "document.hxx"
50 #include <tools/stream.hxx>
52 FltError
ScQProReader::readSheet( SCTAB nTab
, ScDocument
* pDoc
, ScQProStyle
*pStyle
)
54 FltError eRet
= eERR_OK
;
55 sal_uInt8 nCol
, nDummy
;
58 bool bEndOfSheet
= false;
61 fprintf( stderr
, "Read sheet (%d)\n", nTab
);
64 while( eERR_OK
== eRet
&& !bEndOfSheet
&& nextRecord() )
68 case 0x000f:{ // Label cell
70 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nDummy
;
71 readString( aLabel
, getLength() - 7 );
73 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
74 pDoc
->PutCell( nCol
, nRow
, nTab
, ScBaseCell::CreateTextCell( aLabel
, pDoc
), (BOOL
) TRUE
);
78 case 0x00cb: // End of sheet
82 case 0x000c: // Blank cell
83 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
;
85 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
88 case 0x000d:{ // Integer cell
90 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
;
91 ScValueCell
* pInteger
= new ScValueCell( ( double ) nValue
);
93 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
94 pDoc
->PutCell(nCol
,nRow
, nTab
,pInteger
,(BOOL
) TRUE
);
98 case 0x000e:{ // Floating point cell
100 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
;
101 ScValueCell
* pFloat
= new ScValueCell( nValue
);
102 nStyle
= nStyle
>> 3;
103 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
104 pDoc
->PutCell( nCol
, nRow
, nTab
, pFloat
, (BOOL
) TRUE
);
108 case 0x0010:{ // Formula cell
110 sal_uInt16 nState
, nLen
;
111 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
>> nState
>> nLen
;
112 ScAddress
aAddr( nCol
, nRow
, nTab
);
113 const ScTokenArray
*pArray
;
114 QProToSc
aConv( *mpStream
, aAddr
);
115 if (ConvOK
!= aConv
.Convert( pArray
, nLen
))
119 ScFormulaCell
*pFormula
= new ScFormulaCell( pDoc
, aAddr
, pArray
);
120 nStyle
= nStyle
>> 3;
121 pFormula
->AddRecalcMode( RECALCMODE_ONLOAD_ONCE
);
122 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
123 pDoc
->PutCell( nCol
, nRow
, nTab
, pFormula
, ( BOOL
) TRUE
);
132 FltError
ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium
&rMedium
, ScDocument
*pDoc
)
134 FltError eRet
= eERR_OK
;
135 ScQProReader
aReader( rMedium
);
136 eRet
= aReader
.import( pDoc
);
140 ScQProReader::ScQProReader( SfxMedium
&rMedium
):
141 ScBiffReader( rMedium
)
145 FltError
ScQProReader::import( ScDocument
*pDoc
)
147 FltError eRet
= eERR_OK
;
149 sal_uInt16 i
= 1, j
= 1;
156 ScQProStyle
*pStyleElement
= new ScQProStyle
;
158 while( nextRecord() && eRet
== eERR_OK
)
162 case 0x0000: // Begginning of file
163 *mpStream
>> nVersion
;
166 case 0x00ca: // Beginning of sheet
172 aName
.Append( sal_Unicode( 'A' + nTab
) );
174 pDoc
->RenameTab( nTab
, aName
, FALSE
, FALSE
);
176 pDoc
->InsertTab( nTab
, aName
);
178 eRet
= readSheet( nTab
, pDoc
, pStyleElement
);
183 case 0x0001: // End of file
187 case 0x00ce:{ // Attribute cell
188 sal_uInt8 nFormat
, nAlign
, nFont
;
190 *mpStream
>> nFormat
>> nAlign
>> nColor
>> nFont
;
191 pStyleElement
->setAlign( i
, nAlign
);
192 pStyleElement
->setFont( i
, nFont
);
197 case 0x00cf:{ // Font description
198 sal_uInt16 nPtSize
, nFontAttr
;
200 *mpStream
>> nPtSize
>> nFontAttr
;
201 pStyleElement
->setFontRecord( j
, nFontAttr
, nPtSize
);
202 readString( aLabel
, getLength() - 4 );
203 pStyleElement
->setFontType( j
, aLabel
);
209 pDoc
->CalcAfterLoad();
210 delete pStyleElement
;
214 bool ScQProReader::recordsLeft()
216 bool bValue
= ScBiffReader::recordsLeft();
220 bool ScQProReader::nextRecord()
222 bool bValue
= ScBiffReader::nextRecord();
226 void ScQProReader::readString( String
&rString
, sal_uInt16 nLength
)
228 sal_Char
* pText
= new sal_Char
[ nLength
+ 1 ];
229 mpStream
->Read( pText
, nLength
);
230 pText
[ nLength
] = 0;
231 rString
= String( pText
, mpStream
->GetStreamCharSet() );