1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <document.hxx>
21 #include <docoptio.hxx>
24 #include <scerrors.hxx>
26 #include "lotfilter.hxx"
27 #include <lotimpop.hxx>
28 #include <lotattr.hxx>
29 #include <fprogressbar.hxx>
31 #include <sal/log.hxx>
33 ErrCode
ImportLotus::parse()
37 S_START
, // analyse first BOF
38 S_WK3
, // in WK3-Section
41 S_END
// Import finished
47 sal_uInt32 nNextRec
= 0;
48 ErrCode eRet
= ERRCODE_NONE
;
49 // ScFormulaCell *pLastFormCell;
51 STATE eCurrent
= S_START
;
56 pIn
->Seek( nNextRec
);
59 ScfStreamProgressBar
aPrgrsBar( *pIn
, pD
->GetDocumentShell() );
60 LotusContext
&rContext
= aConv
.getContext();
61 while( eCurrent
!= S_END
)
63 pIn
->ReadUInt16( nOp
).ReadUInt16( nRecLen
);
65 if (!pIn
->good() || nNextRec
> SAL_MAX_UINT32
- nRecLen
- 4)
67 eRet
= SCERR_IMPORT_FORMAT
;
73 nNextRec
+= nRecLen
+ 4;
78 case S_START
: // S_START
81 eRet
= SCERR_IMPORT_UNKNOWN_WK
;
89 switch (rContext
.pLotusRoot
->eFirstType
)
91 case Lotus123Typ::WK3
: eCurrent
= S_WK3
; break;
92 case Lotus123Typ::WK4
: eCurrent
= S_WK4
; break;
94 eRet
= SCERR_IMPORT_UNKNOWN_WK
;
100 eCurrent
= S_END
; // TODO: add here something for <= WK1!
101 eRet
= ErrCode(0xFFFFFFFF);
115 case 0x0002: // PASSWORD
116 eRet
= SCERR_IMPORT_FILEPASSWD
;
120 case 0x0007: // COLUMNWIDTH
121 Columnwidth( nRecLen
);
124 case 0x0008: // HIDDENCOLUMN
125 Hiddencolumn( nRecLen
);
128 case 0x0009: // USERRANGE
132 case 0x0013: // FORMAT
135 case 0x0014: // ERRCELL
139 case 0x0015: // NACELL
143 case 0x0016: // LABELCELL
147 case 0x0017: // NUMBERCELL
151 case 0x0018: // SMALLNUMCELL
155 case 0x0019: // FORMULACELL
156 Formulacell( nRecLen
);
159 case 0x001b: // extended attributes
166 case 2007: // ROW PRESENTATION
167 RowPresentation( nRecLen
);
170 case 14000: // NAMED SHEET
177 eRet
= SCERR_IMPORT_FORMAT
;
191 SAL_WARN_IF( nNextRec
< pIn
->Tell(), "sc.filter",
192 "*ImportLotus::Read(): Read too much..." );
194 pIn
->Seek( nNextRec
);
195 aPrgrsBar
.Progress();
198 // TODO: eliminate stupid names
199 SCTAB nTabs
= pD
->GetTableCount();
207 pD
->GetName( 0, aBaseName
);
208 aBaseName
= aBaseName
.copy(0, aBaseName
.getLength()-1);
210 for( nCnt
= 1 ; nCnt
< nTabs
; nCnt
++ )
212 SAL_WARN_IF( !pD
->HasTable( nCnt
), "sc.filter",
213 "-ImportLotus::Read(): Where is my table?!" );
214 pD
->GetName( nCnt
, aTabName
);
215 if( aTabName
== "temp" )
217 aTabName
= aBaseName
;
218 pD
->CreateValidTabName( aTabName
);
219 pD
->RenameTab( nCnt
, aTabName
);
227 ErrCode
ImportLotus::Read()
229 ErrCode eRet
= parse();
234 ErrCode
ImportLotus::Read(SvStream
& rIn
)
241 sal_uInt32 nNextRec
= 0;
242 ErrCode eRet
= ERRCODE_NONE
;
247 pIn
->Seek( nNextRec
);
250 ScfStreamProgressBar
aPrgrsBar( *pIn
, pD
->GetDocumentShell() );
251 LotusContext
&rContext
= aConv
.getContext();
254 pIn
->ReadUInt16( nOp
).ReadUInt16( nRecLen
);
256 if (!pIn
->good() || nNextRec
> SAL_MAX_UINT32
- nRecLen
- 4)
260 nNextRec
+= nRecLen
+ 4;
265 if( nRecLen
!= 26 || !BofFm3() )
268 eRet
= SCERR_IMPORT_FORMAT
;
274 SAL_WARN_IF( nTab
!= 0, "sc.filter",
275 "-ImportLotus::Read( SvStream& ): EOF twice!" );
279 case 174: // FONT_FACE
283 case 176: // FONT_TYPE
287 case 177: // FONT_YSIZE
293 rContext
.pLotusRoot
->maAttrTable
.Apply(rContext
.pLotusRoot
, static_cast<SCTAB
>(nExtTab
));
301 SAL_WARN_IF( nNextRec
< pIn
->Tell(), "sc.filter",
302 "*ImportLotus::Read(): Read too much..." );
303 pIn
->Seek( nNextRec
);
304 aPrgrsBar
.Progress();
308 rContext
.pLotusRoot
->maAttrTable
.Apply(rContext
.pLotusRoot
, static_cast<SCTAB
>(nExtTab
));
313 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportWKS(SvStream
& rStream
)
316 ScDocument aDocument
;
317 ScDocOptions aDocOpt
= aDocument
.GetDocOptions();
318 aDocOpt
.SetLookUpColRowNames(false);
319 aDocument
.SetDocOptions(aDocOpt
);
320 aDocument
.MakeTable(0);
321 aDocument
.EnableExecuteLink(false);
322 aDocument
.SetInsertingFromOtherDoc(true);
324 LotusContext aContext
;
325 ImportLotus
aLotusImport(aContext
, rStream
, &aDocument
, RTL_TEXTENCODING_ASCII_US
);
327 ErrCode eRet
= aLotusImport
.parse();
328 if (eRet
== ErrCode(0xFFFFFFFF))
331 eRet
= ScImportLotus123old(aContext
, rStream
, &aDocument
, RTL_TEXTENCODING_ASCII_US
);
334 return eRet
== ERRCODE_NONE
;
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */