LibreOffice Module sc (master) 1
xerecord.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <xerecord.hxx>
21#include <xeroot.hxx>
22#include <xltools.hxx>
23
24#include <oox/token/tokens.hxx>
25#include <oox/export/utils.hxx>
26#include <osl/diagnose.h>
27
28using namespace ::oox;
29
30// Base classes to export Excel records =======================================
31
33{
34}
35
37{
38}
39
41{
42}
43
45 mpRecord( pRecord )
46{
47}
48
50{
51 // Do Nothing; we use Delegating Record for other objects we "know" will
52 // survive...
53}
54
56{
57 if( mpRecord )
59}
60
62 : mnElement( nElement )
63{
64}
65
67{
68}
69
71 : XclExpXmlElementRecord(nElement)
72{
73}
74
76{
77}
78
80{
81 sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
82 // TODO: no generic way to add attributes here, but it appears to
83 // not be needed yet
84 rStream->startElement(mnElement);
85}
86
88 : XclExpXmlElementRecord( nElement )
89{
90}
91
93{
94}
95
97{
98 rStrm.GetCurrentStream()->endElement( mnElement );
99}
100
102 sal_Int32 const nElement)
103 : XclExpXmlElementRecord( nElement )
104{
105}
106
108{
109}
110
112{
113 sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
114 rStream->write( "<" )->writeId( mnElement );
115}
116
118{
119}
120
122{
123}
124
126{
127 rStrm.GetCurrentStream()->write( "/>" );
128}
129
130XclExpRecord::XclExpRecord( sal_uInt16 nRecId, std::size_t nRecSize ) :
131 mnRecSize( nRecSize ),
132 mnRecId( nRecId )
133{
134}
135
137{
138}
139
140void XclExpRecord::SetRecHeader( sal_uInt16 nRecId, std::size_t nRecSize )
141{
142 SetRecId( nRecId );
143 SetRecSize( nRecSize );
144}
145
147{
148}
149
151{
152 OSL_ENSURE( mnRecId != EXC_ID_UNKNOWN, "XclExpRecord::Save - record ID uninitialized" );
153 rStrm.StartRecord( mnRecId, mnRecSize );
154 WriteBody( rStrm );
155 rStrm.EndRecord();
156}
157
158template<>
160{
161 if( mnAttribute == -1 )
162 return;
163 rStrm.WriteAttributes(mnAttribute, OUString::number(maValue));
164}
165
167{
168 rStrm << static_cast< sal_uInt16 >( mbValue ? 1 : 0 );
169}
170
172{
173 if( mnAttribute == -1 )
174 return;
175
176 rStrm.WriteAttributes(
177 // HACK: HIDEOBJ (excdoc.cxx) should be its own object to handle XML_showObjects
178 mnAttribute, mnAttribute == XML_showObjects ? "all" : ToPsz( mbValue ));
179}
180
181XclExpDummyRecord::XclExpDummyRecord( sal_uInt16 nRecId, const void* pRecData, std::size_t nRecSize ) :
182 XclExpRecord( nRecId )
183{
184 SetData( pRecData, nRecSize );
185}
186
187void XclExpDummyRecord::SetData( const void* pRecData, std::size_t nRecSize )
188{
189 mpData = pRecData;
190 SetRecSize( pRecData ? nRecSize : 0 );
191}
192
194{
195 rStrm.Write( mpData, GetRecSize() );
196}
197
198// Future records =============================================================
199
200XclExpFutureRecord::XclExpFutureRecord( XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize ) :
201 XclExpRecord( nRecId, nRecSize ),
202 meRecType( eRecType )
203{
204}
205
207{
208 rStrm.StartRecord( GetRecId(), GetRecSize() + ((meRecType == EXC_FUTUREREC_UNUSEDREF) ? 12 : 4) );
209 rStrm << GetRecId() << sal_uInt16( 0 );
211 rStrm.WriteZeroBytes( 8 );
212 WriteBody( rStrm );
213 rStrm.EndRecord();
214}
215
216XclExpSubStream::XclExpSubStream( sal_uInt16 nSubStrmType ) :
217 mnSubStrmType( nSubStrmType )
218{
219}
220
222{
223 // BOF record
224 switch( rStrm.GetRoot().GetBiff() )
225 {
226 case EXC_BIFF2:
227 rStrm.StartRecord( EXC_ID2_BOF, 4 );
228 rStrm << sal_uInt16( 7 ) << mnSubStrmType;
229 rStrm.EndRecord();
230 break;
231 case EXC_BIFF3:
232 rStrm.StartRecord( EXC_ID3_BOF, 6 );
233 rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 2104 );
234 rStrm.EndRecord();
235 break;
236 case EXC_BIFF4:
237 rStrm.StartRecord( EXC_ID4_BOF, 6 );
238 rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 1705 );
239 rStrm.EndRecord();
240 break;
241 case EXC_BIFF5:
242 rStrm.StartRecord( EXC_ID5_BOF, 8 );
243 rStrm << EXC_BOF_BIFF5 << mnSubStrmType << sal_uInt16( 4915 ) << sal_uInt16( 1994 );
244 rStrm.EndRecord();
245 break;
246 case EXC_BIFF8:
247 rStrm.StartRecord( EXC_ID5_BOF, 16 );
248 rStrm << EXC_BOF_BIFF8 << mnSubStrmType << sal_uInt16( 3612 ) << sal_uInt16( 1996 );
249 rStrm << sal_uInt32( 1 ) << sal_uInt32( 6 );
250 rStrm.EndRecord();
251 break;
252 default:
254 }
255
256 // substream records
258
259 // EOF record
260 rStrm.StartRecord( EXC_ID_EOF, 0 );
261 rStrm.EndRecord();
262}
263
264/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:273
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:166
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:171
XclExpRecordBase * mpRecord
Definition: xerecord.hxx:80
virtual ~XclExpDelegatingRecord() override
Definition: xerecord.cxx:49
XclExpDelegatingRecord(XclExpRecordBase *pRecord)
Definition: xerecord.cxx:44
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:55
void SetData(const void *pRecData, std::size_t nRecSize)
Sets a data array.
Definition: xerecord.cxx:187
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:193
XclExpDummyRecord(sal_uInt16 nRecId, const void *pRecData, std::size_t nRecSize)
Definition: xerecord.cxx:181
const void * mpData
Definition: xerecord.hxx:294
XclExpFutureRecord(XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize)
Definition: xerecord.cxx:200
XclFutureRecType meRecType
Definition: xerecord.hxx:309
virtual void Save(XclExpStream &rStrm) override
Writes the extended record header and calls WriteBody().
Definition: xerecord.cxx:206
Base class for all Excel records.
Definition: xerecord.hxx:39
virtual void SaveXml(XclExpXmlStream &rStrm)
Definition: xerecord.cxx:40
virtual ~XclExpRecordBase()
Definition: xerecord.cxx:32
virtual void Save(XclExpStream &rStrm)
Overwrite this method to do any operation while saving the record.
Definition: xerecord.cxx:36
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
Definition: xerecord.hxx:375
Base class for single records with any content.
Definition: xerecord.hxx:143
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
Definition: xerecord.cxx:150
XclExpRecord(sal_uInt16 nRecId=EXC_ID_UNKNOWN, std::size_t nRecSize=0)
Definition: xerecord.cxx:130
sal_uInt16 GetRecId() const
Returns the current record ID.
Definition: xerecord.hxx:156
sal_uInt16 mnRecId
The predicted record size.
Definition: xerecord.hxx:179
void SetRecHeader(sal_uInt16 nRecId, std::size_t nRecSize)
Sets record ID and size with one call.
Definition: xerecord.cxx:140
virtual void WriteBody(XclExpStream &rStrm)
Writes the body of the record (without record header).
Definition: xerecord.cxx:146
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:163
void SetRecId(sal_uInt16 nRecId)
Sets a new record ID.
Definition: xerecord.hxx:161
virtual ~XclExpRecord() override
Definition: xerecord.cxx:136
std::size_t GetRecSize() const
Returns the current record size prediction.
Definition: xerecord.hxx:158
std::size_t mnRecSize
Definition: xerecord.hxx:178
This class is used to export Excel record streams.
Definition: xestream.hxx:73
sal_uInt16 mnSubStrmType
Definition: xerecord.hxx:418
XclExpSubStream(sal_uInt16 nSubStrmType)
Definition: xerecord.cxx:216
virtual void Save(XclExpStream &rStrm) override
Writes the complete substream, including leading BOF and trailing EOF.
Definition: xerecord.cxx:221
void SaveXml(XclExpXmlStream &rStrm) override
Write the OOXML attribute and its value.
Definition: xerecord.hxx:229
virtual ~XclExpXmlElementRecord() override
Definition: xerecord.cxx:66
XclExpXmlElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:61
XclExpXmlEndElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:87
virtual ~XclExpXmlEndElementRecord() override
Definition: xerecord.cxx:92
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the element nElement.
Definition: xerecord.cxx:96
virtual ~XclExpXmlEndSingleElementRecord() override
Definition: xerecord.cxx:121
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the single element nElement.
Definition: xerecord.cxx:125
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the element nElement.
Definition: xerecord.cxx:79
XclExpXmlStartElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:70
virtual ~XclExpXmlStartElementRecord() override
Definition: xerecord.cxx:75
XclExpXmlStartSingleElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:101
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the single element nElement.
Definition: xerecord.cxx:111
virtual ~XclExpXmlStartSingleElementRecord() override
Definition: xerecord.cxx:107
double maValue
void SvStream & rStrm
std::shared_ptr< FastSerializerHelper > FSHelperPtr
XclFutureRecType
Enumerates different header types of future records.
Definition: xlconst.hxx:237
@ EXC_FUTUREREC_UNUSEDREF
Record identifier and empty flags field.
Definition: xlconst.hxx:239
const sal_uInt16 EXC_ID2_BOF
Text rotation: vertically stacked.
Definition: xlconst.hxx:147
const sal_uInt16 EXC_BOF_BIFF8
Definition: xlconst.hxx:156
const sal_uInt16 EXC_ID4_BOF
Definition: xlconst.hxx:149
@ EXC_BIFF5
MS Excel 4.0.
Definition: xlconst.hxx:34
@ EXC_BIFF4
MS Excel 3.0.
Definition: xlconst.hxx:33
@ EXC_BIFF2
Definition: xlconst.hxx:31
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:35
@ EXC_BIFF3
MS Excel 2.1.
Definition: xlconst.hxx:32
const sal_uInt16 EXC_BOF_BIFF5
Definition: xlconst.hxx:155
const sal_uInt16 EXC_ID5_BOF
Definition: xlconst.hxx:150
const sal_uInt16 EXC_ID3_BOF
Definition: xlconst.hxx:148
const sal_uInt16 EXC_ID_EOF
Internal use only.
Definition: xlconst.hxx:167
const sal_uInt16 EXC_ID_UNKNOWN
Definition: xlstream.hxx:35
#define DBG_ERROR_BIFF()
Definition: xltools.hxx:33