[Libreoffice-commits] core.git: 2 commits - sc/inc sc/qa sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Mar 13 19:50:56 PDT 2014
sc/inc/document.hxx | 2
sc/qa/unit/data/xlsx/sheet-tab-color.xlsx |binary
sc/qa/unit/subsequent_export-test.cxx | 68 ++++++++++++++++++++++++++++++
sc/source/filter/excel/excdoc.cxx | 3 -
sc/source/filter/excel/excrecds.cxx | 24 +++++++---
sc/source/filter/inc/excrecds.hxx | 24 +++++++---
6 files changed, 105 insertions(+), 16 deletions(-)
New commits:
commit 90af4f50e8673975e63c928aa47fbc18eb160046
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Mar 13 22:46:18 2014 -0400
fdo#58307: Write export test for this to ensure it won't go away...
Change-Id: I01ebdfab7d6098402e2911713b0eb51e2003047c
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index d8b4d7c..a6af9fb 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -569,7 +569,7 @@ public:
SC_DLLPUBLIC bool SetCodeName( SCTAB nTab, const OUString& rName );
SC_DLLPUBLIC bool GetTable( const OUString& rName, SCTAB& rTab ) const;
- std::vector<OUString> GetAllTableNames() const;
+ SC_DLLPUBLIC std::vector<OUString> GetAllTableNames() const;
OUString GetCopyTabName(SCTAB nTab) const;
diff --git a/sc/qa/unit/data/xlsx/sheet-tab-color.xlsx b/sc/qa/unit/data/xlsx/sheet-tab-color.xlsx
new file mode 100644
index 0000000..896bc3b
Binary files /dev/null and b/sc/qa/unit/data/xlsx/sheet-tab-color.xlsx differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 90da87c..defacfb 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -87,6 +87,8 @@ public:
void testCellBordersXLS();
void testCellBordersXLSX();
+ void testSheetTabColorsXLSX();
+
void testSharedFormulaExportXLS();
void testSharedFormulaExportXLSX();
void testSharedFormulaStringResultExportXLSX();
@@ -114,6 +116,7 @@ public:
CPPUNIT_TEST(testSheetProtectionXLSX);
CPPUNIT_TEST(testCellBordersXLS);
CPPUNIT_TEST(testCellBordersXLSX);
+ CPPUNIT_TEST(testSheetTabColorsXLSX);
CPPUNIT_TEST(testSharedFormulaExportXLS);
CPPUNIT_TEST(testSharedFormulaExportXLSX);
CPPUNIT_TEST(testSharedFormulaStringResultExportXLSX);
@@ -1089,6 +1092,71 @@ void ScExportTest::testCellBordersXLSX()
testExcelCellBorders(XLSX);
}
+void ScExportTest::testSheetTabColorsXLSX()
+{
+ struct
+ {
+ bool checkContent( ScDocument* pDoc )
+ {
+
+ std::vector<OUString> aTabNames = pDoc->GetAllTableNames();
+
+ // green, red, blue, yellow (from left to right).
+ if (aTabNames.size() != 4)
+ {
+ cerr << "There should be exactly 4 sheets." << endl;
+ return false;
+ }
+
+ const char* pNames[] = { "Green", "Red", "Blue", "Yellow" };
+ for (size_t i = 0, n = SAL_N_ELEMENTS(pNames); i < n; ++i)
+ {
+ OUString aExpected = OUString::createFromAscii(pNames[i]);
+ if (aExpected != aTabNames[i])
+ {
+ cerr << "incorrect sheet name: expected='" << aExpected <<"', actual='" << aTabNames[i] << "'" << endl;
+ return false;
+ }
+ }
+
+ const ColorData aXclColors[] =
+ {
+ 0x0000B050, // green
+ 0x00FF0000, // red
+ 0x000070C0, // blue
+ 0x00FFFF00, // yellow
+ };
+
+ for (size_t i = 0, n = SAL_N_ELEMENTS(aXclColors); i < n; ++i)
+ {
+ if (aXclColors[i] != pDoc->GetTabBgColor(i).GetColor())
+ {
+ cerr << "wrong sheet color for sheet " << i << endl;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ } aTest;
+
+ ScDocShellRef xDocSh = loadDoc("sheet-tab-color.", XLSX);
+ CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocSh.Is());
+ ScDocument* pDoc = xDocSh->GetDocument();
+ bool bRes = aTest.checkContent(pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Failed on the initial content check.", bRes);
+
+ ScDocShellRef xDocSh2 = saveAndReload(xDocSh, XLSX);
+ CPPUNIT_ASSERT_MESSAGE("Failed to reload file.", xDocSh2.Is());
+ xDocSh->DoClose();
+ pDoc = xDocSh2->GetDocument();
+ bRes = aTest.checkContent(pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Failed on the content check after reload.", bRes);
+
+ xDocSh2->DoClose();
+}
+
void ScExportTest::testSharedFormulaExportXLS()
{
struct
commit 5063f31c248fd3c16115582a1e3aef182257a225
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Mar 13 21:49:04 2014 -0400
fdo#58307: Export sheet tab colors to xlsx.
And let's not re-use Biff's XclExpWsbool record class to export <SheetPr>
elements. That was a bit hacky...
Change-Id: Ia585f53d547af3d6840fce1b1244b60bb5076b07
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index 9cf433d..87b17aa 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -550,7 +550,8 @@ void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
Add( new ExcBof8 );
- Add( new XclExpWsbool( bFitToPages, mnScTab, &GetFilterManager() ) );
+ Color aTabColor = GetRoot().GetDoc().GetTabBgColor(mnScTab);
+ Add(new XclExpXmlSheetPr(bFitToPages, mnScTab, aTabColor, &GetFilterManager()));
// GUTS (count & size of outline icons)
aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 4c94850..b7e6df7 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -442,16 +442,17 @@ void XclExpCountry::WriteBody( XclExpStream& rStrm )
// XclExpWsbool ===============================================================
-XclExpWsbool::XclExpWsbool( bool bFitToPages, SCTAB nScTab, XclExpFilterManager* pManager )
+XclExpWsbool::XclExpWsbool( bool bFitToPages )
: XclExpUInt16Record( EXC_ID_WSBOOL, EXC_WSBOOL_DEFAULTFLAGS )
- , mnScTab( nScTab )
- , mpManager( pManager )
{
if( bFitToPages )
SetValue( GetValue() | EXC_WSBOOL_FITTOPAGE );
}
-void XclExpWsbool::SaveXml( XclExpXmlStream& rStrm )
+XclExpXmlSheetPr::XclExpXmlSheetPr( bool bFitToPages, SCTAB nScTab, const Color& rTabColor, XclExpFilterManager* pManager ) :
+ mnScTab(nScTab), mpManager(pManager), mbFitToPage(bFitToPages), maTabColor(rTabColor) {}
+
+void XclExpXmlSheetPr::SaveXml( XclExpXmlStream& rStrm )
{
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
rWorksheet->startElement( XML_sheetPr,
@@ -465,11 +466,18 @@ void XclExpWsbool::SaveXml( XclExpXmlStream& rStrm )
XML_filterMode, mpManager ? XclXmlUtils::ToPsz( mpManager->HasFilterMode( mnScTab ) ) : NULL,
// OOXTODO: XML_enableFormatConditionsCalculation,
FSEND );
- // OOXTODO: elements XML_tabColor, XML_outlinePr
- rWorksheet->singleElement( XML_pageSetUpPr,
+
+ // Note : the order of child elements is significant. Don't change the order.
+
+ // OOXTODO: XML_outlinePr
+
+ rWorksheet->singleElement(
+ XML_tabColor, XML_rgb, XclXmlUtils::ToOString(maTabColor).getStr(), FSEND);
+
+ rWorksheet->singleElement(XML_pageSetUpPr,
// OOXTODO: XML_autoPageBreaks,
- XML_fitToPage, XclXmlUtils::ToPsz( (GetValue() & EXC_WSBOOL_FITTOPAGE) != 0 ),
- FSEND );
+ XML_fitToPage, XclXmlUtils::ToPsz(mbFitToPage), FSEND);
+
rWorksheet->endElement( XML_sheetPr );
}
diff --git a/sc/source/filter/inc/excrecds.hxx b/sc/source/filter/inc/excrecds.hxx
index 796e624..90a2a12 100644
--- a/sc/source/filter/inc/excrecds.hxx
+++ b/sc/source/filter/inc/excrecds.hxx
@@ -24,6 +24,7 @@
#include <rtl/ustring.hxx>
#include <svl/zforlist.hxx>
#include <tools/solar.h>
+#include <tools/color.hxx>
#include <vcl/vclenum.hxx>
@@ -325,15 +326,26 @@ private:
class XclExpWsbool : public XclExpUInt16Record
{
public:
- explicit XclExpWsbool( bool bFitToPages, SCTAB nScTab = -1, XclExpFilterManager* pManager = NULL );
-
- virtual void SaveXml( XclExpXmlStream& rStrm );
-private:
- SCTAB mnScTab;
- XclExpFilterManager* mpManager;
+ explicit XclExpWsbool( bool bFitToPages );
};
+/**
+ * Save sheetPr element and its children for xlsx export.
+ */
+class XclExpXmlSheetPr : public XclExpRecordBase
+{
+public:
+ explicit XclExpXmlSheetPr(
+ bool bFitToPages, SCTAB nScTab, const Color& rTabColor, XclExpFilterManager* pManager );
+
+ virtual void SaveXml( XclExpXmlStream& rStrm );
+private:
+ SCTAB mnScTab;
+ XclExpFilterManager* mpManager;
+ bool mbFitToPage;
+ Color maTabColor;
+};
class XclExpFiltermode : public XclExpEmptyRecord
More information about the Libreoffice-commits
mailing list