1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/config.h>
23 #include <sfx2/docfile.hxx>
25 #include "qproform.hxx"
27 #include "qprostyle.hxx"
30 #include "scerrors.hxx"
31 #include "docpool.hxx"
32 #include "patattr.hxx"
34 #include "document.hxx"
35 #include "formulacell.hxx"
37 #include <tools/stream.hxx>
39 FltError
ScQProReader::readSheet( SCTAB nTab
, ScDocument
* pDoc
, ScQProStyle
*pStyle
)
41 FltError eRet
= eERR_OK
;
42 sal_uInt8 nCol
, nDummy
;
45 bool bEndOfSheet
= false;
47 #if OSL_DEBUG_LEVEL > 1
48 fprintf( stderr
, "Read sheet (%d)\n", nTab
);
51 while( eERR_OK
== eRet
&& !bEndOfSheet
&& nextRecord() )
55 case 0x000f:{ // Label cell
57 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nDummy
;
58 sal_uInt16 nLen
= getLength();
61 readString( aLabel
, nLen
- 7 );
63 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
64 pDoc
->EnsureTable(nTab
);
65 pDoc
->SetTextCell(ScAddress(nCol
,nRow
,nTab
), aLabel
);
72 case 0x00cb: // End of sheet
76 case 0x000c: // Blank cell
77 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
;
79 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
82 case 0x000d:{ // Integer cell
84 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
;
86 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
87 pDoc
->EnsureTable(nTab
);
88 pDoc
->SetValue(ScAddress(nCol
,nRow
,nTab
), static_cast<double>(nValue
));
92 case 0x000e:{ // Floating point cell
94 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
;
96 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
97 pDoc
->EnsureTable(nTab
);
98 pDoc
->SetValue(ScAddress(nCol
,nRow
,nTab
), nValue
);
102 case 0x0010:{ // Formula cell
104 sal_uInt16 nState
, nLen
;
105 *mpStream
>> nCol
>> nDummy
>> nRow
>> nStyle
>> nValue
>> nState
>> nLen
;
106 ScAddress
aAddr( nCol
, nRow
, nTab
);
107 const ScTokenArray
*pArray
;
108 QProToSc
aConv( *mpStream
, aAddr
);
109 if (ConvOK
!= aConv
.Convert( pArray
, nLen
))
113 ScFormulaCell
*pFormula
= new ScFormulaCell( pDoc
, aAddr
, pArray
);
114 nStyle
= nStyle
>> 3;
115 pFormula
->AddRecalcMode( RECALCMODE_ONLOAD_ONCE
);
116 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
117 pDoc
->EnsureTable(nTab
);
118 pDoc
->SetFormulaCell(ScAddress(nCol
,nRow
,nTab
), pFormula
);
127 FltError
ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium
&rMedium
, ScDocument
*pDoc
)
129 ScQProReader
aReader( rMedium
);
130 FltError eRet
= aReader
.import( pDoc
);
134 ScQProReader::ScQProReader( SfxMedium
&rMedium
):
135 ScBiffReader( rMedium
)
139 FltError
ScQProReader::import( ScDocument
*pDoc
)
141 FltError eRet
= eERR_OK
;
143 sal_uInt16 i
= 1, j
= 1;
150 ScQProStyle
*pStyleElement
= new ScQProStyle
;
152 while( nextRecord() && eRet
== eERR_OK
)
156 case 0x0000: // Begginning of file
157 *mpStream
>> nVersion
;
160 case 0x00ca: // Beginning of sheet
166 aName
.Append( sal_Unicode( 'A' + nTab
) );
168 pDoc
->RenameTab( nTab
, aName
, false, false);
170 pDoc
->InsertTab( nTab
, aName
);
172 eRet
= readSheet( nTab
, pDoc
, pStyleElement
);
177 case 0x0001: // End of file
181 case 0x00ce:{ // Attribute cell
182 sal_uInt8 nFormat
, nAlign
, nFont
;
184 *mpStream
>> nFormat
>> nAlign
>> nColor
>> nFont
;
185 pStyleElement
->setAlign( i
, nAlign
);
186 pStyleElement
->setFont( i
, nFont
);
191 case 0x00cf:{ // Font description
192 sal_uInt16 nPtSize
, nFontAttr
;
194 *mpStream
>> nPtSize
>> nFontAttr
;
195 pStyleElement
->setFontRecord( j
, nFontAttr
, nPtSize
);
196 sal_uInt16 nLen
= getLength();
198 readString( aLabel
, nLen
- 4 );
201 pStyleElement
->setFontType( j
, aLabel
);
207 pDoc
->CalcAfterLoad();
208 delete pStyleElement
;
212 bool ScQProReader::recordsLeft()
214 bool bValue
= ScBiffReader::recordsLeft();
218 bool ScQProReader::nextRecord()
220 bool bValue
= ScBiffReader::nextRecord();
224 void ScQProReader::readString( String
&rString
, sal_uInt16 nLength
)
226 sal_Char
* pText
= new sal_Char
[ nLength
+ 1 ];
227 mpStream
->Read( pText
, nLength
);
228 pText
[ nLength
] = 0;
229 rString
= String( pText
, mpStream
->GetStreamCharSet() );
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */