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"
39 #include "document.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*/ )
53 inline void ExportWK1::Bof()
55 aOut
<< ( USHORT
) 0x00 << ( USHORT
) 2 << ( USHORT
) 0x0406; // Version 1-2-3/2, Symhony/1.1
59 inline void ExportWK1::Eof()
61 aOut
<< ( USHORT
) 0x01 << ( USHORT
) 0;
65 inline void ExportWK1::Calcmode()
67 // Calculationmode = automatic
68 aOut
<< ( USHORT
) 0x02 << ( USHORT
) 1 << ( BYTE
) 0xFF;
72 inline void ExportWK1::Calcorder()
75 aOut
<< ( USHORT
) 0x03 << ( USHORT
) 1 << ( BYTE
) 0x00;
79 inline void ExportWK1::Split()
82 aOut
<< ( USHORT
) 0x04 << ( USHORT
) 1 << ( BYTE
) 0x00;
86 inline void ExportWK1::Sync()
89 aOut
<< ( USHORT
) 0x05 << ( USHORT
) 1 << ( BYTE
) 0x00;
93 inline void ExportWK1::Dimensions()
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
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()
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()
130 // ACHTUNG: muss nach Window1 und vor hidden cols record kommen!
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
)
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
)
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
)
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
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
)
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
198 // zunaechst nur Dummy-Angaben (Formel := Ergebnis der Berechnung )
201 fErgebnis
= ( ( ScFormulaCell
* ) pFC
)->GetValue();
203 aOut
<< ( USHORT
) 0x10 << ( USHORT
) nLaenge
204 << GenFormByte( aAttr
) << nCol
<< nRow
206 << ( USHORT
) 9+1 // Dummy-Formula-Size
207 << ( BYTE
) 0x00 // constant, floating point
209 << ( BYTE
) 0x03; // return
213 inline void ExportWK1::Protect()
215 //Global protection off
216 aOut
<< ( USHORT
) 0x24 << ( USHORT
) 1 << ( BYTE
) 0x00;
220 inline void ExportWK1::Footer()
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()
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()
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()
249 // Global label alignment = left
250 aOut
<< ( USHORT
) 0x29 << ( USHORT
) 1 << ( BYTE
) 0x27;
254 inline void ExportWK1::Calccount()
256 // Iteration count = 16 (oder so aehnlich)
257 aOut
<< ( USHORT
) 0x2F << ( USHORT
) 1 << ( BYTE
) 16;
261 inline void ExportWK1::Cursorw12()
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*/ )
270 // PREC: nCol <= WK1MAXCOL, nRow <= WK1MAXROW
271 /* DBG_ASSERT( nCol <= WK1MAXCOL, "ExportWK1::Label(): Col > WK1MAXCOL" );
272 DBG_ASSERT( nRow <= WK1MAXROW, "ExportWK1::Label(): Row > WK1MAXROW" );
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
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()
300 //aOut << ( USHORT ) 0x47 << ( USHORT ) x
301 /* ScRangeName *pRanges = pD->GetRangeName();
305 USHORT nAnz = pRanges->GetCount();
307 for( USHORT nLauf = 0 ; nLauf < nAnz ; nLauf++ )
309 pData = pRanges[ nLauf ];
316 inline void ExportWK1::Hidcol()
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()
329 //aOut << ( USHORT ) 0x96 << ( USHORT ) x;
333 FltError
ExportWK1::Write()
355 ScDocumentIterator
aIter( pD
, 0, 0 );
359 const ScPatternAttr
* pPatAttr
;
361 if( aIter
.GetFirst() )
363 { // ueber alle Zellen der ersten Tabelle iterieren
364 pPatAttr
= aIter
.GetPattern();
365 pCell
= aIter
.GetCell();
368 aIter
.GetPos( nScCol
, nScRow
, nTab
);
369 #if SC_ROWLIMIT_MORE_THAN_64K
372 nCol
= static_cast<USHORT
>(nScCol
);
373 nRow
= static_cast<USHORT
>(nScRow
);
375 switch( pCell
->GetCellType() )
380 fVal
= ( ( ScValueCell
* ) pCell
)->GetValue();
381 Number( nCol
, nRow
, fVal
, *pPatAttr
);
384 case CELLTYPE_STRING
:
387 ( ( ScStringCell
* ) pCell
)->GetString( aStr
);
388 Label( nCol
, nRow
, aStr
, *pPatAttr
);
391 case CELLTYPE_FORMULA
:
393 Formula( nCol
, nRow
, ( ScFormulaCell
* ) pCell
, *pPatAttr
);
394 WKString( nCol
, nRow
, ( ScFormulaCell
* ) pCell
, *pPatAttr
);
401 DBG_ASSERT( FALSE
, "ExportWK1::Write(): unbekannter Celltype!" );
404 while( aIter
.GetNext() );