merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / source / filter / lotus / expop.cxx
blob7ecc9127b49d516f22b5e6051969575c671fd3c2
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"
33 //------------------------------------------------------------------------
35 #include <tools/debug.hxx>
37 #include "dociter.hxx"
38 #include "cell.hxx"
39 #include "document.hxx"
41 #include "exp_op.hxx"
43 #if ENABLE_LOTUS123_EXPORT
44 const USHORT ExportWK1::WK1MAXCOL = 255;
45 const USHORT ExportWK1::WK1MAXROW = 8191;
47 BYTE ExportWK1::GenFormByte( const ScPatternAttr& /*aAttr*/ )
49 return 0xFF;
53 inline void ExportWK1::Bof()
54 { // (0x00)
55 aOut << ( USHORT ) 0x00 << ( USHORT ) 2 << ( USHORT ) 0x0406; // Version 1-2-3/2, Symhony/1.1
59 inline void ExportWK1::Eof()
60 { // (0x01)
61 aOut << ( USHORT ) 0x01 << ( USHORT ) 0;
65 inline void ExportWK1::Calcmode()
66 { // (0x02)
67 // Calculationmode = automatic
68 aOut << ( USHORT ) 0x02 << ( USHORT ) 1 << ( BYTE ) 0xFF;
72 inline void ExportWK1::Calcorder()
73 { // (0x03)
74 // order = natural
75 aOut << ( USHORT ) 0x03 << ( USHORT ) 1 << ( BYTE ) 0x00;
79 inline void ExportWK1::Split()
80 { // (0x04)
81 // not split
82 aOut << ( USHORT ) 0x04 << ( USHORT ) 1 << ( BYTE ) 0x00;
86 inline void ExportWK1::Sync()
87 { // (0x05)
88 // not synchronized
89 aOut << ( USHORT ) 0x05 << ( USHORT ) 1 << ( BYTE ) 0x00;
93 inline void ExportWK1::Dimensions()
94 { // (0x06)
95 SCCOL nEndCol;
96 SCROW nEndRow;
97 aOut << ( USHORT ) 0x06 << ( USHORT ) 8 << ( USHORT ) 0 << ( USHORT ) 0; // Starting Col/Row
98 pD->GetPrintArea( 0, nEndCol, nEndRow );
99 #if SC_ROWLIMIT_MORE_THAN_64K
100 #error row limit 64k
101 #endif
102 USHORT nCol = static_cast<USHORT>(nEndCol);
103 USHORT nRow = static_cast<USHORT>(nEndRow);
104 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Dimensions(): Col > WK1MAXCOL" );
105 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Dimensions(): Row > WK1MAXROW" );
106 aOut << nCol << nRow; // Ending Col/Row
110 inline void ExportWK1::Window1()
111 { // (0x07)
112 aOut << ( USHORT ) 0x07 << ( USHORT ) 32
113 << ( USHORT ) 0 << ( USHORT ) 0 // Cursor Col/Row
114 << ( BYTE ) 0xFF // Format: protected, special, default
115 << ( BYTE ) 0 // Dummy
116 << ( USHORT ) 9 // Default column width
117 << ( USHORT ) 8 << ( USHORT ) 14// Number of cols/rows on screen
118 << ( USHORT ) 0 << ( USHORT ) 0 // Left col / top row
119 // Rest aus Doku-Beispiel
120 << ( USHORT ) 0 << ( USHORT ) 0 // Number of title cols / rows
121 << ( USHORT ) 0 << ( USHORT ) 0 // Left title col / top title row
122 << ( USHORT ) 0x0004 << ( USHORT ) 0x0004// Top-left col / row
123 << ( USHORT ) 0x0048 // Number of cols in window
124 << ( USHORT ) 0x00; // Dummy
128 inline void ExportWK1::Colw()
129 { // (0x08)
130 // ACHTUNG: muss nach Window1 und vor hidden cols record kommen!
131 USHORT nWidth;
132 BYTE nWidthSpaces;
133 for( USHORT nCol = 0 ; nCol < 256 ; nCol++ )
135 nWidth = pD->GetColWidth( static_cast<SCCOL>(nCol), 0 );
136 nWidthSpaces = ( BYTE ) ( nWidth / TWIPS_PER_CHAR );
137 aOut << ( USHORT ) 0x08 << ( USHORT ) 3 << nCol << nWidthSpaces;
142 void ExportWK1::Blank( const USHORT nCol, const USHORT nRow, const ScPatternAttr& aAttr )
143 { // (0x0C)
144 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
145 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Blank(): Col > WK1MAXCOL" );
146 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Blank(): Row > WK1MAXROW" );
148 aOut << ( USHORT ) 0x0C << ( USHORT ) 5 << GenFormByte( aAttr ) << nCol << nRow;
152 void ExportWK1::Number( const USHORT nCol, const USHORT nRow, const double fWert, const ScPatternAttr &aAttr )
153 { // (0x0E)
154 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
155 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Number(): Col > WK1MAXCOL" );
156 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Number(): Row > WK1MAXROW" );
158 aOut << ( USHORT ) 0x0E << ( USHORT ) 13 << GenFormByte( aAttr ) << nCol << nRow << fWert;
162 void ExportWK1::Label( const USHORT nCol, const USHORT nRow, const String& rStr, const ScPatternAttr& aAttr )
163 { // (0x0F)
164 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
165 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Label(): Col > WK1MAXCOL" );
166 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Label(): Row > WK1MAXROW" );
168 ByteString aStr( rStr, eZielChar );
170 USHORT nLaenge = 7; // Anzahl Bytes vor String+Nullbyte am Ende + Alignment-Char
172 xub_StrLen nAnz = aStr.Len();
175 if( nAnz > 240 ) // max. 240 Zeichen im String
176 nAnz = 240;
178 nLaenge = nLaenge + ( USHORT ) nAnz; // + Stringlaenge
180 aOut << ( USHORT ) 0x0F << nLaenge << GenFormByte( aAttr ) << nCol << nRow << ( sal_Char ) '\'';
181 // ACHTUNG: ZUNAECHST NUR LEFT ALIGNMENT
183 aOut.Write( aStr.GetBuffer(), nAnz );
185 aOut << ( BYTE ) 0x00; // ...und Nullterminator anhaengen
189 void ExportWK1::Formula( const USHORT nCol, const USHORT nRow, const ScFormulaCell* pFC, const ScPatternAttr& aAttr )
190 { // (0x10)
191 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
192 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Formula(): Col > WK1MAXCOL" );
193 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Formula(): Row > WK1MAXROW" );
195 USHORT nLaenge = 15; // Bytes bis Formel
196 double fErgebnis;
198 // zunaechst nur Dummy-Angaben (Formel := Ergebnis der Berechnung )
199 nLaenge += 9+1;
201 fErgebnis = ( ( ScFormulaCell* ) pFC )->GetValue();
203 aOut << ( USHORT ) 0x10 << ( USHORT ) nLaenge
204 << GenFormByte( aAttr ) << nCol << nRow
205 << fErgebnis
206 << ( USHORT ) 9+1 // Dummy-Formula-Size
207 << ( BYTE ) 0x00 // constant, floating point
208 << fErgebnis
209 << ( BYTE ) 0x03; // return
213 inline void ExportWK1::Protect()
214 { // (0x24)
215 //Global protection off
216 aOut << ( USHORT ) 0x24 << ( USHORT ) 1 << ( BYTE ) 0x00;
220 inline void ExportWK1::Footer()
221 { // (0x25)
222 // zunaechst nur leerer C-String
223 aOut << ( USHORT ) 0x25 << ( USHORT ) 242 << ( sal_Char ) '\''; // linksbuendiger leerer String
224 for( short nLauf = 0 ; nLauf < 241 ; nLauf++ )
225 aOut << ( BYTE ) 0x00;
229 inline void ExportWK1::Header()
230 { // (0x26)
231 // zunaechst nur leerer C-String
232 aOut << ( USHORT ) 0x26 << ( USHORT ) 242 << ( sal_Char ) '\''; // linksbuendiger leerer String
233 for( short nLauf = 0 ; nLauf < 241 ; nLauf++ )
234 aOut << ( BYTE ) 0x00;
238 inline void ExportWK1::Margins()
239 { // (0x28)
240 aOut << ( USHORT ) 0x28 << ( USHORT ) 10
241 << ( USHORT ) 4 << ( USHORT ) 76 // Left/right margin
242 << ( USHORT ) 66 // Page length
243 << ( USHORT ) 2 << ( USHORT ) 2; // Top/Bottom margin
247 inline void ExportWK1::Labelfmt()
248 { // (0x29)
249 // Global label alignment = left
250 aOut << ( USHORT ) 0x29 << ( USHORT ) 1 << ( BYTE ) 0x27;
254 inline void ExportWK1::Calccount()
255 { // (0x2F)
256 // Iteration count = 16 (oder so aehnlich)
257 aOut << ( USHORT ) 0x2F << ( USHORT ) 1 << ( BYTE ) 16;
261 inline void ExportWK1::Cursorw12()
262 { // (0x31)
263 // Cursor location in window 1
264 aOut << ( USHORT ) 0x31 << ( USHORT ) 1 << ( BYTE ) 1;
268 void ExportWK1::WKString( const USHORT /*nCol*/, const USHORT /*nRow*/, const ScFormulaCell* /*pFC*/, const ScPatternAttr& /*aAttr*/ )
269 { // (0x33)
270 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
271 /* DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Label(): Col > WK1MAXCOL" );
272 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Label(): Row > WK1MAXROW" );
274 String aStr;
275 ( ( ScFormulaCell * ) pFC )->GetString( aStr ); // Formeltext zunaechst so belassen
277 USHORT nLaenge = 6; // Anzahl Bytes vor String+Nullbyte am Ende
279 USHORT nAnz = aStr.Len();
281 if( nAnz > 240 ) // max. 240 Zeichen im String
282 nAnz = 240;
284 nLaenge += nAnz; // + Stringlaenge
286 aOut << ( USHORT ) 0x33 << nLaenge
287 << GenFormByte( aAttr ) << nCol << nRow;
289 // Zeichenweise String ausgeben
290 for( USHORT nLauf = 0 ; nLauf < nAnz ; nLauf++ )
291 aOut << aStr[ nLauf ];
293 aOut << ( BYTE ) 0x00; // ...und Nullterminator anhaengen
298 inline void ExportWK1::Snrange()
299 { // (0x47)
300 //aOut << ( USHORT ) 0x47 << ( USHORT ) x
301 /* ScRangeName *pRanges = pD->GetRangeName();
302 ScRangeData *pData;
303 String aName;
305 USHORT nAnz = pRanges->GetCount();
307 for( USHORT nLauf = 0 ; nLauf < nAnz ; nLauf++ )
309 pData = pRanges[ nLauf ];
316 inline void ExportWK1::Hidcol()
317 { // (0x64)
318 sal_uInt32 nHide = 0x00000000; // ...niemand ist versteckt
320 aOut << ( USHORT ) 0x64 << ( USHORT ) 32;
322 for( int nLauf = 0 ; nLauf < 8 ; nLauf++ )
323 aOut << nHide; // 8 * 32 Bits = 256
327 inline void ExportWK1::Cpi()
328 { // (0x96)
329 //aOut << ( USHORT ) 0x96 << ( USHORT ) x;
333 FltError ExportWK1::Write()
335 Bof();
336 //Dimensions();
337 //Cpi();
338 //Calccount();
339 //Calcmode();
340 //Calcorder();
341 //Split();
342 //Sync();
343 //Window1();
344 Colw();
345 //Hidcol();
346 //Cursorw12();
347 //Snrange();
348 //Protect();
349 //Footer();
350 //Header();
351 //Margins();
352 //Labelfmt();
354 // Zellen-Bemachung
355 ScDocumentIterator aIter( pD, 0, 0 );
356 ScBaseCell* pCell;
357 USHORT nCol, nRow;
358 SCTAB nTab;
359 const ScPatternAttr* pPatAttr;
361 if( aIter.GetFirst() )
363 { // ueber alle Zellen der ersten Tabelle iterieren
364 pPatAttr = aIter.GetPattern();
365 pCell = aIter.GetCell();
366 SCCOL nScCol;
367 SCROW nScRow;
368 aIter.GetPos( nScCol, nScRow, nTab );
369 #if SC_ROWLIMIT_MORE_THAN_64K
370 #error row limit 64k
371 #endif
372 nCol = static_cast<USHORT>(nScCol);
373 nRow = static_cast<USHORT>(nScRow);
375 switch( pCell->GetCellType() )
377 case CELLTYPE_VALUE:
379 double fVal;
380 fVal = ( ( ScValueCell * ) pCell)->GetValue();
381 Number( nCol, nRow, fVal, *pPatAttr );
383 break;
384 case CELLTYPE_STRING:
386 String aStr;
387 ( ( ScStringCell * ) pCell)->GetString( aStr );
388 Label( nCol, nRow, aStr, *pPatAttr );
390 break;
391 case CELLTYPE_FORMULA:
393 Formula( nCol, nRow, ( ScFormulaCell * ) pCell, *pPatAttr );
394 WKString( nCol, nRow, ( ScFormulaCell * ) pCell, *pPatAttr );
396 break;
397 case CELLTYPE_NOTE:
398 case CELLTYPE_NONE:
399 break;
400 default:
401 DBG_ASSERT( FALSE, "ExportWK1::Write(): unbekannter Celltype!" );
404 while( aIter.GetNext() );
406 Eof();
408 return eERR_OK;
410 #endif