/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
CPPUNIT_TEST_FIXTURE(ScExportTest, testFontColorWithMultipleAttributesDefined)
{ // Related: TDF #113271 // Test font color where "rgb" and "theme" attribute is defined and // is imported and exported correctly. Theme should have priority, // so LO is fine to ignore "rgb" at export.
createScDoc("xlsx/tdf113271.xlsx");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pDoc = parseExport(u"xl/styles.xml"_ustr);
CPPUNIT_ASSERT(pDoc);
// Expect "theme" attribute to be set correctly
assertXPath(pDoc, "/x:styleSheet/x:fonts/x:font[1]/x:color", "theme", u"1"); // We don't export "rgb" attribute
assertXPathNoAttribute(pDoc, "/x:styleSheet/x:fonts/x:font[1]/x:color", "rgb"); // Just making sure the checked font is the correct one
assertXPath(pDoc, "/x:styleSheet/x:fonts/x:font[1]/x:name", "val", u"Calibri");
}
// Document is saved to the temporary directory, relative path should be different than original one
CPPUNIT_ASSERT(sTarget != "../xls/bug-fixes.xls");
}
// Excel can't open corrupt file if the list is longer than 255 characters
std::vector<ScTypedStrData> aList;
pData->FillSelectionList(aList, ScAddress(0, 1, 1));
CPPUNIT_ASSERT_EQUAL(size_t(18), aList.size());
CPPUNIT_ASSERT_EQUAL(u"18 Missis"_ustr, aList[17].GetString());
}
// we can't assume that the user entered the password; check that we // round-trip the password as-is
save(u"calc8"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='vbnhxyBKtPHCA1wB21zG1Oha8ZA=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha1']");
assertXPath(pXmlDoc, "//table:table[@table:protected='true' and " "@table:protection-key='vbnhxyBKtPHCA1wB21zG1Oha8ZA=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha1']");
}
// we can't assume that the user entered the password; check that we // round-trip the password as-is
save(u"calc8"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='nLHas0RIwepGDaH4c2hpyIUvIS8=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha1']");
assertXPath(pXmlDoc, "//table:table[@table:protected='true' and " "@table:protection-key='nLHas0RIwepGDaH4c2hpyIUvIS8=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha1']");
}
// we can't assume that the user entered the password; check that we // round-trip the password as-is
save(u"calc8"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(
pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='1tnJohagR2T0yF/v69hLPuumSTsj32CumW97nkKGuSQ=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha256']");
assertXPath(
pXmlDoc, "//table:table[@table:protected='true' and " "@table:protection-key='1tnJohagR2T0yF/v69hLPuumSTsj32CumW97nkKGuSQ=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha256']");
}
// we can't assume that the user entered the password; check that we // round-trip the password as-is
save(u"calc8"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(
pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='1tnJohagR2T0yF/v69hLPuumSTsj32CumW97nkKGuSQ=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha256']");
assertXPath(
pXmlDoc, "//table:table[@table:protected='true' and " "@table:protection-key='1tnJohagR2T0yF/v69hLPuumSTsj32CumW97nkKGuSQ=' and " "@table:protection-key-digest-algorithm='http://www.w3.org/2000/09/xmldsig#sha256']");
}
// we can't assume that the user entered the password; check that we // round-trip the password as-is
save(u"calc8"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(
pXmlDoc, "//office:spreadsheet[@table:structure-protected='true' and " "@table:protection-key='OX3WkEe79fv1PE+FUmfOLdwVoqI=' and " "@table:protection-key-digest-algorithm='http://docs.oasis-open.org/office/ns/table/" "legacy-hash-excel' and " "@loext:protection-key-digest-algorithm-2='http://www.w3.org/2000/09/xmldsig#sha1']");
assertXPath(
pXmlDoc, "//table:table[@table:protected='true' and " "@table:protection-key='OX3WkEe79fv1PE+FUmfOLdwVoqI=' and " "@table:protection-key-digest-algorithm='http://docs.oasis-open.org/office/ns/table/" "legacy-hash-excel' and " "@loext:protection-key-digest-algorithm-2='http://www.w3.org/2000/09/xmldsig#sha1']");
}
CPPUNIT_TEST_FIXTURE(ScExportTest, testCommentExportXLSX)
{ //tdf#104729 FILESAVE OpenOffice do not save author of the comment during export to .xlsx
createScDoc("ods/comment.ods");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pComments = parseExport(u"xl/comments1.xml"_ustr);
CPPUNIT_ASSERT(pComments);
//tdf#117274 fix MSO interoperability with the secret VML shape type id
assertXPath(pVmlDrawing, "/xml/v:shapetype", "id", u"_x0000_t202");
assertXPath(pVmlDrawing, "/xml/v:shape", "type", u"#_x0000_t202");
}
CPPUNIT_TEST_FIXTURE(ScExportTest, testCommentExportXLSX_2_XLSX)
{ //tdf#117287 FILESAVE XLSX: Comments always disappear after opening the exported XLSX file with Excel
createScDoc("xlsx/tdf117287_comment.xlsx");
#if HAVE_MORE_FONTS
CPPUNIT_TEST_FIXTURE(ScExportTest, testCustomColumnWidthExportXLSX)
{ //tdf#100946 FILESAVE Excel on macOS ignored column widths in XLSX last saved by LO
createScDoc("ods/custom_column_width.ods");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// tdf#124741: check that we export default width, otherwise the skipped columns would have // wrong width. Previously defaultColWidth attribute was missing double nDefWidth
= getXPath(pSheet, "/x:worksheet/x:sheetFormatPr", "defaultColWidth").toDouble();
CPPUNIT_ASSERT_DOUBLES_EQUAL(11.53515625, nDefWidth, 0.01);
// First column, has everything default (width in Calc: 1280), skipped
CPPUNIT_TEST_FIXTURE(ScExportTest, testXfDefaultValuesXLSX)
{ //tdf#70565 FORMATTING: User Defined Custom Formatting is not applied during importing XLSX documents
createScDoc("xlsx/xf_default_values.xlsx");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/styles.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// cellStyleXfs don't need xfId, so we need to make sure it is not saved
assertXPathNoAttribute(pSheet, "/x:styleSheet/x:cellStyleXfs/x:xf[1]", "xfId");
// Because numFmtId fontId fillId borderId xfId are not existing during import // it should be created during export, with values set to "0"
assertXPath(pSheet, "/x:styleSheet/x:cellXfs/x:xf[1]", "xfId", u"0");
assertXPath(pSheet, "/x:styleSheet/x:cellXfs/x:xf[2]", "xfId", u"0");
assertXPath(pSheet, "/x:styleSheet/x:cellXfs/x:xf[3]", "xfId", u"0");
assertXPath(pSheet, "/x:styleSheet/x:cellXfs/x:xf[4]", "xfId", u"0");
// We expected that exactly 15 cellXfs:xf Nodes will be produced
assertXPath(pSheet, "/x:styleSheet/x:cellXfs/x:xf", 14);
}
CPPUNIT_TEST_FIXTURE(ScExportTest, testColumnWidthResaveXLSX)
{ // tdf#91475 FILESAVE: Column width is not preserved in XLSX / after round trip. // Test if after resave .xlsx file, columns width is identical with previous one
createScDoc("xlsx/different-column-width-excel2010.xlsx");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// In original Excel document the width is "24"
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "width", u"24");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "customWidth", u"true");
// In original Excel document the width is "12"
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "width", u"12");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "customWidth", u"true");
// In original Excel document the width is "6"
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "width", u"6");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "customWidth", u"true");
// In original Excel document the width is "1"
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "width", u"1");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "customWidth", u"true");
// In original Excel document the width is "250"
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "width", u"250");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "customWidth", u"true");
#if HAVE_MORE_FONTS
CPPUNIT_TEST_FIXTURE(ScExportTest, testColumnWidthExportFromODStoXLSX)
{ // tdf#91475 FILESAVE: Column width is not preserved in XLSX / after round trip. // Test if after export .ods to .xlsx format, displayed columns width // is identical with previous (.ods) one
CPPUNIT_TEST_FIXTURE(ScExportTest, testOutlineExportXLSX)
{ //tdf#100347 FILESAVE FILEOPEN after exporting to .xlsx format grouping are lost //tdf#51524 FILESAVE .xlsx and.xls looses width information for hidden/collapsed grouped columns
createScDoc("ods/outline.ods");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// Maximum Outline Row is 4 for this document
assertXPath(pSheet, "/x:worksheet/x:sheetFormatPr", "outlineLevelRow", u"4"); // Maximum Outline Column is 4 for this document
assertXPath(pSheet, "/x:worksheet/x:sheetFormatPr", "outlineLevelCol", u"4");
// First XML node, creates two columns (from min=1 to max=2)
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "hidden", u"false");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "outlineLevel", u"1");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "collapsed", u"false");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "min", u"1");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "max", u"2");
// Column 4 has custom width and it is hidden. We need to make sure that it is created
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "hidden", u"true");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "outlineLevel", u"2");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "collapsed", u"false");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "min", u"4");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "max", u"4");
// Column 8 has custom width and it is hidden. We need to make sure that it is created
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "hidden", u"true");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "outlineLevel", u"4");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "collapsed", u"false");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "min", u"8");
assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "max", u"8");
CPPUNIT_TEST_FIXTURE(ScExportTest, testHiddenEmptyRowsXLSX)
{ //tdf#98106 FILESAVE: Hidden and empty rows became visible when export to .XLSX
createScDoc("ods/hidden-empty-rows.ods");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
CPPUNIT_TEST_FIXTURE(ScExportTest, testHiddenEmptyColsODS)
{ //tdf#98106 FILESAVE: Hidden and empty rows became visible when export to .XLSX
createScDoc("ods/tdf128895_emptyHiddenCols.ods");
CPPUNIT_TEST_FIXTURE(ScExportTest, testLandscapeOrientationXLSX)
{ //tdf#48767 - Landscape page orientation is not loaded from .xlsx format with MS Excel, after export with Libre Office
createScDoc("ods/hidden-empty-rows.ods");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// the usePrinterDefaults cannot be saved to allow opening sheets in Landscape mode via MS Excel
assertXPathNoAttribute(pSheet, "/x:worksheet/x:pageSetup", "usePrinterDefaults");
assertXPath(pSheet, "/x:worksheet/x:pageSetup", "orientation", u"landscape");
}
staticconst TestParam::RowData EmptyRepeatRowData[] = { // rows 0-4, 5-10, 17-20 are all set at various // heights, there is no content in the rows, there // was a bug where only the first row ( of repeated rows ) // was set after export
{ 0, 4, 0, 529, 0, false },
{ 5, 10, 0, 1058, 0, false },
{ 17, 20, 0, 1767, 0, false },
};
TestParam aTestValues[] = { // Checks that some distributed ( non-empty ) heights remain set after export (roundtrip) // additionally there is effectively a default row height ( 5.29 mm ). So we test the // unset rows at the end of the document to ensure the effective xlsx default height // is set there too.
{ u"xlsx/miscrowheights.xlsx", u"Calc Office Open XML"_ustr, SAL_N_ELEMENTS(DfltRowData),
DfltRowData }, // Checks that some distributed ( non-empty ) heights remain set after export (to xls)
{ u"xlsx/miscrowheights.xlsx", u"MS Excel 97"_ustr, SAL_N_ELEMENTS(DfltRowData),
DfltRowData }, // Checks that repeated rows ( of various heights ) remain set after export ( to xlsx )
{ u"ods/miscemptyrepeatedrowheights.ods", u"Calc Office Open XML"_ustr,
SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData }, // Checks that repeated rows ( of various heights ) remain set after export ( to xls )
{ u"ods/miscemptyrepeatedrowheights.ods", u"MS Excel 97"_ustr,
SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData },
};
miscRowHeightsTest(aTestValues, SAL_N_ELEMENTS(aTestValues));
}
CPPUNIT_TEST_FIXTURE(ScExportTest, testNamedRangeBugfdo62729)
{ #if !defined(MACOSX) // FIXME: infinite loop on jenkins' mac
createScDoc("ods/fdo62729.ods");
ScDocument* pDoc = getScDoc();
ScRangeName* pNames = pDoc->GetRangeName(); //should be just a single named range
CPPUNIT_ASSERT_EQUAL(size_t(1), pNames->size());
pDoc->DeleteTab(0); //should be still a single named range
CPPUNIT_ASSERT_EQUAL(size_t(1), pNames->size());
saveAndReload(u"calc8"_ustr);
pDoc = getScDoc();
pNames = pDoc->GetRangeName(); //after reload should still have a named range
CPPUNIT_ASSERT_EQUAL(size_t(1), pNames->size()); #endif
}
if (pAttr->maAttributes.size() != 1 || !isEscapement(*pAttr, -32, 66)) returnfalse;
returntrue;
}
bool checkB10(const EditTextObject* pText) const
{ if (!pText) returnfalse;
if (pText->GetParagraphCount() != 1) returnfalse;
if (pText->GetText(0) != "BLUE AUTO") returnfalse;
std::vector<editeng::Section> aSecAttrs;
pText->GetAllSections(aSecAttrs); if (aSecAttrs.size() != 2) returnfalse;
// auto color const editeng::Section* pAttr = &aSecAttrs[1]; if (pAttr->mnParagraph != 0 || pAttr->mnStart != 5 || pAttr->mnEnd != 9) returnfalse;
if (pAttr->maAttributes.size() != 1 || !isColor(*pAttr, COL_AUTO)) returnfalse;
returntrue;
}
} aCheckFunc;
// Start with an empty document, put one edit text cell, and make sure it // survives the save and reload.
createScDoc(); const EditTextObject* pEditText;
{
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.",
pDoc->GetTableCount() > 0);
// Insert an edit text cell.
ScFieldEditEngine* pEE = &pDoc->GetEditEngine();
pEE->SetTextCurrentDefaults(u"Bold and Italic"_ustr); // Set the 'Bold' part bold.
setAttribute(*pEE, 0, 0, 4, EE_CHAR_WEIGHT); // Set the 'Italic' part italic.
setAttribute(*pEE, 0, 9, 15, EE_CHAR_ITALIC);
// Set this edit text to cell B2.
pDoc->SetEditText(ScAddress(1, 1, 0), pEE->CreateTextObject());
pEditText = pDoc->GetEditText(ScAddress(1, 1, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B2 value.", aCheckFunc.checkB2(pEditText));
}
// Now, save and reload this document.
saveAndReload(u"calc8"_ustr);
{
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.",
pDoc->GetTableCount() > 0);
ScFieldEditEngine* pEE = &pDoc->GetEditEngine();
pEditText = pDoc->GetEditText(ScAddress(1, 1, 0));
// Make sure the content of B2 is still intact.
CPPUNIT_ASSERT_MESSAGE("Incorrect B2 value.", aCheckFunc.checkB2(pEditText));
// Reload the doc again, and check the content of B2 and B4.
saveAndReload(u"calc8"_ustr);
{
ScDocument* pDoc = getScDoc();
ScFieldEditEngine* pEE = &pDoc->GetEditEngine();
pEditText = pDoc->GetEditText(ScAddress(1, 1, 0));
CPPUNIT_ASSERT_MESSAGE("B2 should be an edit text.", pEditText);
pEditText = pDoc->GetEditText(ScAddress(1, 3, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B4 value.", aCheckFunc.checkB4(pEditText));
// Insert a multi-line content to B5, but this time, set some empty paragraphs.
pEE->Clear();
pEE->SetTextCurrentDefaults(u"\nTwo\nThree\n\nFive\n"_ustr);
pDoc->SetEditText(ScAddress(1, 4, 0), pEE->CreateTextObject());
pEditText = pDoc->GetEditText(ScAddress(1, 4, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B5 value.", aCheckFunc.checkB5(pEditText));
// Insert a text with strikethrough in B6.
pEE->Clear();
pEE->SetTextCurrentDefaults(u"Strike Me"_ustr); // Set the 'Strike' part strikethrough.
setAttribute(*pEE, 0, 0, 6, EE_CHAR_STRIKEOUT);
pDoc->SetEditText(ScAddress(1, 5, 0), pEE->CreateTextObject());
pEditText = pDoc->GetEditText(ScAddress(1, 5, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B6 value.", aCheckFunc.checkB6(pEditText));
// Insert a text with different font segments in B7.
pEE->Clear();
pEE->SetTextCurrentDefaults(u"Font1 and Font2"_ustr);
setFont(*pEE, 0, 0, 5, u"Courier"_ustr);
setFont(*pEE, 0, 10, 15, u"Luxi Mono"_ustr);
pDoc->SetEditText(ScAddress(1, 6, 0), pEE->CreateTextObject());
pEditText = pDoc->GetEditText(ScAddress(1, 6, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B7 value.", aCheckFunc.checkB7(pEditText));
// Insert a text with overline and underline in B8.
pEE->Clear();
pEE->SetTextCurrentDefaults(u"Over and Under"_ustr);
setAttribute(*pEE, 0, 0, 4, EE_CHAR_OVERLINE);
setAttribute(*pEE, 0, 9, 14, EE_CHAR_UNDERLINE);
pDoc->SetEditText(ScAddress(1, 7, 0), pEE->CreateTextObject());
pEditText = pDoc->GetEditText(ScAddress(1, 7, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B8 value.", aCheckFunc.checkB8(pEditText));
ScPatternAttr aCellFontColor(pDoc->getCellAttributeHelper());
aCellFontColor.GetItemSet().Put(SvxColorItem(COL_BLUE, ATTR_FONT_COLOR)); // Set font color of B10 to blue.
pDoc->ApplyPattern(1, 9, 0, aCellFontColor);
pEE->Clear();
pEE->SetTextCurrentDefaults(u"BLUE AUTO"_ustr); // Set the color of the string "AUTO" to automatic color.
setAttribute(*pEE, 0, 5, 9, EE_CHAR_COLOR, COL_AUTO);
pDoc->SetEditText(ScAddress(1, 9, 0), pEE->CreateTextObject());
pEditText = pDoc->GetEditText(ScAddress(1, 9, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B10 value.", aCheckFunc.checkB10(pEditText));
}
// Reload the doc again, and check the content of B2, B4, B6 and B7.
saveAndReload(u"calc8"_ustr);
ScDocument* pDoc = getScDoc();
pEditText = pDoc->GetEditText(ScAddress(1, 1, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B2 value after save and reload.",
aCheckFunc.checkB2(pEditText));
pEditText = pDoc->GetEditText(ScAddress(1, 3, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B4 value after save and reload.",
aCheckFunc.checkB4(pEditText));
pEditText = pDoc->GetEditText(ScAddress(1, 4, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B5 value after save and reload.",
aCheckFunc.checkB5(pEditText));
pEditText = pDoc->GetEditText(ScAddress(1, 5, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B6 value after save and reload.",
aCheckFunc.checkB6(pEditText));
pEditText = pDoc->GetEditText(ScAddress(1, 6, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B7 value after save and reload.",
aCheckFunc.checkB7(pEditText));
pEditText = pDoc->GetEditText(ScAddress(1, 7, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B8 value after save and reload.",
aCheckFunc.checkB8(pEditText));
pEditText = pDoc->GetEditText(ScAddress(1, 9, 0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B10 value after save and reload.",
aCheckFunc.checkB10(pEditText));
}
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// make sure the only cell in this doc is assigned some formatting record
OUString aCellFormat = getXPath(pSheet, "/x:worksheet/x:sheetData/x:row/x:c", "s");
CPPUNIT_ASSERT_MESSAGE("Cell format is missing", !aCellFormat.isEmpty());
OString nFormatIdx = OString::number(aCellFormat.toInt32() + 1); const OString aXPath1("/x:styleSheet/x:cellXfs/x:xf[" + nFormatIdx + "]/x:alignment"); // formatting record is set to wrap text
assertXPath(pStyles, aXPath1, "wrapText", u"true");
// see what font it references const OString aXPath2("/x:styleSheet/x:cellXfs/x:xf[" + nFormatIdx + "]");
OUString aFontId = getXPath(pStyles, aXPath2, "fontId");
OString nFontIdx = OString::number(aFontId.toInt32() + 1);
// that font should be bold const OString aXPath3("/x:styleSheet/x:fonts/x:font[" + nFontIdx + "]/x:b");
assertXPath(pStyles, aXPath3, "val", u"true");
}
CPPUNIT_TEST_FIXTURE(ScExportTest, testCellValuesExportODS)
{ // Start with an empty document
createScDoc();
{
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.",
pDoc->GetTableCount() > 0);
// set a value double
pDoc->SetValue(ScAddress(0, 0, 0), 2.0); // A1
// set a formula
pDoc->SetValue(ScAddress(2, 0, 0), 3.0); // C1
pDoc->SetValue(ScAddress(3, 0, 0), 3); // D1
pDoc->SetString(ScAddress(4, 0, 0), u"=10*C1/4"_ustr); // E1
pDoc->SetValue(ScAddress(5, 0, 0), 3.0); // F1
pDoc->SetString(ScAddress(7, 0, 0), u"=SUM(C1:F1)"_ustr); //H1
// set a string
pDoc->SetString(ScAddress(0, 2, 0), u"a simple line"_ustr); //A3
// set a digit string
pDoc->SetString(ScAddress(0, 4, 0), u"'12"_ustr); //A5 // set a contiguous value
pDoc->SetValue(ScAddress(0, 5, 0), 12.0); //A6 // set a contiguous string
pDoc->SetString(ScAddress(0, 6, 0), u"a string"_ustr); //A7 // set a contiguous formula
pDoc->SetString(ScAddress(0, 7, 0), u"=$A$6"_ustr); //A8
} // save and reload
saveAndReload(u"calc8"_ustr);
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.",
pDoc->GetTableCount() > 0);
CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", pDoc->HasNote(aPos));
aPos.IncRow(); // Move to A2.
ScPostIt* pNote = pDoc->GetOrCreateNote(aPos);
pNote->SetText(aPos, u"Note One"_ustr);
pNote->SetAuthor(u"Author One"_ustr);
CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", pDoc->HasNote(aPos));
} // save and reload
saveAndReload(u"calc8"_ustr);
ScDocument* pDoc = getScDoc();
aPos.SetRow(0); // Move back to A1.
CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", pDoc->HasNote(aPos));
aPos.IncRow(); // Move to A2.
CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", pDoc->HasNote(aPos));
}
CPPUNIT_TEST_FIXTURE(ScExportTest, testCellNoteExportXLS)
{ // Start with an empty document.s
createScDoc("ods/notes-on-3-sheets.ods");
{
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_EQUAL_MESSAGE("This document should have 3 sheets.", SCTAB(3),
pDoc->GetTableCount());
// the document contains a group anchored on the first cell, make sure it's there in the right place
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0);
ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
SdrPage* pPage = pDrawLayer->GetPage(0);
CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); const size_t nCount = pPage->GetObjCount();
CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 1 objects.", static_cast<size_t>(1), nCount);
SdrObject* pObj = pPage->GetObj(0);
CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj);
ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj);
CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
CPPUNIT_ASSERT_MESSAGE("Upper left of bounding rectangle should be nonnegative.",
pData->getShapeRect().Left() >= 0 || pData->getShapeRect().Top() >= 0);
}
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D2", u"=$A$2+$B$2+$C$2"_ustr,
pDoc->GetFormula(3, 1, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D3", u"=A3+B3+C3"_ustr,
pDoc->GetFormula(3, 2, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D6", u"=SUM($A$6:$C$6)"_ustr,
pDoc->GetFormula(3, 5, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D7", u"=SUM(A7:C7)"_ustr,
pDoc->GetFormula(3, 6, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D10", u"=$Two.$A$2+$Two.$B$2+$Two.$C$2"_ustr,
pDoc->GetFormula(3, 9, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D11", u"=$Two.A3+$Two.B3+$Two.C3"_ustr,
pDoc->GetFormula(3, 10, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D14", u"=MIN($Two.$A$2:$C$2)"_ustr,
pDoc->GetFormula(3, 13, 0));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula in D15", u"=MAX($Two.A3:C3)"_ustr,
pDoc->GetFormula(3, 14, 0));
}
namespace
{ constchar* toBorderName(SvxBorderLineStyle eStyle)
{ switch (eStyle)
{ case SvxBorderLineStyle::SOLID: return"SOLID"; case SvxBorderLineStyle::DOTTED: return"DOTTED"; case SvxBorderLineStyle::DASHED: return"DASHED"; case SvxBorderLineStyle::DASH_DOT: return"DASH_DOT"; case SvxBorderLineStyle::DASH_DOT_DOT: return"DASH_DOT_DOT"; case SvxBorderLineStyle::DOUBLE_THIN: return"DOUBLE_THIN"; case SvxBorderLineStyle::FINE_DASHED: return"FINE_DASHED"; default:;
}
// Without the fix in place, this test would have failed with // - Expected: false // - Actual : true
assertXPath(pStyles, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "wrapText", u"false");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.