1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
//------------------------------------------------------------------------
#include "scitems.hxx"
#include <comphelper/processfactory.hxx>
#include <svx/svdobj.hxx>
#include <svx/svditer.hxx>
#include <svx/svdpage.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <svl/intitem.hxx>
#include <svl/zformat.hxx>
#include <sot/storage.hxx>
#include <sfx2/objsh.hxx>
#include <tools/urlobj.hxx>
#include <rtl/ustring.hxx>
#include "cell.hxx"
#include "dociter.hxx"
#include "document.hxx"
#include "rangenam.hxx"
#include "dbdata.hxx"
#include "global.hxx"
#include "globstr.hrc"
#include "progress.hxx"
#include "conditio.hxx"
#include "dpobject.hxx"
#include "attrib.hxx"
#include "scextopt.hxx"
#include "stlsheet.hxx"
#include "stlpool.hxx"
#include "olinetab.hxx"
#include "unonames.hxx"
#include "convuno.hxx"
#include "patattr.hxx"
#include "docoptio.hxx"
#include "tabprotection.hxx"
#include "excdoc.hxx"
#include "namebuff.hxx"
#include "xcl97rec.hxx"
#include "xcl97esc.hxx"
#include "xetable.hxx"
#include "xelink.hxx"
#include "xename.hxx"
#include "xepage.hxx"
#include "xeview.hxx"
#include "xecontent.hxx"
#include "xeescher.hxx"
#include "xepivot.hxx"
#include "XclExpChangeTrack.hxx"
#include <math.h>
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <oox/token/tokens.hxx>
#include <boost/shared_ptr.hpp>
using ::rtl::OString;
using namespace oox;
static String lcl_GetVbaTabName( SCTAB n )
{
String aRet( RTL_CONSTASCII_USTRINGPARAM( "__VBA__" ) );
aRet += String::CreateFromInt32( static_cast<sal_uInt16>(n) );
return aRet;
}
static void lcl_AddBookviews( XclExpRecordList<>& aRecList, ExcTable& self )
{
aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_bookViews ) );
aRecList.AppendNewRecord( new XclExpWindow1( self.GetRoot() ) );
aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_bookViews ) );
}
static void lcl_AddCalcPr( XclExpRecordList<>& aRecList, ExcTable& self )
{
ScDocument& rDoc = self.GetDoc();
aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_calcPr ) );
// OOXTODO: calcCompleted, calcId, calcMode, calcOnSave,
// concurrentCalc, concurrentManualCount,
// forceFullCalc, fullCalcOnLoad, fullPrecision
aRecList.AppendNewRecord( new XclCalccount( rDoc ) );
aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
aRecList.AppendNewRecord( new XclIteration( rDoc ) );
aRecList.AppendNewRecord( new XclDelta( rDoc ) );
aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_calcPr
}
static void lcl_AddWorkbookProtection( XclExpRecordList<>& aRecList, ExcTable& self )
{
aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_workbookProtection ) );
const ScDocProtection* pProtect = self.GetDoc().GetDocProtection();
if (pProtect && pProtect->isProtected())
{
aRecList.AppendNewRecord( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
aRecList.AppendNewRecord( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
aRecList.AppendNewRecord( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
}
aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_workbookProtection
}
static void lcl_AddScenariosAndFilters( XclExpRecordList<>& aRecList, const XclExpRoot& rRoot, SCTAB nScTab )
{
// Scenarios
aRecList.AppendNewRecord( new ExcEScenarioManager( rRoot, nScTab ) );
// filter
aRecList.AppendRecord( rRoot.GetFilterManager().CreateRecord( nScTab ) );
}
ExcTable::ExcTable( const XclExpRoot& rRoot ) :
XclExpRoot( rRoot ),
mnScTab( SCTAB_GLOBAL ),
nExcTab( EXC_NOTAB ),
pTabNames( new NameBuffer( 0, 16 ) )
{
}
ExcTable::ExcTable( const XclExpRoot& rRoot, SCTAB nScTab ) :
XclExpRoot( rRoot ),
mnScTab( nScTab ),
nExcTab( rRoot.GetTabInfo().GetXclTab( nScTab ) ),
pTabNames( new NameBuffer( 0, 16 ) )
{
}
ExcTable::~ExcTable()
{
delete pTabNames;
}
void ExcTable::Add( XclExpRecordBase* pRec )
{
OSL_ENSURE( pRec, "-ExcTable::Add(): pRec ist NULL!" );
aRecList.AppendNewRecord( pRec );
}
void ExcTable::FillAsHeader( ExcBoundsheetList& rBoundsheetList )
{
InitializeGlobals();
RootData& rR = GetOldRoot();
ScDocument& rDoc = GetDoc();
XclExpTabInfo& rTabInfo = GetTabInfo();
if ( GetBiff() <= EXC_BIFF5 )
Add( new ExcBofW );
else
Add( new ExcBofW8 );
SCTAB nC;
rtl::OUString aTmpString;
SCTAB nScTabCount = rTabInfo.GetScTabCount();
sal_uInt16 nExcTabCount = rTabInfo.GetXclTabCount();
sal_uInt16 nCodenames = static_cast< sal_uInt16 >( GetExtDocOptions().GetCodeNameCount() );
SfxObjectShell* pShell = GetDocShell();
sal_uInt16 nWriteProtHash = pShell ? pShell->GetModifyPasswordHash() : 0;
bool bRecommendReadOnly = pShell && pShell->IsLoadReadonly();
if( (nWriteProtHash > 0) || bRecommendReadOnly )
Add( new XclExpEmptyRecord( EXC_ID_WRITEPROT ) );
// TODO: correct codepage for BIFF5?
sal_uInt16 nCodePage = XclTools::GetXclCodePage( (GetBiff() <= EXC_BIFF5) ? RTL_TEXTENCODING_MS_1252 : RTL_TEXTENCODING_UNICODE );
if( GetBiff() <= EXC_BIFF5 )
{
Add( new XclExpEmptyRecord( EXC_ID_INTERFACEHDR ) );
Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
Add( new XclExpEmptyRecord( EXC_ID_TOOLBARHDR ) );
Add( new XclExpEmptyRecord( EXC_ID_TOOLBAREND ) );
Add( new XclExpEmptyRecord( EXC_ID_INTERFACEEND ) );
Add( new ExcDummy_00 );
}
else
{
if( IsDocumentEncrypted() )
Add( new XclExpFileEncryption( GetRoot() ) );
Add( new XclExpInterfaceHdr( nCodePage ) );
Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
Add( new XclExpInterfaceEnd );
Add( new XclExpWriteAccess );
}
Add( new XclExpFileSharing( GetRoot(), nWriteProtHash, bRecommendReadOnly ) );
Add( new XclExpUInt16Record( EXC_ID_CODEPAGE, nCodePage ) );
if( GetBiff() == EXC_BIFF8 )
{
Add( new XclExpBoolRecord( EXC_ID_DSF, false ) );
Add( new XclExpEmptyRecord( EXC_ID_XL9FILE ) );
rR.pTabId = new XclExpChTrTabId( Max( nExcTabCount, nCodenames ) );
Add( rR.pTabId );
if( HasVbaStorage() )
{
Add( new XclObproj );
const String& rCodeName = GetExtDocOptions().GetDocSettings().maGlobCodeName;
if( rCodeName.Len() )
Add( new XclCodename( rCodeName ) );
}
}
Add( new XclExpUInt16Record( EXC_ID_FNGROUPCOUNT, 14 ) );
// erst Namen- und Tabellen-Eintraege aufbauen
String aName;
for( nC = 0 ; nC < nScTabCount ; nC++ )
if( rTabInfo.IsExportTab( nC ) )
{
rDoc.GetName( nC, aTmpString );
*pTabNames << aTmpString;
}
if ( GetBiff() <= EXC_BIFF5 )
{
// global link table: EXTERNCOUNT, EXTERNSHEET, NAME
aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
}
// document protection options
if( GetOutput() == EXC_OUTPUT_BINARY )
{
lcl_AddWorkbookProtection( aRecList, *this );
if( GetBiff() == EXC_BIFF8 )
{
Add( new XclExpProt4Rev );
Add( new XclExpProt4RevPass );
}
lcl_AddBookviews( aRecList, *this );
}
Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
if ( GetBiff() == EXC_BIFF8 && GetOutput() != EXC_OUTPUT_BINARY )
{
Add( new XclExpBoolRecord(0x0040, false, XML_backupFile ) ); // BACKUP
Add( new XclExpBoolRecord(0x008D, false, XML_showObjects ) ); // HIDEOBJ
}
if ( GetBiff() == EXC_BIFF8 )
{
Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
}
if( GetBiff() <= EXC_BIFF5 )
{
Add( new ExcDummy_040 );
Add( new Exc1904( rDoc ) );
Add( new ExcDummy_041 );
}
else
{
// BIFF8
Add( new Exc1904( rDoc ) );
Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
// OOXTODO: The following /workbook/workbookPr attributes are mapped
// to various BIFF records that are not currently supported:
//
// XML_allowRefreshQuery: QSISTAG 802h: fEnableRefresh
// XML_autoCompressPictures: COMPRESSPICTURES 89Bh: fAutoCompressPictures
// XML_checkCompatibility: COMPAT12 88Ch: fNoCompatChk
// XML_codeName: "Calc"
// XML_defaultThemeVersion: ???
// XML_filterPrivacy: BOOKEXT 863h: fFilterPrivacy
// XML_hidePivotFieldList: BOOKBOOL DAh: fHidePivotTableFList
// XML_promptedSolutions: BOOKEXT 863h: fBuggedUserAboutSolution
// XML_publishItems: NAMEPUBLISH 893h: fPublished
// XML_saveExternalLinkValues: BOOKBOOL DAh: fNoSavSupp
// XML_showBorderUnselectedTables: BOOKBOOL DAh: fHideBorderUnsels
// XML_showInkAnnotation: BOOKEXT 863h: fShowInkAnnotation
// XML_showPivotChart: PIVOTCHARTBITS 859h: fGXHide??
// XML_updateLinks: BOOKBOOL DAh: grbitUpdateLinks
}
Add( new XclExpXmlEndSingleElementRecord() ); // XML_workbookPr
// Formatting: FONT, FORMAT, XF, STYLE, PALETTE
if( GetOutput() != EXC_OUTPUT_BINARY )
{
aRecList.AppendNewRecord( new XclExpXmlStyleSheet( *this ) );
}
else
{
aRecList.AppendRecord( CreateRecord( EXC_ID_FONTLIST ) );
aRecList.AppendRecord( CreateRecord( EXC_ID_FORMATLIST ) );
aRecList.AppendRecord( CreateRecord( EXC_ID_XFLIST ) );
aRecList.AppendRecord( CreateRecord( EXC_ID_PALETTE ) );
}
if( GetBiff() <= EXC_BIFF5 )
{
// Bundlesheet
for( nC = 0 ; nC < nScTabCount ; nC++ )
if( rTabInfo.IsExportTab( nC ) )
{
ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet( rR, nC ) );
aRecList.AppendRecord( xBoundsheet );
rBoundsheetList.AppendRecord( xBoundsheet );
}
}
else
{
// Pivot Cache
GetPivotTableManager().CreatePivotTables();
aRecList.AppendRecord( GetPivotTableManager().CreatePivotCachesRecord() );
// Change tracking
if( rDoc.GetChangeTrack() )
{
rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
Add( rR.pUserBViewList );
}
// Natural Language Formulas Flag
aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_USESELFS, GetDoc().GetDocOptions().IsLookUpColRowNames() ) );
if( GetOutput() != EXC_OUTPUT_BINARY )
{
lcl_AddWorkbookProtection( aRecList, *this );
lcl_AddBookviews( aRecList, *this );
}
// Bundlesheet
aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_sheets ) );
for( nC = 0 ; nC < nScTabCount ; nC++ )
if( rTabInfo.IsExportTab( nC ) )
{
ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
aRecList.AppendRecord( xBoundsheet );
rBoundsheetList.AppendRecord( xBoundsheet );
}
aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_sheets ) );
for( SCTAB nAdd = 0; nC < static_cast<SCTAB>(nCodenames) ; nC++, nAdd++ )
{
aTmpString = lcl_GetVbaTabName( nAdd );
ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( aTmpString ) );
aRecList.AppendRecord( xBoundsheet );
rBoundsheetList.AppendRecord( xBoundsheet );
}
// COUNTRY - in BIFF8 in workbook globals
Add( new XclExpCountry( GetRoot() ) );
// link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
if( GetOutput() != EXC_OUTPUT_BINARY )
lcl_AddCalcPr( aRecList, *this );
Add( new XclExpRecalcId );
// MSODRAWINGGROUP per-document data
aRecList.AppendRecord( GetObjectManager().CreateDrawingGroup() );
// Shared string table: SST, EXTSST
aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
Add( new XclExpBookExt );
}
Add( new ExcEof );
}
void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
{
InitializeTable( mnScTab );
RootData& rR = GetOldRoot();
XclBiff eBiff = GetBiff();
ScDocument& rDoc = GetDoc();
OSL_ENSURE( (mnScTab >= 0L) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
// create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
if( eBiff == EXC_BIFF8 )
GetObjectManager().StartSheet();
// cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
if( GetOutput() != EXC_OUTPUT_BINARY )
{
FillAsXmlTable( nCodeNameIdx );
return;
}
// WSBOOL needs data from page settings, create it here, add it later
boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
if( eBiff <= EXC_BIFF5 )
{
Add( new ExcBof );
Add( new ExcDummy_02a );
}
else
{
Add( new ExcBof8 );
lcl_AddCalcPr( aRecList, *this );
}
// GUTS (count & size of outline icons)
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
// DEFROWHEIGHT, created by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
// COUNTRY - in BIFF5/7 in every worksheet
if( eBiff <= EXC_BIFF5 )
Add( new XclExpCountry( GetRoot() ) );
Add( new XclExpWsbool( bFitToPages ) );
// page settings (SETUP and various other records)
aRecList.AppendRecord( xPageSett );
const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
if (pTabProtect && pTabProtect->isProtected())
{
Add( new XclExpProtection(true) );
Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
}
// local link table: EXTERNCOUNT, EXTERNSHEET
if( eBiff <= EXC_BIFF5 )
aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
if ( eBiff == EXC_BIFF8 )
lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
// cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
aRecList.AppendRecord( mxCellTable );
// MERGEDCELLS record, generated by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
// label ranges
if( eBiff == EXC_BIFF8 )
Add( new XclExpLabelranges( GetRoot() ) );
// data validation (DVAL and list of DV records), generated by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
if( eBiff == EXC_BIFF8 )
{
// all MSODRAWING and OBJ stuff of this sheet goes here
aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
// pivot tables
aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
}
// list of NOTE records, generated by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_NOTE ) );
// sheet view settings: WINDOW2, SCL, PANE, SELECTION
aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
if( eBiff == EXC_BIFF8 )
{
// sheet protection options
Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
// web queries
Add( new XclExpWebQueryBuffer( GetRoot() ) );
// conditional formats
Add( new XclExpCondFormatBuffer( GetRoot() ) );
if( HasVbaStorage() )
if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
}
// list of HLINK records, generated by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_HLINK ) );
// change tracking
if( rR.pUserBViewList )
{
XclExpUserBViewList::const_iterator iter;
for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter)
{
Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
Add( new XclExpUsersViewEnd );
}
}
// EOF
Add( new ExcEof );
}
void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
{
RootData& rR = GetOldRoot();
// WSBOOL needs data from page settings, create it here, add it later
boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
Add( new ExcBof8 );
Add( new XclExpWsbool( bFitToPages, mnScTab, &GetFilterManager() ) );
// GUTS (count & size of outline icons)
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
// DEFROWHEIGHT, created by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID3_DIMENSIONS ) );
// sheet view settings: WINDOW2, SCL, PANE, SELECTION
aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
// cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
aRecList.AppendRecord( mxCellTable );
// label ranges
Add( new XclExpLabelranges( GetRoot() ) );
// DFF not needed in MSOOXML export
// GetObjectManager().AddSdrPage();
// //! close Escher group shape and ESCHER_DgContainer
// //! opened by XclExpObjList ctor MSODRAWING
// rR.pObjRecs->EndSheet();
// // all MSODRAWING and OBJ stuff of this sheet goes here
// Add( rR.pObjRecs );
// pivot tables
aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
// list of NOTE records, generated by the cell table
XclExpRecordRef xNotes = mxCellTable->CreateRecord( EXC_ID_NOTE );
XclExpRecordList< XclExpNote >* xNoteList = dynamic_cast< XclExpRecordList< XclExpNote >* >( xNotes.get() );
if( xNoteList != NULL && !xNoteList->IsEmpty() )
aRecList.AppendNewRecord( new XclExpComments( mnScTab, *xNoteList ) );
// web queries
Add( new XclExpWebQueryBuffer( GetRoot() ) );
lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
// MERGEDCELLS record, generated by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
// conditional formats
Add( new XclExpCondFormatBuffer( GetRoot() ) );
if( HasVbaStorage() )
if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
// data validation (DVAL and list of DV records), generated by the cell table
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
// list of HLINK records, generated by the cell table
XclExpRecordRef xHyperlinks = mxCellTable->CreateRecord( EXC_ID_HLINK );
XclExpHyperlinkList* xHyperlinkList = dynamic_cast<XclExpHyperlinkList*>(xHyperlinks.get());
if( xHyperlinkList != NULL && !xHyperlinkList->IsEmpty() )
{
aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_hyperlinks ) );
aRecList.AppendRecord( xHyperlinks );
aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_hyperlinks ) );
}
aRecList.AppendRecord( xPageSett );
// change tracking
if( rR.pUserBViewList )
{
XclExpUserBViewList::const_iterator iter;
for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter )
{
Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
Add( new XclExpUsersViewEnd );
}
}
// all MSODRAWING and OBJ stuff of this sheet goes here
aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
// EOF
Add( new ExcEof );
}
void ExcTable::FillAsEmptyTable( SCTAB nCodeNameIdx )
{
InitializeTable( mnScTab );
if( HasVbaStorage() && (nCodeNameIdx < GetExtDocOptions().GetCodeNameCount()) )
{
if( GetBiff() <= EXC_BIFF5 )
{
Add( new ExcBof );
}
else
{
Add( new ExcBof8 );
Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
}
// sheet view settings: WINDOW2, SCL, PANE, SELECTION
aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
Add( new ExcEof );
}
}
void ExcTable::Write( XclExpStream& rStrm )
{
SetCurrScTab( mnScTab );
if( mxCellTable.get() )
mxCellTable->Finalize();
aRecList.Save( rStrm );
}
void ExcTable::WriteXml( XclExpXmlStream& rStrm )
{
if (GetTabInfo().IsExportTab( mnScTab ) )
{
// worksheet export
String sSheetName = XclXmlUtils::GetStreamName( "xl/", "worksheets/sheet", mnScTab+1 );
sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetStreamForPath( sSheetName );
rStrm.PushStream( pWorksheet );
pWorksheet->startElement( XML_worksheet,
XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
FSEND );
}
SetCurrScTab( mnScTab );
if( mxCellTable.get() )
mxCellTable->Finalize();
aRecList.SaveXml( rStrm );
if (GetTabInfo().IsExportTab( mnScTab ) )
{
rStrm.GetCurrentStream()->endElement( XML_worksheet );
rStrm.PopStream();
}
}
ExcDocument::ExcDocument( const XclExpRoot& rRoot ) :
XclExpRoot( rRoot ),
aHeader( rRoot ),
pExpChangeTrack( NULL )
{
}
ExcDocument::~ExcDocument()
{
maTableList.RemoveAllRecords(); //! for the following assertion
delete pExpChangeTrack;
}
void ExcDocument::ReadDoc( void )
{
InitializeConvert();
aHeader.FillAsHeader( maBoundsheetList );
SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
SCTAB nCodeNameIdx = 0, nCodeNameCount = GetExtDocOptions().GetCodeNameCount();
for( ; nScTab < nScTabCount; ++nScTab )
{
if( GetTabInfo().IsExportTab( nScTab ) )
{
ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
maTableList.AppendRecord( xTab );
xTab->FillAsTable( nCodeNameIdx );
++nCodeNameIdx;
}
}
for( ; nCodeNameIdx < nCodeNameCount; ++nScTab, ++nCodeNameIdx )
{
ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
maTableList.AppendRecord( xTab );
xTab->FillAsEmptyTable( nCodeNameIdx );
}
if ( GetBiff() == EXC_BIFF8 )
{
// complete temporary Escher stream
GetObjectManager().EndDocument();
// change tracking
if ( GetDoc().GetChangeTrack() )
pExpChangeTrack = new XclExpChangeTrack( GetRoot() );
}
}
void ExcDocument::Write( SvStream& rSvStrm )
{
if( !maTableList.IsEmpty() )
{
InitializeSave();
XclExpStream aXclStrm( rSvStrm, GetRoot() );
aHeader.Write( aXclStrm );
OSL_ENSURE( maTableList.GetSize() == maBoundsheetList.GetSize(),
"ExcDocument::Write - different number of sheets and BOUNDSHEET records" );
for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
{
// set current stream position in BOUNDSHEET record
ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
if( xBoundsheet.get() )
xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
// write the table
maTableList.GetRecord( nTab )->Write( aXclStrm );
}
// write the table stream positions into the BOUNDSHEET records
for( size_t nBSheet = 0, nBSheetCount = maBoundsheetList.GetSize(); nBSheet < nBSheetCount; ++nBSheet )
maBoundsheetList.GetRecord( nBSheet )->UpdateStreamPos( aXclStrm );
}
if( pExpChangeTrack )
pExpChangeTrack->Write();
}
void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
{
SfxObjectShell* pDocShell = GetDocShell();
using namespace ::com::sun::star;
uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
rStrm.exportDocumentProperties( xDocProps );
sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
rWorkbook->startElement( XML_workbook,
XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
FSEND );
rWorkbook->singleElement( XML_fileVersion,
XML_appName, "Calc",
// OOXTODO: XML_codeName
// OOXTODO: XML_lastEdited
// OOXTODO: XML_lowestEdited
// OOXTODO: XML_rupBuild
FSEND );
if( !maTableList.IsEmpty() )
{
InitializeSave();
aHeader.WriteXml( rStrm );
for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
{
// write the table
maTableList.GetRecord( nTab )->WriteXml( rStrm );
}
}
if( pExpChangeTrack )
pExpChangeTrack->WriteXml( rStrm );
rWorkbook->endElement( XML_workbook );
rWorkbook.reset();
rStrm.commitStorage();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|