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"
42 #include "document.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*/ )
56 inline void ExportWK1::Bof()
58 aOut
<< ( USHORT
) 0x00 << ( USHORT
) 2 << ( USHORT
) 0x0406; // Version 1-2-3/2, Symhony/1.1
62 inline void ExportWK1::Eof()
64 aOut
<< ( USHORT
) 0x01 << ( USHORT
) 0;
68 inline void ExportWK1::Calcmode()
70 // Calculationmode = automatic
71 aOut
<< ( USHORT
) 0x02 << ( USHORT
) 1 << ( BYTE
) 0xFF;
75 inline void ExportWK1::Calcorder()
78 aOut
<< ( USHORT
) 0x03 << ( USHORT
) 1 << ( BYTE
) 0x00;
82 inline void ExportWK1::Split()
85 aOut
<< ( USHORT
) 0x04 << ( USHORT
) 1 << ( BYTE
) 0x00;
89 inline void ExportWK1::Sync()
92 aOut
<< ( USHORT
) 0x05 << ( USHORT
) 1 << ( BYTE
) 0x00;
96 inline void ExportWK1::Dimensions()
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
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()
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()
133 // ACHTUNG: muss nach Window1 und vor hidden cols record kommen!
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
)
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
)
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
)
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
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
)
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
201 // zunaechst nur Dummy-Angaben (Formel := Ergebnis der Berechnung )
204 fErgebnis
= ( ( ScFormulaCell
* ) pFC
)->GetValue();
206 aOut
<< ( USHORT
) 0x10 << ( USHORT
) nLaenge
207 << GenFormByte( aAttr
) << nCol
<< nRow
209 << ( USHORT
) 9+1 // Dummy-Formula-Size
210 << ( BYTE
) 0x00 // constant, floating point
212 << ( BYTE
) 0x03; // return
216 inline void ExportWK1::Protect()
218 //Global protection off
219 aOut
<< ( USHORT
) 0x24 << ( USHORT
) 1 << ( BYTE
) 0x00;
223 inline void ExportWK1::Footer()
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()
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()
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()
252 // Global label alignment = left
253 aOut
<< ( USHORT
) 0x29 << ( USHORT
) 1 << ( BYTE
) 0x27;
257 inline void ExportWK1::Calccount()
259 // Iteration count = 16 (oder so aehnlich)
260 aOut
<< ( USHORT
) 0x2F << ( USHORT
) 1 << ( BYTE
) 16;
264 inline void ExportWK1::Cursorw12()
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*/ )
273 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
274 /* DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Label(): Col > WK1MAXCOL" );
275 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Label(): Row > WK1MAXROW" );
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
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()
303 //aOut << ( USHORT ) 0x47 << ( USHORT ) x
304 /* ScRangeName *pRanges = pD->GetRangeName();
308 USHORT nAnz = pRanges->GetCount();
310 for( USHORT nLauf = 0 ; nLauf < nAnz ; nLauf++ )
312 pData = pRanges[ nLauf ];
319 inline void ExportWK1::Hidcol()
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()
332 //aOut << ( USHORT ) 0x96 << ( USHORT ) x;
336 FltError
ExportWK1::Write()
358 ScDocumentIterator
aIter( pD
, 0, 0 );
362 const ScPatternAttr
* pPatAttr
;
364 if( aIter
.GetFirst() )
366 { // ueber alle Zellen der ersten Tabelle iterieren
367 pPatAttr
= aIter
.GetPattern();
368 pCell
= aIter
.GetCell();
371 aIter
.GetPos( nScCol
, nScRow
, nTab
);
372 #if SC_ROWLIMIT_MORE_THAN_64K
375 nCol
= static_cast<USHORT
>(nScCol
);
376 nRow
= static_cast<USHORT
>(nScRow
);
378 switch( pCell
->GetCellType() )
383 fVal
= ( ( ScValueCell
* ) pCell
)->GetValue();
384 Number( nCol
, nRow
, fVal
, *pPatAttr
);
387 case CELLTYPE_STRING
:
390 ( ( ScStringCell
* ) pCell
)->GetString( aStr
);
391 Label( nCol
, nRow
, aStr
, *pPatAttr
);
394 case CELLTYPE_FORMULA
:
396 Formula( nCol
, nRow
, ( ScFormulaCell
* ) pCell
, *pPatAttr
);
397 WKString( nCol
, nRow
, ( ScFormulaCell
* ) pCell
, *pPatAttr
);
404 DBG_ASSERT( FALSE
, "ExportWK1::Write(): unbekannter Celltype!" );
407 while( aIter
.GetNext() );