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 .
20 #include <sal/config.h>
22 #include <sfx2/docfile.hxx>
24 #include "qproform.hxx"
26 #include "qprostyle.hxx"
29 #include "scerrors.hxx"
30 #include "docpool.hxx"
31 #include "patattr.hxx"
33 #include "document.hxx"
34 #include "formulacell.hxx"
36 #include <tools/stream.hxx>
37 #include <boost/scoped_array.hpp>
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
->ReadUChar( nCol
).ReadUChar( nDummy
).ReadUInt16( nRow
).ReadUInt16( nStyle
).ReadUChar( 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
->ReadUChar( nCol
).ReadUChar( nDummy
).ReadUInt16( nRow
).ReadUInt16( nStyle
);
79 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
82 case 0x000d:{ // Integer cell
84 mpStream
->ReadUChar( nCol
).ReadUChar( nDummy
).ReadUInt16( nRow
).ReadUInt16( nStyle
).ReadInt16( 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
->ReadUChar( nCol
).ReadUChar( nDummy
).ReadUInt16( nRow
).ReadUInt16( nStyle
).ReadDouble( nValue
);
96 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
97 pDoc
->EnsureTable(nTab
);
98 pDoc
->SetValue(ScAddress(nCol
,nRow
,nTab
), nValue
);
106 sal_uInt16 nState
, nLen
;
107 mpStream
->ReadUChar( nCol
).ReadUChar( nDummy
).ReadUInt16( nRow
).ReadUInt16( nStyle
).ReadDouble( nValue
).ReadUInt16( nState
).ReadUInt16( nLen
);
108 ScAddress
aAddr( nCol
, nRow
, nTab
);
109 const ScTokenArray
*pArray
;
111 QProToSc
aConv(*mpStream
, pDoc
->GetSharedStringPool(), aAddr
);
112 if (ConvOK
!= aConv
.Convert( pArray
, nLen
))
116 ScFormulaCell
* pFormula
= new ScFormulaCell(pDoc
, aAddr
, *pArray
);
117 nStyle
= nStyle
>> 3;
118 pFormula
->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE
);
119 pStyle
->SetFormat( pDoc
, nCol
, nRow
, nTab
, nStyle
);
120 pDoc
->EnsureTable(nTab
);
121 pDoc
->SetFormulaCell(ScAddress(nCol
,nRow
,nTab
), pFormula
);
130 FltError
ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium
&rMedium
, ScDocument
*pDoc
)
132 ScQProReader
aReader( rMedium
);
133 FltError 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
->ReadUInt16( nVersion
);
163 case 0x00ca: // Beginning of sheet
169 aName
+= OUString( 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
->ReadUChar( nFormat
).ReadUChar( nAlign
).ReadInt16( nColor
).ReadUChar( nFont
);
188 pStyleElement
->setAlign( i
, nAlign
);
189 pStyleElement
->setFont( i
, nFont
);
194 case 0x00cf:{ // Font description
195 sal_uInt16 nPtSize
, nFontAttr
;
197 mpStream
->ReadUInt16( nPtSize
).ReadUInt16( nFontAttr
);
198 pStyleElement
->setFontRecord( j
, nFontAttr
, nPtSize
);
199 sal_uInt16 nLen
= getLength();
201 readString( aLabel
, nLen
- 4 );
204 pStyleElement
->setFontType( j
, aLabel
);
210 pDoc
->CalcAfterLoad();
211 delete pStyleElement
;
215 bool ScQProReader::recordsLeft()
217 bool bValue
= ScBiffReader::recordsLeft();
221 bool ScQProReader::nextRecord()
223 bool bValue
= ScBiffReader::nextRecord();
227 void ScQProReader::readString( OUString
&rString
, sal_uInt16 nLength
)
229 boost::scoped_array
<sal_Char
> pText(new sal_Char
[ nLength
+ 1 ]);
230 nLength
= mpStream
->Read(pText
.get(), nLength
);
231 pText
[ nLength
] = 0;
232 rString
= OUString( pText
.get(), strlen(pText
.get()), mpStream
->GetStreamCharSet() );
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */