update dev300-m58
[ooovba.git] / sc / source / filter / lotus / expop.cxx
blobefe7b305270e257573d41d72a770efbd8413b7e4
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: expop.cxx,v $
10 * $Revision: 1.7.128.1 $
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"
36 //------------------------------------------------------------------------
38 #include <tools/debug.hxx>
40 #include "dociter.hxx"
41 #include "cell.hxx"
42 #include "document.hxx"
44 #include "exp_op.hxx"
46 #if ENABLE_LOTUS123_EXPORT
47 const USHORT ExportWK1::WK1MAXCOL = 255;
48 const USHORT ExportWK1::WK1MAXROW = 8191;
50 BYTE ExportWK1::GenFormByte( const ScPatternAttr& /*aAttr*/ )
52 return 0xFF;
56 inline void ExportWK1::Bof()
57 { // (0x00)
58 aOut << ( USHORT ) 0x00 << ( USHORT ) 2 << ( USHORT ) 0x0406; // Version 1-2-3/2, Symhony/1.1
62 inline void ExportWK1::Eof()
63 { // (0x01)
64 aOut << ( USHORT ) 0x01 << ( USHORT ) 0;
68 inline void ExportWK1::Calcmode()
69 { // (0x02)
70 // Calculationmode = automatic
71 aOut << ( USHORT ) 0x02 << ( USHORT ) 1 << ( BYTE ) 0xFF;
75 inline void ExportWK1::Calcorder()
76 { // (0x03)
77 // order = natural
78 aOut << ( USHORT ) 0x03 << ( USHORT ) 1 << ( BYTE ) 0x00;
82 inline void ExportWK1::Split()
83 { // (0x04)
84 // not split
85 aOut << ( USHORT ) 0x04 << ( USHORT ) 1 << ( BYTE ) 0x00;
89 inline void ExportWK1::Sync()
90 { // (0x05)
91 // not synchronized
92 aOut << ( USHORT ) 0x05 << ( USHORT ) 1 << ( BYTE ) 0x00;
96 inline void ExportWK1::Dimensions()
97 { // (0x06)
98 SCCOL nEndCol;
99 SCROW nEndRow;
100 aOut << ( USHORT ) 0x06 << ( USHORT ) 8 << ( USHORT ) 0 << ( USHORT ) 0; // Starting Col/Row
101 pD->GetPrintArea( 0, nEndCol, nEndRow );
102 #if SC_ROWLIMIT_MORE_THAN_64K
103 #error row limit 64k
104 #endif
105 USHORT nCol = static_cast<USHORT>(nEndCol);
106 USHORT nRow = static_cast<USHORT>(nEndRow);
107 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Dimensions(): Col > WK1MAXCOL" );
108 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Dimensions(): Row > WK1MAXROW" );
109 aOut << nCol << nRow; // Ending Col/Row
113 inline void ExportWK1::Window1()
114 { // (0x07)
115 aOut << ( USHORT ) 0x07 << ( USHORT ) 32
116 << ( USHORT ) 0 << ( USHORT ) 0 // Cursor Col/Row
117 << ( BYTE ) 0xFF // Format: protected, special, default
118 << ( BYTE ) 0 // Dummy
119 << ( USHORT ) 9 // Default column width
120 << ( USHORT ) 8 << ( USHORT ) 14// Number of cols/rows on screen
121 << ( USHORT ) 0 << ( USHORT ) 0 // Left col / top row
122 // Rest aus Doku-Beispiel
123 << ( USHORT ) 0 << ( USHORT ) 0 // Number of title cols / rows
124 << ( USHORT ) 0 << ( USHORT ) 0 // Left title col / top title row
125 << ( USHORT ) 0x0004 << ( USHORT ) 0x0004// Top-left col / row
126 << ( USHORT ) 0x0048 // Number of cols in window
127 << ( USHORT ) 0x00; // Dummy
131 inline void ExportWK1::Colw()
132 { // (0x08)
133 // ACHTUNG: muss nach Window1 und vor hidden cols record kommen!
134 USHORT nWidth;
135 BYTE nWidthSpaces;
136 for( USHORT nCol = 0 ; nCol < 256 ; nCol++ )
138 nWidth = pD->GetColWidth( static_cast<SCCOL>(nCol), 0 );
139 nWidthSpaces = ( BYTE ) ( nWidth / TWIPS_PER_CHAR );
140 aOut << ( USHORT ) 0x08 << ( USHORT ) 3 << nCol << nWidthSpaces;
145 void ExportWK1::Blank( const USHORT nCol, const USHORT nRow, const ScPatternAttr& aAttr )
146 { // (0x0C)
147 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
148 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Blank(): Col > WK1MAXCOL" );
149 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Blank(): Row > WK1MAXROW" );
151 aOut << ( USHORT ) 0x0C << ( USHORT ) 5 << GenFormByte( aAttr ) << nCol << nRow;
155 void ExportWK1::Number( const USHORT nCol, const USHORT nRow, const double fWert, const ScPatternAttr &aAttr )
156 { // (0x0E)
157 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
158 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Number(): Col > WK1MAXCOL" );
159 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Number(): Row > WK1MAXROW" );
161 aOut << ( USHORT ) 0x0E << ( USHORT ) 13 << GenFormByte( aAttr ) << nCol << nRow << fWert;
165 void ExportWK1::Label( const USHORT nCol, const USHORT nRow, const String& rStr, const ScPatternAttr& aAttr )
166 { // (0x0F)
167 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
168 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Label(): Col > WK1MAXCOL" );
169 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Label(): Row > WK1MAXROW" );
171 ByteString aStr( rStr, eZielChar );
173 USHORT nLaenge = 7; // Anzahl Bytes vor String+Nullbyte am Ende + Alignment-Char
175 xub_StrLen nAnz = aStr.Len();
178 if( nAnz > 240 ) // max. 240 Zeichen im String
179 nAnz = 240;
181 nLaenge = nLaenge + ( USHORT ) nAnz; // + Stringlaenge
183 aOut << ( USHORT ) 0x0F << nLaenge << GenFormByte( aAttr ) << nCol << nRow << ( sal_Char ) '\'';
184 // ACHTUNG: ZUNAECHST NUR LEFT ALIGNMENT
186 aOut.Write( aStr.GetBuffer(), nAnz );
188 aOut << ( BYTE ) 0x00; // ...und Nullterminator anhaengen
192 void ExportWK1::Formula( const USHORT nCol, const USHORT nRow, const ScFormulaCell* pFC, const ScPatternAttr& aAttr )
193 { // (0x10)
194 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
195 DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Formula(): Col > WK1MAXCOL" );
196 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Formula(): Row > WK1MAXROW" );
198 USHORT nLaenge = 15; // Bytes bis Formel
199 double fErgebnis;
201 // zunaechst nur Dummy-Angaben (Formel := Ergebnis der Berechnung )
202 nLaenge += 9+1;
204 fErgebnis = ( ( ScFormulaCell* ) pFC )->GetValue();
206 aOut << ( USHORT ) 0x10 << ( USHORT ) nLaenge
207 << GenFormByte( aAttr ) << nCol << nRow
208 << fErgebnis
209 << ( USHORT ) 9+1 // Dummy-Formula-Size
210 << ( BYTE ) 0x00 // constant, floating point
211 << fErgebnis
212 << ( BYTE ) 0x03; // return
216 inline void ExportWK1::Protect()
217 { // (0x24)
218 //Global protection off
219 aOut << ( USHORT ) 0x24 << ( USHORT ) 1 << ( BYTE ) 0x00;
223 inline void ExportWK1::Footer()
224 { // (0x25)
225 // zunaechst nur leerer C-String
226 aOut << ( USHORT ) 0x25 << ( USHORT ) 242 << ( sal_Char ) '\''; // linksbuendiger leerer String
227 for( short nLauf = 0 ; nLauf < 241 ; nLauf++ )
228 aOut << ( BYTE ) 0x00;
232 inline void ExportWK1::Header()
233 { // (0x26)
234 // zunaechst nur leerer C-String
235 aOut << ( USHORT ) 0x26 << ( USHORT ) 242 << ( sal_Char ) '\''; // linksbuendiger leerer String
236 for( short nLauf = 0 ; nLauf < 241 ; nLauf++ )
237 aOut << ( BYTE ) 0x00;
241 inline void ExportWK1::Margins()
242 { // (0x28)
243 aOut << ( USHORT ) 0x28 << ( USHORT ) 10
244 << ( USHORT ) 4 << ( USHORT ) 76 // Left/right margin
245 << ( USHORT ) 66 // Page length
246 << ( USHORT ) 2 << ( USHORT ) 2; // Top/Bottom margin
250 inline void ExportWK1::Labelfmt()
251 { // (0x29)
252 // Global label alignment = left
253 aOut << ( USHORT ) 0x29 << ( USHORT ) 1 << ( BYTE ) 0x27;
257 inline void ExportWK1::Calccount()
258 { // (0x2F)
259 // Iteration count = 16 (oder so aehnlich)
260 aOut << ( USHORT ) 0x2F << ( USHORT ) 1 << ( BYTE ) 16;
264 inline void ExportWK1::Cursorw12()
265 { // (0x31)
266 // Cursor location in window 1
267 aOut << ( USHORT ) 0x31 << ( USHORT ) 1 << ( BYTE ) 1;
271 void ExportWK1::WKString( const USHORT /*nCol*/, const USHORT /*nRow*/, const ScFormulaCell* /*pFC*/, const ScPatternAttr& /*aAttr*/ )
272 { // (0x33)
273 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
274 /* DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Label(): Col > WK1MAXCOL" );
275 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Label(): Row > WK1MAXROW" );
277 String aStr;
278 ( ( ScFormulaCell * ) pFC )->GetString( aStr ); // Formeltext zunaechst so belassen
280 USHORT nLaenge = 6; // Anzahl Bytes vor String+Nullbyte am Ende
282 USHORT nAnz = aStr.Len();
284 if( nAnz > 240 ) // max. 240 Zeichen im String
285 nAnz = 240;
287 nLaenge += nAnz; // + Stringlaenge
289 aOut << ( USHORT ) 0x33 << nLaenge
290 << GenFormByte( aAttr ) << nCol << nRow;
292 // Zeichenweise String ausgeben
293 for( USHORT nLauf = 0 ; nLauf < nAnz ; nLauf++ )
294 aOut << aStr[ nLauf ];
296 aOut << ( BYTE ) 0x00; // ...und Nullterminator anhaengen
301 inline void ExportWK1::Snrange()
302 { // (0x47)
303 //aOut << ( USHORT ) 0x47 << ( USHORT ) x
304 /* ScRangeName *pRanges = pD->GetRangeName();
305 ScRangeData *pData;
306 String aName;
308 USHORT nAnz = pRanges->GetCount();
310 for( USHORT nLauf = 0 ; nLauf < nAnz ; nLauf++ )
312 pData = pRanges[ nLauf ];
319 inline void ExportWK1::Hidcol()
320 { // (0x64)
321 sal_uInt32 nHide = 0x00000000; // ...niemand ist versteckt
323 aOut << ( USHORT ) 0x64 << ( USHORT ) 32;
325 for( int nLauf = 0 ; nLauf < 8 ; nLauf++ )
326 aOut << nHide; // 8 * 32 Bits = 256
330 inline void ExportWK1::Cpi()
331 { // (0x96)
332 //aOut << ( USHORT ) 0x96 << ( USHORT ) x;
336 FltError ExportWK1::Write()
338 Bof();
339 //Dimensions();
340 //Cpi();
341 //Calccount();
342 //Calcmode();
343 //Calcorder();
344 //Split();
345 //Sync();
346 //Window1();
347 Colw();
348 //Hidcol();
349 //Cursorw12();
350 //Snrange();
351 //Protect();
352 //Footer();
353 //Header();
354 //Margins();
355 //Labelfmt();
357 // Zellen-Bemachung
358 ScDocumentIterator aIter( pD, 0, 0 );
359 ScBaseCell* pCell;
360 USHORT nCol, nRow;
361 SCTAB nTab;
362 const ScPatternAttr* pPatAttr;
364 if( aIter.GetFirst() )
366 { // ueber alle Zellen der ersten Tabelle iterieren
367 pPatAttr = aIter.GetPattern();
368 pCell = aIter.GetCell();
369 SCCOL nScCol;
370 SCROW nScRow;
371 aIter.GetPos( nScCol, nScRow, nTab );
372 #if SC_ROWLIMIT_MORE_THAN_64K
373 #error row limit 64k
374 #endif
375 nCol = static_cast<USHORT>(nScCol);
376 nRow = static_cast<USHORT>(nScRow);
378 switch( pCell->GetCellType() )
380 case CELLTYPE_VALUE:
382 double fVal;
383 fVal = ( ( ScValueCell * ) pCell)->GetValue();
384 Number( nCol, nRow, fVal, *pPatAttr );
386 break;
387 case CELLTYPE_STRING:
389 String aStr;
390 ( ( ScStringCell * ) pCell)->GetString( aStr );
391 Label( nCol, nRow, aStr, *pPatAttr );
393 break;
394 case CELLTYPE_FORMULA:
396 Formula( nCol, nRow, ( ScFormulaCell * ) pCell, *pPatAttr );
397 WKString( nCol, nRow, ( ScFormulaCell * ) pCell, *pPatAttr );
399 break;
400 case CELLTYPE_NOTE:
401 case CELLTYPE_NONE:
402 break;
403 default:
404 DBG_ASSERT( FALSE, "ExportWK1::Write(): unbekannter Celltype!" );
407 while( aIter.GetNext() );
409 Eof();
411 return eERR_OK;
413 #endif