2 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <officecfg/Office/Common.hxx>
13 #include "helper/qahelper.hxx"
16 #include <docpool.hxx>
17 #include <scitems.hxx>
19 #include <stlpool.hxx>
20 #include <formulacell.hxx>
21 #include <validat.hxx>
23 #include <dpcache.hxx>
24 #include <dpobject.hxx>
25 #include <clipparam.hxx>
27 #include <editeng/wghtitem.hxx>
28 #include <editeng/postitem.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <editeng/editobj.hxx>
31 #include <editeng/flditem.hxx>
32 #include <editeng/justifyitem.hxx>
33 #include <comphelper/scopeguard.hxx>
34 #include <unotools/syslocaleoptions.hxx>
35 #include <formula/grammar.hxx>
36 #include <tools/fldunit.hxx>
37 #include <svl/numformat.hxx>
38 #include <svl/zformat.hxx>
40 #include <com/sun/star/chart2/XChartDocument.hpp>
41 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
42 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
43 #include <com/sun/star/drawing/XDrawPage.hpp>
44 #include <com/sun/star/drawing/XDrawPages.hpp>
45 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
46 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
47 #include <com/sun/star/sheet/GlobalSheetSettings.hpp>
48 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
49 #include <com/sun/star/text/XTextColumns.hpp>
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::uno
;
54 class ScExportTest2
: public ScModelTestBase
57 virtual void registerNamespaces(xmlXPathContextPtr
& pXmlXPathCtx
) override
;
62 void testGroupShape();
63 void testMatrixMultiplicationXLSX();
65 void testTextDirectionXLSX();
75 void testTdf95640_ods_to_xlsx();
76 void testTdf95640_ods_to_xlsx_with_standard_list();
77 void testTdf95640_xlsx_to_xlsx();
78 void testDateAutofilterXLSX();
79 void testDateAutofilterODS();
80 void testAutofilterColorsODF();
81 void testAutofilterColorsOOXML();
82 void testAutofilterTop10XLSX();
84 void testRefStringXLSX();
85 void testRefStringConfigXLSX();
86 void testRefStringUnspecified();
87 void testHeaderImageODS();
88 void testHeaderFooterContentODS();
90 void testTdf88657ODS();
93 void testEscapeCharInNumberFormatXLSX();
94 void testNatNumInNumberFormatXLSX();
95 void testExponentWithoutSignFormatXLSX();
96 void testExtendedLCIDXLSX();
98 void testHiddenRepeatedRowsODS();
99 void testHyperlinkTargetFrameODS();
100 void testOpenDocumentAsReadOnly();
101 void testKeepSettingsOfBlankRows();
103 void testTdf133595();
104 void testTdf134769();
105 void testTdf106181();
106 void testTdf145057();
107 void testTdf105272();
108 void testTdf118990();
109 void testTdf121612();
110 void testTdf112936();
111 void testPivotCacheAfterExportXLSX();
112 void testTdf114969XLSX();
113 void testTdf115192XLSX();
114 void testTdf142764();
115 void testTdf91634XLSX();
116 void testTdf115159();
117 void testTdf112567();
119 void testTdf103829();
120 void testTdf122191();
121 void testTdf142881();
122 void testTdf112567b();
123 void testTdf123645XLSX();
124 void testTdf125173XLSX();
125 void testTdf79972XLSX();
126 void testTdf126024XLSX();
127 void testTdf126177XLSX();
128 void testCommentTextVAlignment();
129 void testCommentTextHAlignment();
130 void testValidationCopyPaste();
132 void testXltxExport();
133 void testRotatedImageODS();
135 void testTdf128976();
136 void testTdf151484();
137 void testTdf143979();
138 void testTdf120502();
139 void testTdf131372();
141 void testTdf122331();
143 void testTdf121715_FirstPageHeaderFooterXLSX();
144 void testTdf121716_ExportEvenHeaderFooterXLSX();
145 void testTdf134459_HeaderFooterColorXLSX();
146 void testTdf134817_HeaderFooterTextWith2SectionXLSX();
147 void testTdf121718_UseFirstPageNumberXLSX();
148 void testHeaderFontStyleXLSX();
149 void testTdf135828_Shape_Rect();
150 void testTdf123139XLSX();
151 void testTdf123353();
152 void testTdf140098();
153 void testTdf133688_precedents();
154 void testTdf91251_missingOverflowRoundtrip();
155 void testTdf137000_handle_upright();
156 void testTdf126305_DataValidatyErrorAlert();
157 void testTdf76047_externalLink();
158 void testTdf87973_externalLinkSkipUnuseds();
159 void testTdf51022_lostPrintRange();
160 void testTdf138741_externalLinkSkipUnusedsCrash();
161 void testTdf138824_linkToParentDirectory();
162 void testTdf129969();
163 void testTdf147088();
165 void testTdf136721_paper_size();
166 void testTdf139258_rotated_image();
167 void testTdf144642_RowHeightRounding();
168 void testTdf145129_DefaultRowHeightRounding();
169 void testTdf151755_stylesLostOnXLSXExport();
170 void testTdf152581_bordercolorNotExportedToXLSX();
171 void testTdf140431();
172 void testCheckboxFormControlXlsxExport();
173 void testButtonFormControlXlsxExport();
174 void testTdf142929_filterLessThanXLSX();
175 void testInvalidNamedRange();
176 void testExternalDefinedNameXLSX();
177 void testHyperlinkLocationXLSX();
178 void testTdf142264ManyChartsToXLSX();
179 void testTdf143929MultiColumnToODS();
180 void testTdf142578();
181 void testTdf145059();
182 void testTdf130104_XLSXIndent();
183 void testWholeRowBold();
184 void testXlsxRowsOrder();
186 void testTdf148820();
187 void testEmbeddedTextInDecimal();
188 void testTotalsRowFunction();
189 void testAutofilterHiddenButton();
191 CPPUNIT_TEST_SUITE(ScExportTest2
);
193 CPPUNIT_TEST(testGroupShape
);
194 CPPUNIT_TEST(testMatrixMultiplicationXLSX
);
195 CPPUNIT_TEST(testTdf121260
);
196 CPPUNIT_TEST(testTextDirectionXLSX
);
197 CPPUNIT_TEST(testTdf120168
);
198 CPPUNIT_TEST(testTdf66668
);
199 CPPUNIT_TEST(testTdf130108
);
200 CPPUNIT_TEST(testTdf76949
);
201 CPPUNIT_TEST(testTdf107586
);
202 CPPUNIT_TEST(testTdf55417
);
203 CPPUNIT_TEST(testTdf129985
);
204 CPPUNIT_TEST(testTdf73063
);
205 CPPUNIT_TEST(testTdf95640_ods_to_xlsx
);
206 CPPUNIT_TEST(testTdf95640_ods_to_xlsx_with_standard_list
);
207 CPPUNIT_TEST(testTdf95640_xlsx_to_xlsx
);
208 CPPUNIT_TEST(testDateAutofilterXLSX
);
209 CPPUNIT_TEST(testDateAutofilterODS
);
210 CPPUNIT_TEST(testAutofilterColorsODF
);
211 CPPUNIT_TEST(testAutofilterColorsOOXML
);
212 CPPUNIT_TEST(testAutofilterTop10XLSX
);
214 CPPUNIT_TEST(testRefStringXLSX
);
215 CPPUNIT_TEST(testRefStringConfigXLSX
);
216 CPPUNIT_TEST(testRefStringUnspecified
);
217 CPPUNIT_TEST(testHeaderImageODS
);
218 CPPUNIT_TEST(testHeaderFooterContentODS
);
220 CPPUNIT_TEST(testTdf88657ODS
);
221 CPPUNIT_TEST(testTdf41722
);
222 CPPUNIT_TEST(testTdf113621
);
223 CPPUNIT_TEST(testEscapeCharInNumberFormatXLSX
);
224 CPPUNIT_TEST(testNatNumInNumberFormatXLSX
);
225 CPPUNIT_TEST(testExponentWithoutSignFormatXLSX
);
226 CPPUNIT_TEST(testExtendedLCIDXLSX
);
228 CPPUNIT_TEST(testHiddenRepeatedRowsODS
);
229 CPPUNIT_TEST(testHyperlinkTargetFrameODS
);
230 CPPUNIT_TEST(testOpenDocumentAsReadOnly
);
231 CPPUNIT_TEST(testKeepSettingsOfBlankRows
);
233 CPPUNIT_TEST(testTdf133595
);
234 CPPUNIT_TEST(testTdf134769
);
235 CPPUNIT_TEST(testTdf106181
);
236 CPPUNIT_TEST(testTdf145057
);
237 CPPUNIT_TEST(testTdf105272
);
238 CPPUNIT_TEST(testTdf118990
);
239 CPPUNIT_TEST(testTdf121612
);
240 CPPUNIT_TEST(testTdf112936
);
241 CPPUNIT_TEST(testPivotCacheAfterExportXLSX
);
242 CPPUNIT_TEST(testTdf114969XLSX
);
243 CPPUNIT_TEST(testTdf115192XLSX
);
244 CPPUNIT_TEST(testTdf142764
);
245 CPPUNIT_TEST(testTdf91634XLSX
);
246 CPPUNIT_TEST(testTdf115159
);
247 CPPUNIT_TEST(testTdf112567
);
248 CPPUNIT_TEST(testTdf75702
);
249 CPPUNIT_TEST(testTdf103829
);
250 CPPUNIT_TEST(testTdf122191
);
251 CPPUNIT_TEST(testTdf142881
);
252 CPPUNIT_TEST(testTdf112567b
);
253 CPPUNIT_TEST(testTdf123645XLSX
);
254 CPPUNIT_TEST(testTdf125173XLSX
);
255 CPPUNIT_TEST(testTdf79972XLSX
);
256 CPPUNIT_TEST(testTdf126024XLSX
);
257 CPPUNIT_TEST(testTdf126177XLSX
);
258 CPPUNIT_TEST(testCommentTextVAlignment
);
259 CPPUNIT_TEST(testCommentTextHAlignment
);
260 CPPUNIT_TEST(testValidationCopyPaste
);
261 CPPUNIT_TEST(testXltxExport
);
262 CPPUNIT_TEST(testRotatedImageODS
);
263 CPPUNIT_TEST(testTdf85553
);
264 CPPUNIT_TEST(testTdf128976
);
265 CPPUNIT_TEST(testTdf151484
);
266 CPPUNIT_TEST(testTdf143979
);
267 CPPUNIT_TEST(testTdf120502
);
268 CPPUNIT_TEST(testTdf131372
);
269 CPPUNIT_TEST(testTdf81470
);
270 CPPUNIT_TEST(testTdf122331
);
271 CPPUNIT_TEST(testTdf83779
);
272 CPPUNIT_TEST(testTdf121715_FirstPageHeaderFooterXLSX
);
273 CPPUNIT_TEST(testTdf121716_ExportEvenHeaderFooterXLSX
);
274 CPPUNIT_TEST(testTdf134459_HeaderFooterColorXLSX
);
275 CPPUNIT_TEST(testTdf134817_HeaderFooterTextWith2SectionXLSX
);
276 CPPUNIT_TEST(testTdf121718_UseFirstPageNumberXLSX
);
277 CPPUNIT_TEST(testHeaderFontStyleXLSX
);
278 CPPUNIT_TEST(testTdf135828_Shape_Rect
);
279 CPPUNIT_TEST(testTdf123139XLSX
);
280 CPPUNIT_TEST(testTdf123353
);
281 CPPUNIT_TEST(testTdf140098
);
282 CPPUNIT_TEST(testTdf133688_precedents
);
283 CPPUNIT_TEST(testTdf91251_missingOverflowRoundtrip
);
284 CPPUNIT_TEST(testTdf137000_handle_upright
);
285 CPPUNIT_TEST(testTdf126305_DataValidatyErrorAlert
);
286 CPPUNIT_TEST(testTdf76047_externalLink
);
287 CPPUNIT_TEST(testTdf87973_externalLinkSkipUnuseds
);
288 CPPUNIT_TEST(testTdf51022_lostPrintRange
);
289 CPPUNIT_TEST(testTdf138741_externalLinkSkipUnusedsCrash
);
290 CPPUNIT_TEST(testTdf138824_linkToParentDirectory
);
291 CPPUNIT_TEST(testTdf129969
);
292 CPPUNIT_TEST(testTdf147088
);
293 CPPUNIT_TEST(testTdf84874
);
294 CPPUNIT_TEST(testTdf136721_paper_size
);
295 CPPUNIT_TEST(testTdf139258_rotated_image
);
296 CPPUNIT_TEST(testTdf144642_RowHeightRounding
);
297 CPPUNIT_TEST(testTdf145129_DefaultRowHeightRounding
);
298 CPPUNIT_TEST(testTdf151755_stylesLostOnXLSXExport
);
299 CPPUNIT_TEST(testTdf152581_bordercolorNotExportedToXLSX
);
300 CPPUNIT_TEST(testTdf140431
);
301 CPPUNIT_TEST(testCheckboxFormControlXlsxExport
);
302 CPPUNIT_TEST(testButtonFormControlXlsxExport
);
303 CPPUNIT_TEST(testTdf142929_filterLessThanXLSX
);
304 CPPUNIT_TEST(testInvalidNamedRange
);
305 CPPUNIT_TEST(testExternalDefinedNameXLSX
);
306 CPPUNIT_TEST(testHyperlinkLocationXLSX
);
307 CPPUNIT_TEST(testTdf142264ManyChartsToXLSX
);
308 CPPUNIT_TEST(testTdf143929MultiColumnToODS
);
309 CPPUNIT_TEST(testTdf142578
);
310 CPPUNIT_TEST(testTdf145059
);
311 CPPUNIT_TEST(testTdf130104_XLSXIndent
);
312 CPPUNIT_TEST(testWholeRowBold
);
313 CPPUNIT_TEST(testXlsxRowsOrder
);
314 CPPUNIT_TEST(testTdf91286
);
315 CPPUNIT_TEST(testTdf148820
);
316 CPPUNIT_TEST(testEmbeddedTextInDecimal
);
317 CPPUNIT_TEST(testTotalsRowFunction
);
318 CPPUNIT_TEST(testAutofilterHiddenButton
);
320 CPPUNIT_TEST_SUITE_END();
323 ScExportTest2::ScExportTest2()
324 : ScModelTestBase("sc/qa/unit/data")
328 void ScExportTest2::registerNamespaces(xmlXPathContextPtr
& pXmlXPathCtx
)
330 XmlTestTools::registerOOXMLNamespaces(pXmlXPathCtx
);
331 XmlTestTools::registerODFNamespaces(pXmlXPathCtx
);
334 void ScExportTest2::testGroupShape()
336 createScDoc("xlsx/groupShape.xlsx");
337 save("Calc Office Open XML");
339 xmlDocUniquePtr pDoc
= parseExport("xl/drawings/drawing1.xml");
340 CPPUNIT_ASSERT(pDoc
);
341 assertXPath(pDoc
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:grpSp/xdr:grpSpPr");
344 void ScExportTest2::testMatrixMultiplicationXLSX()
346 createScDoc("xlsx/matrix-multiplication.xlsx");
348 save("Calc Office Open XML");
350 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
351 CPPUNIT_ASSERT(pDoc
);
353 OUString CellFormulaRange
= getXPath(pDoc
, "/x:worksheet/x:sheetData/x:row[4]/x:c/x:f", "ref");
355 // make sure that the CellFormulaRange is G5:G6.
356 CPPUNIT_ASSERT_EQUAL(OUString("G5:G6"), CellFormulaRange
);
358 OUString CellFormulaType
= getXPath(pDoc
, "/x:worksheet/x:sheetData/x:row[4]/x:c/x:f", "t");
360 // make sure that the CellFormulaType is array.
361 CPPUNIT_ASSERT_EQUAL(OUString("array"), CellFormulaType
);
364 void ScExportTest2::testRefStringXLSX()
366 createScDoc("xlsx/ref_string.xlsx");
368 //make sure ref syntax gets saved for MSO-produced docs
369 saveAndReload("Calc Office Open XML");
371 ScDocument
* pDoc
= getScDoc();
372 ScCalcConfig aCalcConfig
= pDoc
->GetCalcConfig();
373 CPPUNIT_ASSERT_EQUAL(formula::FormulaGrammar::CONV_XL_A1
, aCalcConfig
.meStringRefAddressSyntax
);
376 void ScExportTest2::testRefStringConfigXLSX()
378 // this doc is configured with CalcA1 ref syntax
379 createScDoc("xlsx/empty.xlsx");
381 saveAndReload("Calc Office Open XML");
383 ScDocument
* pDoc
= getScDoc();
384 ScCalcConfig aConfig
= pDoc
->GetCalcConfig();
385 CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match",
386 formula::FormulaGrammar::CONV_OOO
,
387 aConfig
.meStringRefAddressSyntax
);
389 // this doc has no entry for ref syntax
390 createScDoc("xlsx/empty-noconf.xlsx");
393 aConfig
= pDoc
->GetCalcConfig();
394 // therefore after import, ref syntax should be set to CalcA1 | ExcelA1
395 CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match",
396 formula::FormulaGrammar::CONV_A1_XL_A1
,
397 aConfig
.meStringRefAddressSyntax
);
399 //set ref syntax to something else than ExcelA1 (native to xlsx format) ...
400 aConfig
.meStringRefAddressSyntax
= formula::FormulaGrammar::CONV_XL_R1C1
;
401 pDoc
->SetCalcConfig(aConfig
);
403 saveAndReload("Calc Office Open XML");
405 // ... and make sure it got saved
407 aConfig
= pDoc
->GetCalcConfig();
408 CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match",
409 formula::FormulaGrammar::CONV_XL_R1C1
,
410 aConfig
.meStringRefAddressSyntax
);
413 void ScExportTest2::testRefStringUnspecified()
417 ScDocument
* pDoc
= getScDoc();
418 ScCalcConfig aConfig
= pDoc
->GetCalcConfig();
419 CPPUNIT_ASSERT_EQUAL_MESSAGE("Default string ref syntax value doesn't match",
420 formula::FormulaGrammar::CONV_UNSPECIFIED
,
421 aConfig
.meStringRefAddressSyntax
);
423 // change formula syntax (i.e. not string ref syntax) to ExcelA1
424 pDoc
->SetGrammar(formula::FormulaGrammar::GRAM_NATIVE_XL_A1
);
426 saveAndReload("calc8");
428 // with string ref syntax at its default value, we should've saved ExcelA1
430 aConfig
= pDoc
->GetCalcConfig();
431 CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match",
432 formula::FormulaGrammar::CONV_XL_A1
,
433 aConfig
.meStringRefAddressSyntax
);
436 void ScExportTest2::testHeaderImageODS()
438 // Graphic as header background was lost on export.
439 createScDoc("ods/header-image.ods");
440 saveAndReload("calc8");
441 uno::Reference
<style::XStyleFamiliesSupplier
> xStyleFamiliesSupplier(mxComponent
,
443 uno::Reference
<container::XNameAccess
> xStyleFamilies
444 = xStyleFamiliesSupplier
->getStyleFamilies();
445 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName("PageStyles"),
447 uno::Reference
<beans::XPropertySet
> xStyle(xPageStyles
->getByName("Default"), uno::UNO_QUERY
);
449 uno::Reference
<graphic::XGraphic
> xGraphic
;
450 xStyle
->getPropertyValue("HeaderBackGraphic") >>= xGraphic
;
451 CPPUNIT_ASSERT(xGraphic
.is());
454 void ScExportTest2::testHeaderFooterContentODS()
456 createScDoc("ods/header-footer-content.ods");
457 saveAndReload("calc8");
458 uno::Reference
<style::XStyleFamiliesSupplier
> xStyleFamiliesSupplier(mxComponent
,
460 uno::Reference
<container::XNameAccess
> xStyleFamilies
461 = xStyleFamiliesSupplier
->getStyleFamilies();
462 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName("PageStyles"),
464 uno::Reference
<beans::XPropertySet
> xStyle(xPageStyles
->getByName("Default"), uno::UNO_QUERY
);
466 uno::Reference
<css::sheet::XHeaderFooterContent
> xContent
;
467 xStyle
->getPropertyValue("RightPageHeaderContent") >>= xContent
;
468 CPPUNIT_ASSERT(xContent
.is());
469 CPPUNIT_ASSERT_EQUAL(OUString("header"), xContent
->getCenterText()->getString());
471 xStyle
->getPropertyValue("FirstPageHeaderContent") >>= xContent
;
472 CPPUNIT_ASSERT(xContent
.is());
473 CPPUNIT_ASSERT_EQUAL(OUString("first page header"), xContent
->getCenterText()->getString());
475 xStyle
->getPropertyValue("RightPageFooterContent") >>= xContent
;
476 CPPUNIT_ASSERT(xContent
.is());
477 CPPUNIT_ASSERT_EQUAL(OUString("footer"), xContent
->getCenterText()->getString());
479 xStyle
->getPropertyValue("FirstPageFooterContent") >>= xContent
;
480 // First page footer content used to be lost upon export.
481 CPPUNIT_ASSERT(xContent
.is());
482 CPPUNIT_ASSERT_EQUAL(OUString("first page footer"), xContent
->getCenterText()->getString());
485 void ScExportTest2::testTextDirectionXLSX()
487 createScDoc("xlsx/writingMode.xlsx");
489 save("Calc Office Open XML");
490 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
491 CPPUNIT_ASSERT(pDoc
);
493 assertXPath(pDoc
, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "readingOrder", "1"); //LTR
494 assertXPath(pDoc
, "/x:styleSheet/x:cellXfs/x:xf[3]/x:alignment", "readingOrder", "2"); //RTL
497 void ScExportTest2::testTdf121260()
499 createScDoc("ods/tdf121260.ods");
501 ScDocument
* pDoc
= getScDoc();
502 // change formula syntax (i.e. not string ref syntax) to ExcelA1
503 pDoc
->SetGrammar(formula::FormulaGrammar::GRAM_NATIVE_XL_A1
);
505 save("Calc Office Open XML");
506 xmlDocUniquePtr pChart1
= parseExport("xl/charts/chart1.xml");
507 CPPUNIT_ASSERT(pChart1
);
509 // Without the fix in place, this test would have failed with
510 // - Expected: Sheet1!$A$1:$A$2
511 // - Actual : sheet1 $A$1:$A$2
512 assertXPathContent(pChart1
,
513 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:val/c:numRef/c:f",
515 assertXPathContent(pChart1
,
516 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:val/c:numRef/c:f",
520 void ScExportTest2::testTdf120168()
522 createScDoc("xlsx/tdf120168.xlsx");
524 save("Calc Office Open XML");
525 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
526 CPPUNIT_ASSERT(pDoc
);
528 // Without the fix in place, this test would have failed with
530 // - Actual : general
531 assertXPath(pDoc
, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "horizontal", "left");
532 assertXPath(pDoc
, "/x:styleSheet/x:cellXfs/x:xf[3]/x:alignment", "horizontal", "right");
535 void ScExportTest2::testTdf66668()
537 // Would hang on exporting without the fix in place
538 createScDoc("xlsx/tdf66668.xlsx");
540 save("Calc Office Open XML");
541 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
542 CPPUNIT_ASSERT(pDoc
);
545 void ScExportTest2::testTdf130108()
547 createScDoc("ods/tdf130108.ods");
549 save("Calc Office Open XML");
550 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
551 CPPUNIT_ASSERT(pDoc
);
553 assertXPath(pDoc
, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:b", "val", "1");
554 assertXPath(pDoc
, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:i", "val", "0");
555 assertXPath(pDoc
, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:color", "rgb", "FFFFFFFF");
556 assertXPath(pDoc
, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:sz", "val", "10");
557 assertXPath(pDoc
, "/x:styleSheet/x:dxfs/x:dxf/x:fill/x:patternFill/x:bgColor", "rgb",
561 void ScExportTest2::testTdf76949()
563 createScDoc("ods/tdf76949.ods");
565 save("Calc Office Open XML");
566 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
567 CPPUNIT_ASSERT(pSheet
);
569 assertXPathContent(pSheet
, "/x:worksheet/x:sheetData/x:row/x:c/x:f", "_xlfn.CHISQ.DIST(1,1,1)");
572 void ScExportTest2::testTdf107586()
574 createScDoc("xlsx/tdf107586.xlsx");
576 save("Calc Office Open XML");
577 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
578 CPPUNIT_ASSERT(pSheet
);
580 // Without the fix in place, this test would have failed with
581 // XPath '/x:worksheet/x:sheetPr/x:tabColor' number of nodes is incorrect
582 assertXPath(pSheet
, "/x:worksheet/x:sheetPr/x:tabColor", "rgb", "FF9BBB59");
585 void ScExportTest2::testTdf55417()
587 createScDoc("xlsx/tdf55417.xlsx");
589 save("Calc Office Open XML");
590 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
591 CPPUNIT_ASSERT(pDoc
);
592 assertXPath(pDoc
, "/x:styleSheet/x:cellXfs/x:xf[1]/x:alignment", 1);
593 assertXPath(pDoc
, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", 1);
596 void ScExportTest2::testTdf129985()
598 createScDoc("xlsx/tdf129985.xlsx");
600 save("Calc Office Open XML");
601 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
602 CPPUNIT_ASSERT(pDoc
);
604 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", "m/d/yyyy");
607 void ScExportTest2::testTdf73063()
609 createScDoc("xlsx/tdf73063.xlsx");
611 save("Calc Office Open XML");
612 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
613 CPPUNIT_ASSERT(pDoc
);
615 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode",
616 "[$-1C1A]dddd\", \"d\". \"mmmm\\ yyyy;@");
619 void ScExportTest2::testTdf95640_ods_to_xlsx()
621 // Roundtripping sort options with user defined list to XLSX
622 createScDoc("ods/tdf95640.ods");
624 save("Calc Office Open XML");
625 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
627 assertXPath(pDoc
, "//x:worksheet/x:autoFilter", "ref", "A1:B4");
629 assertXPath(pDoc
, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4");
631 assertXPath(pDoc
, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList",
632 "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec");
635 void ScExportTest2::testTdf95640_ods_to_xlsx_with_standard_list()
637 // Roundtripping sort options with user defined list to XLSX
638 createScDoc("ods/tdf95640_standard_list.ods");
639 save("Calc Office Open XML");
640 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
642 assertXPath(pDoc
, "//x:worksheet/x:autoFilter", "ref", "A1:B4");
644 assertXPath(pDoc
, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4");
646 assertXPath(pDoc
, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList",
647 "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday");
650 void ScExportTest2::testTdf95640_xlsx_to_xlsx()
652 // XLSX Roundtripping sort options with custom sort list - note
653 // that compared to ODS source documents above, here we _actually_
654 // can use custom lists (beyond the global user defines), like
656 createScDoc("xlsx/tdf95640.xlsx");
658 save("Calc Office Open XML");
659 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
661 assertXPath(pDoc
, "//x:worksheet/x:autoFilter", "ref", "A1:B4");
663 assertXPath(pDoc
, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4");
665 assertXPath(pDoc
, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList",
669 void ScExportTest2::testDateAutofilterXLSX()
671 // XLSX Roundtripping autofilter with date list
672 createScDoc("xlsx/dateAutofilter.xlsx");
674 save("Calc Office Open XML");
675 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
676 CPPUNIT_ASSERT(pDoc
);
678 assertXPath(pDoc
, "//x:autoFilter", "ref", "A1:B4");
679 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "day", "02");
680 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "month", "03");
681 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "year", "2017");
682 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]",
683 "dateTimeGrouping", "day");
685 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "day", "01");
686 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "month", "10");
687 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "year", "2014");
688 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]",
689 "dateTimeGrouping", "day");
692 void ScExportTest2::testDateAutofilterODS()
694 createScDoc("ods/tdf142231.ods");
697 xmlDocUniquePtr pDoc
= parseExport("content.xml");
698 CPPUNIT_ASSERT(pDoc
);
700 assertXPath(pDoc
, "//table:filter/table:filter-and/table:filter-condition[1]", "value", "Calc");
701 assertXPath(pDoc
, "//table:filter/table:filter-and/table:filter-condition[2]", "value",
705 void ScExportTest2::testAutofilterColorsODF()
707 createScDoc("ods/autofilter-colors.ods");
710 xmlDocUniquePtr pDoc
= parseExport("content.xml");
711 CPPUNIT_ASSERT(pDoc
);
714 "//table:database-ranges/table:database-range[1]/table:filter/table:filter-and/"
715 "table:filter-condition[1]",
718 "//table:database-ranges/table:database-range[1]/table:filter/table:filter-and/"
719 "table:filter-condition[1][@loext:data-type='background-color']");
721 "//table:database-ranges/table:database-range[1]/table:filter/table:filter-and/"
722 "table:filter-condition[2]",
724 assertXPath(pDoc
, "//table:database-ranges/table:database-range[1]/table:filter/"
725 "table:filter-and/table:filter-condition[2][@loext:data-type='text-color']");
727 // tdf#142965 Check "none" value when automatic text color / no fill was selected
728 assertXPath(pDoc
, "//table:database-ranges/table:database-range[2]/table:filter/"
730 "table:filter-condition[1][@loext:data-type='background-color']");
732 "//table:database-ranges/table:database-range[2]/table:filter/table:filter-and/"
733 "table:filter-condition[1]",
734 "value", "transparent");
735 assertXPath(pDoc
, "//table:database-ranges/table:database-range[3]/table:filter/"
736 "table:filter-and/table:filter-condition[1][@loext:data-type='text-color']");
738 "//table:database-ranges/table:database-range[3]/table:filter/table:filter-and/"
739 "table:filter-condition[1]",
740 "value", "window-font-color");
743 void ScExportTest2::testAutofilterColorsOOXML()
746 createScDoc("xlsx/autofilter-colors.xlsx");
747 save("Calc Office Open XML");
748 xmlDocUniquePtr pTable1
= parseExport("xl/tables/table1.xml");
749 CPPUNIT_ASSERT(pTable1
);
751 = getXPath(pTable1
, "/x:table/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId")
755 xmlDocUniquePtr pStyles
= parseExport("xl/styles.xml");
756 CPPUNIT_ASSERT(pStyles
);
757 OString
sDxfXPath("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfId
)
758 + "]/x:fill/x:patternFill/x:fgColor");
759 assertXPath(pStyles
, sDxfXPath
, "rgb", "FFFFD7D7");
763 createScDoc("xlsx/autofilter-colors-fg.xlsx");
764 save("Calc Office Open XML");
765 xmlDocUniquePtr pTable1
= parseExport("xl/tables/table1.xml");
766 CPPUNIT_ASSERT(pTable1
);
768 = getXPath(pTable1
, "/x:table/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId")
772 xmlDocUniquePtr pStyles
= parseExport("xl/styles.xml");
773 CPPUNIT_ASSERT(pStyles
);
774 OString
sDxfXPath("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfId
)
775 + "]/x:fill/x:patternFill/x:fgColor");
776 assertXPath(pStyles
, sDxfXPath
, "rgb", "FF3465A4");
780 void ScExportTest2::testAutofilterTop10XLSX()
782 createScDoc("xlsx/tdf143068_top10filter.xlsx");
784 save("Calc Office Open XML");
785 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
786 CPPUNIT_ASSERT(pDoc
);
787 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn", "colId", "0");
788 assertXPath(pDoc
, "//x:autoFilter/x:filterColumn/x:top10", "val", "4");
791 void ScExportTest2::testTdf88657ODS()
793 createScDoc("ods/tdf88657.ods");
796 xmlDocUniquePtr pDoc
= parseExport("styles.xml");
797 CPPUNIT_ASSERT(pDoc
);
799 assertXPath(pDoc
, "//number:fraction", "min-denominator-digits", "3");
802 void ScExportTest2::testTdf41722()
804 createScDoc("xlsx/tdf41722.xlsx");
806 save("Calc Office Open XML");
807 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
808 CPPUNIT_ASSERT(pDoc
);
810 assertXPath(pDoc
, "//x:conditionalFormatting/x:cfRule[1]", "operator", "containsText");
811 assertXPath(pDoc
, "//x:conditionalFormatting/x:cfRule[2]", "operator", "containsText");
812 assertXPath(pDoc
, "//x:conditionalFormatting/x:cfRule[3]", "operator", "containsText");
815 void ScExportTest2::testTdf113621()
817 createScDoc("xlsx/tdf113621.xlsx");
819 save("Calc Office Open XML");
820 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
821 CPPUNIT_ASSERT(pDoc
);
823 assertXPath(pDoc
, "//x:conditionalFormatting", "sqref", "A1:A1048576");
826 void ScExportTest2::testEscapeCharInNumberFormatXLSX()
828 createScDoc("xlsx/tdf81939.xlsx");
830 save("Calc Office Open XML");
831 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
832 CPPUNIT_ASSERT(pDoc
);
834 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode",
835 "00\\ 00\\ 00\\ 00\\ 00");
836 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode",
837 "00\\.00\\.00\\.000\\.0"); // tdf#81939
838 // "_-* #,##0\ _€_-;\-* #,##0\ _€_-;_-* "- "_€_-;_-@_-" // tdf#81222
839 OUString
rFormatStrExpected(u
"_-* #,##0\\ _€_-;\\-* #,##0\\ _€_-;_-* \"- \"_€_-;_-@_-");
840 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[4]", "formatCode", rFormatStrExpected
);
841 // "_-* #,##0" €"_-;\-* #,##0" €"_-;_-* "- €"_-;_-@_-");
842 rFormatStrExpected
= u
"_-* #,##0\" €\"_-;\\-* #,##0\" €\"_-;_-* \"- €\"_-;_-@_-";
843 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[5]", "formatCode", rFormatStrExpected
);
844 // remove escape char in fraction
845 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[6]", "formatCode",
846 "# ?/?;[RED]\\-# #/#####");
849 void ScExportTest2::testNatNumInNumberFormatXLSX()
851 createScDoc("ods/tdf79398_NatNum5.ods");
853 save("Calc Office Open XML");
854 xmlDocUniquePtr pDoc
= parseExport("xl/styles.xml");
855 CPPUNIT_ASSERT(pDoc
);
857 assertXPath(pDoc
, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode",
858 "[DBNum2][$-804]General;[RED][DBNum2][$-804]General");
861 void ScExportTest2::testExponentWithoutSignFormatXLSX()
863 createScDoc("ods/tdf102370_ExponentWithoutSign.ods");
864 saveAndReload("Calc Office Open XML");
866 saveAndReload("calc8");
868 ScDocument
* pDoc
= getScDoc();
869 sal_uInt32 nNumberFormat
= pDoc
->GetNumberFormat(0, 0, 0);
870 const SvNumberformat
* pNumberFormat
= pDoc
->GetFormatTable()->GetEntry(nNumberFormat
);
871 const OUString
& rFormatStr
= pNumberFormat
->GetFormatstring();
873 CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format lost exponent without sign during Excel export",
874 OUString("0.00E0"), rFormatStr
);
877 void ScExportTest2::testExtendedLCIDXLSX()
879 createScDoc("ods/tdf36038_ExtendedLCID.ods");
881 saveAndReload("Calc Office Open XML");
882 xmlDocUniquePtr pDocXml
= parseExport("xl/styles.xml");
883 CPPUNIT_ASSERT(pDocXml
);
885 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode",
886 "[$-107041E]dd\\-mm\\-yyyy");
887 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode",
888 "[$-D07041E]dd\\-mm\\-yyyy");
889 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[4]", "formatCode",
890 "[$-1030411]dd\\-mm\\-ee");
891 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[5]", "formatCode",
892 "[$-1B030411]dd\\-mm\\-ee");
893 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[6]", "formatCode",
894 "[$-108040D]dd\\-mm\\-yyyy");
895 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[7]", "formatCode",
896 "[$-108040D]dd\\-mm\\-yyyy");
897 assertXPath(pDocXml
, "/x:styleSheet/x:numFmts/x:numFmt[8]", "formatCode",
898 "[$-1060401]dd\\-mm\\-yyyy");
901 ScDocument
* pDoc
= getScDoc();
902 SvNumberFormatter
* pNumFormatter
= pDoc
->GetFormatTable();
903 const OUString aLang
[5] = { "[$-41E]", "[$-411]", "[$-40D]", "[$-401]", "[$-500]" };
904 const OUString aCalendar
[5] = { "[~buddhist]DD-MM-YYYY", "DD-MM-EE", "[~jewish]DD-MM-YYYY",
905 "[~hijri]DD-MM-YYYY", "[~dangi]YYYY/MM/DD" };
906 // Note: ja-JP Gengou calendar is an implicit secondary (non-gregorian)
907 // calendar, the explicit [~gengou] calendar modifier does not need to be
908 // present, the E and EE keywords are used instead of YY and YYYY.
909 for (sal_Int16 nCol
= 1; nCol
<= 2; nCol
++)
911 for (sal_Int16 nRow
= 1; nRow
<= 4; nRow
++)
913 sal_uInt32 nNumberFormat
= pDoc
->GetNumberFormat(nCol
, nRow
, 0);
914 const SvNumberformat
* pNumberFormat
= pNumFormatter
->GetEntry(nNumberFormat
);
915 const OUString
& rFormatStr
= pNumberFormat
->GetFormatstring();
916 const OUString aExpectedFormatStr
917 = aLang
[nRow
- 1] + ((nCol
== 2 && nRow
!= 3) ? OUString("[NatNum1]") : OUString())
918 + aCalendar
[nRow
- 1];
920 CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format lost extended LCID during Excel export",
921 aExpectedFormatStr
, rFormatStr
);
926 void ScExportTest2::testHiddenRepeatedRowsODS()
931 ScDocument
* pDoc
= getScDoc();
932 pDoc
->SetRowHidden(0, 20, 0, true);
935 saveAndReload("calc8");
936 ScDocument
* pDoc
= getScDoc();
939 bool bHidden
= pDoc
->RowHidden(0, 0, &nFirstRow
, &nLastRow
);
940 CPPUNIT_ASSERT(bHidden
);
941 CPPUNIT_ASSERT_EQUAL(SCROW(0), nFirstRow
);
942 CPPUNIT_ASSERT_EQUAL(SCROW(20), nLastRow
);
945 void ScExportTest2::testHyperlinkTargetFrameODS()
947 createScDoc("ods/hyperlink_frame.ods");
949 ScDocument
* pDoc
= getScDoc();
950 const EditTextObject
* pEditText
= pDoc
->GetEditText(ScAddress(2, 5, 0));
951 CPPUNIT_ASSERT(pEditText
);
953 const SvxFieldData
* pData
= pEditText
->GetFieldData(0, 0, text::textfield::Type::URL
);
954 CPPUNIT_ASSERT_MESSAGE("Failed to get the URL data.", pData
);
955 CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to get the URL data.", text::textfield::Type::URL
,
956 pData
->GetClassId());
958 const SvxURLField
* pURLData
= static_cast<const SvxURLField
*>(pData
);
959 OUString aTargetFrame
= pURLData
->GetTargetFrame();
960 CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrame
);
963 xmlDocUniquePtr pDocXml
= parseExport("content.xml");
964 CPPUNIT_ASSERT(pDocXml
);
965 OUString aTargetFrameExport
967 "/office:document-content/office:body/office:spreadsheet/table:table/"
968 "table:table-row[2]/table:table-cell[2]/text:p/text:a",
969 "target-frame-name");
970 CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrameExport
);
973 void ScExportTest2::testOpenDocumentAsReadOnly()
975 createScDoc("xlsx/open-as-read-only.xlsx");
976 ScDocShell
* pDocSh
= getScDocShell();
977 CPPUNIT_ASSERT(pDocSh
->IsSecurityOptOpenReadOnly());
978 saveAndReload("Calc Office Open XML");
979 pDocSh
= getScDocShell();
980 CPPUNIT_ASSERT(pDocSh
->IsSecurityOptOpenReadOnly());
983 void ScExportTest2::testKeepSettingsOfBlankRows()
985 createScDoc("xlsx/tdf41425.xlsx");
987 save("Calc Office Open XML");
988 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
989 CPPUNIT_ASSERT(pSheet
);
991 // saved blank row with not default setting in A2
992 assertXPath(pSheet
, "/x:worksheet/x:sheetData/x:row", 2);
995 void ScExportTest2::testTdf133595()
997 createScDoc("xlsx/tdf133595.xlsx");
999 save("Calc Office Open XML");
1000 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
1001 CPPUNIT_ASSERT(pSheet
);
1003 // without the fix in place, mc:AlternateContent would have been added to sheet1
1004 assertXPath(pSheet
, "/x:worksheet/mc:AlternateContent", 0);
1007 void ScExportTest2::testTdf134769()
1009 createScDoc("xlsx/tdf134769.xlsx");
1011 save("Calc Office Open XML");
1012 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
1013 CPPUNIT_ASSERT(pSheet
);
1015 // without the fix in place, the legacyDrawing would have been exported after the checkbox
1016 // and Excel would have claimed the document is corrupted
1017 // Use their ids to check the order
1018 assertXPath(pSheet
, "/x:worksheet/x:drawing", "id", "rId2");
1019 assertXPath(pSheet
, "/x:worksheet/x:legacyDrawing", "id", "rId3");
1021 "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/"
1022 "mc:Choice/x:control",
1026 void ScExportTest2::testTdf106181()
1028 createScDoc("ods/tdf106181.ods");
1030 save("Calc Office Open XML");
1031 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
1032 CPPUNIT_ASSERT(pSheet
);
1035 "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/"
1036 "mc:Choice/x:control",
1037 "name", "Check Box");
1039 "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/"
1040 "mc:Choice/x:control/x:controlPr",
1041 "altText", "Check Box 1");
1043 xmlDocUniquePtr pDrawing
= parseExport("xl/drawings/drawing1.xml");
1044 CPPUNIT_ASSERT(pDrawing
);
1048 "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr",
1049 "name", "Check Box 1");
1052 "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr",
1053 "descr", "Check Box");
1056 "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr",
1060 void ScExportTest2::testTdf145057()
1062 createScDoc("xlsx/tdf145057.xlsx");
1064 save("Calc Office Open XML");
1065 xmlDocUniquePtr pDoc
= parseExport("xl/tables/table1.xml");
1066 CPPUNIT_ASSERT(pDoc
);
1068 assertXPath(pDoc
, "//x:colorFilter", "dxfId", "1");
1071 void ScExportTest2::testTdf105272()
1073 createScDoc("xlsx/tdf105272.xlsx");
1074 saveAndReload("Calc Office Open XML");
1075 ScDocument
* pDoc
= getScDoc();
1076 //without the fix in place,it would fail
1077 //Expected: Table1[[#This Row],[Total]]/Table1[[#This Row],['# Athletes]]
1078 //Actual : table1[[#this row],[total]]/table1[[#this row],['# athletes]]
1080 CPPUNIT_ASSERT_EQUAL_MESSAGE(
1081 "Wrong formula", OUString("=Table1[[#This Row],[Total]]/Table1[[#This Row],['# Athletes]]"),
1082 pDoc
->GetFormula(7, 3, 0));
1085 void ScExportTest2::testTdf118990()
1087 createScDoc("xlsx/tdf118990.xlsx");
1088 saveAndReload("Calc Office Open XML");
1089 ScDocument
* pDoc
= getScDoc();
1091 // TODO: also test A1, which contains a UNC reference to \\localhost\share\lookupsource.xlsx,
1092 // but currently looses "localhost" part when normalized in INetURLObject, becoming
1093 // file:///share/lookupsource.xlsx - which is incorrect, since it points to local filesystem
1094 // and not to Windows network share.
1096 CPPUNIT_ASSERT_EQUAL_MESSAGE(
1097 "Wrong Windows share (using host IP) URL in A2",
1098 OUString("=VLOOKUP(B1,'file://192.168.1.1/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)"),
1099 pDoc
->GetFormula(0, 1, 0));
1101 CPPUNIT_ASSERT_EQUAL_MESSAGE(
1102 "Wrong Windows share (using hostname) URL in A3",
1103 OUString("=VLOOKUP(B1,'file://NETWORKHOST/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)"),
1104 pDoc
->GetFormula(0, 2, 0));
1107 void ScExportTest2::testTdf121612()
1109 createScDoc("ods/tdf121612.ods");
1110 saveAndReload("Calc Office Open XML");
1112 ScDocument
* pDoc
= getScDoc();
1114 // There should be a pivot table
1115 CPPUNIT_ASSERT(pDoc
->HasPivotTable());
1117 // DP collection is not lost after export and has one entry
1118 ScDPCollection
* pDPColl
= pDoc
->GetDPCollection();
1119 CPPUNIT_ASSERT(pDPColl
);
1120 CPPUNIT_ASSERT_EQUAL(size_t(1), pDPColl
->GetCount());
1123 void ScExportTest2::testTdf112936()
1125 createScDoc("xlsx/tdf112936.xlsx");
1127 save("Calc Office Open XML");
1128 xmlDocUniquePtr pDoc
= parseExport("xl/pivotCache/pivotCacheDefinition1.xml");
1129 CPPUNIT_ASSERT(pDoc
);
1131 assertXPath(pDoc
, "//x:pivotCacheDefinition", "recordCount", "4");
1132 assertXPath(pDoc
, "//x:pivotCacheDefinition", "createdVersion", "3");
1135 void ScExportTest2::testXltxExport()
1137 // Create new document
1140 // Export as template and check content type
1141 save("Calc MS Excel 2007 XML Template");
1142 xmlDocUniquePtr pDoc
= parseExport("[Content_Types].xml");
1143 CPPUNIT_ASSERT(pDoc
);
1144 assertXPath(pDoc
, "/ContentType:Types/ContentType:Override[@PartName='/xl/workbook.xml']",
1146 "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml");
1149 void ScExportTest2::testPivotCacheAfterExportXLSX()
1151 createScDoc("ods/numgroup_example.ods");
1154 save("Calc Office Open XML");
1156 ScDocument
* pDoc
= getScDoc();
1157 CPPUNIT_ASSERT(pDoc
->HasPivotTable());
1160 ScDPCollection
* pDPColl
= pDoc
->GetDPCollection();
1161 CPPUNIT_ASSERT(pDPColl
);
1162 CPPUNIT_ASSERT_EQUAL(size_t(2), pDPColl
->GetCount());
1165 ScDPCollection::SheetCaches
& rSheetCaches
= pDPColl
->GetSheetCaches();
1166 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rSheetCaches
.size());
1167 const ScDPCache
* pCache
= rSheetCaches
.getExistingCache(ScRange(0, 0, 0, 3, 30, 0));
1168 CPPUNIT_ASSERT_MESSAGE("Pivot cache is expected for A1:D31 on the first sheet.", pCache
);
1170 // See if XLSX export didn't damage group info of the 1st pivot table
1171 const ScDPNumGroupInfo
* pInfo
= pCache
->GetNumGroupInfo(1);
1172 CPPUNIT_ASSERT_MESSAGE("No number group info :(", pInfo
);
1175 void ScExportTest2::testTdf114969XLSX()
1177 createScDoc("ods/sheet_name_with_dots.ods");
1179 save("Calc Office Open XML");
1180 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1181 CPPUNIT_ASSERT(pDoc
);
1182 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink[1]", "location", "'1.1.1.1'!C1");
1183 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink[2]", "location", "'1.1.1.1'!C2");
1186 void ScExportTest2::testTdf115192XLSX()
1188 createScDoc("xlsx/test_115192.xlsx");
1190 save("Calc Office Open XML");
1191 xmlDocUniquePtr pDoc
= parseExport("xl/drawings/_rels/drawing1.xml.rels");
1192 CPPUNIT_ASSERT(pDoc
);
1193 assertXPath(pDoc
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "TargetMode",
1195 assertXPathNoAttribute(pDoc
, "/rels:Relationships/rels:Relationship[@Id='rId2']", "TargetMode");
1196 assertXPath(pDoc
, "/rels:Relationships/rels:Relationship[@Id='rId3']", "TargetMode",
1200 void ScExportTest2::testTdf142764()
1202 createScDoc("ods/tdf142764.ods");
1204 save("Calc Office Open XML");
1205 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
1206 CPPUNIT_ASSERT(pSheet
);
1208 assertXPath(pSheet
, "/x:worksheet/x:headerFooter", "differentOddEven", "true");
1209 assertXPath(pSheet
, "/x:worksheet/x:headerFooter", "differentFirst", "true");
1212 void ScExportTest2::testTdf91634XLSX()
1214 createScDoc("xlsx/image_hyperlink.xlsx");
1215 save("Calc Office Open XML");
1217 xmlDocUniquePtr pDoc
= parseExport("xl/drawings/drawing1.xml");
1218 CPPUNIT_ASSERT(pDoc
);
1219 assertXPath(pDoc
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick", 1);
1221 xmlDocUniquePtr pXmlRels
= parseExport("xl/drawings/_rels/drawing1.xml.rels");
1222 CPPUNIT_ASSERT(pXmlRels
);
1223 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "Target",
1224 "https://www.google.com/");
1225 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "TargetMode",
1229 void ScExportTest2::testValidationCopyPaste()
1231 createScDoc("ods/validation-copypaste.ods");
1232 ScDocument
* pDoc
= getScDoc();
1234 // Copy B1 from src doc to clip
1235 ScDocument
aClipDoc(SCDOCMODE_CLIP
);
1236 ScRange
aSrcRange(1, 0, 1);
1237 ScClipParam
aClipParam(aSrcRange
, false);
1238 ScMarkData
aMark(pDoc
->GetSheetLimits());
1239 aMark
.SetMarkArea(aSrcRange
);
1240 pDoc
->CopyToClip(aClipParam
, &aClipDoc
, &aMark
, false, false);
1242 // Create second document, paste B1 from clip
1245 ScRange
aDstRange(1, 0, 0);
1246 ScMarkData
aMark2(pDoc
->GetSheetLimits());
1247 aMark2
.SetMarkArea(aDstRange
);
1248 pDoc
->CopyFromClip(aDstRange
, aMark2
, InsertDeleteFlags::ALL
, nullptr, &aClipDoc
);
1251 save("Calc Office Open XML");
1254 xmlDocUniquePtr pDocXml
= parseExport("xl/worksheets/sheet1.xml");
1255 CPPUNIT_ASSERT(pDocXml
);
1256 assertXPathContent(pDocXml
, "/x:worksheet/x:dataValidations/x:dataValidation/x:formula1",
1260 void ScExportTest2::testTdf115159()
1262 createScDoc("xlsx/tdf115159.xlsx");
1264 save("Calc Office Open XML");
1265 xmlDocUniquePtr pDoc
= parseExport("xl/workbook.xml");
1266 CPPUNIT_ASSERT(pDoc
);
1268 //assert the existing OOXML built-in name is not duplicated
1269 assertXPath(pDoc
, "/x:workbook/x:definedNames/x:definedName", 1);
1272 void ScExportTest2::testTdf112567()
1274 // Set the system locale to Hungarian (a language with different range separator)
1275 SvtSysLocaleOptions aOptions
;
1276 OUString sLocaleConfigString
= aOptions
.GetLanguageTag().getBcp47();
1277 aOptions
.SetLocaleConfigString("hu-HU");
1279 comphelper::ScopeGuard
g([&aOptions
, &sLocaleConfigString
] {
1280 aOptions
.SetLocaleConfigString(sLocaleConfigString
);
1284 createScDoc("xlsx/tdf112567.xlsx");
1286 save("Calc Office Open XML");
1287 xmlDocUniquePtr pDoc
= parseExport("xl/workbook.xml");
1288 CPPUNIT_ASSERT(pDoc
);
1290 //assert the existing OOXML built-in name is not duplicated
1291 assertXPath(pDoc
, "/x:workbook/x:definedNames/x:definedName", 1);
1294 void ScExportTest2::testTdf75702()
1296 // The problem was that line breaks were not imported.
1297 const OUString
sA1("line1\nline2");
1299 createScDoc("ods/tdf75702_textLineBreak.ods");
1300 ScDocument
* pDoc
= getScDoc();
1301 CPPUNIT_ASSERT_EQUAL_MESSAGE("load a1", sA1
, pDoc
->GetString(0, 0, 0));
1303 saveAndReload("calc8");
1305 CPPUNIT_ASSERT_EQUAL_MESSAGE("reload a1", sA1
, pDoc
->GetString(0, 0, 0));
1308 xmlDocUniquePtr pContent
= parseExport("content.xml");
1309 assertXPath(pContent
, "//table:table-row[1]/table:table-cell/text:p", 2);
1312 void ScExportTest2::testTdf103829()
1314 // The problem was that tabspaces were not imported or exported at all.
1315 // These strings match the current implementations of CELLTYPE_EDIT and CELLTYPE_STRING.
1316 const OUString
sA1("\x001Leading tab\nTHREE tabs inside: [\x001\x001\x001]");
1317 const OUString
sA2("\tLeading tab. THREE tabs inside: [\t\t\t]");
1319 createScDoc("ods/tdf103829_textTab.ods");
1320 ScDocument
* pDoc
= getScDoc();
1321 CPPUNIT_ASSERT_EQUAL_MESSAGE("load a1", sA1
, pDoc
->GetString(0, 0, 0));
1322 CPPUNIT_ASSERT_EQUAL_MESSAGE("load a2", sA2
, pDoc
->GetString(0, 1, 0));
1324 saveAndReload("calc8");
1326 CPPUNIT_ASSERT_EQUAL_MESSAGE("reload a1", sA1
, pDoc
->GetString(0, 0, 0));
1327 CPPUNIT_ASSERT_EQUAL_MESSAGE("reload a2", sA2
, pDoc
->GetString(0, 1, 0));
1330 void ScExportTest2::testTdf122191()
1332 // Set the system locale to Hungarian
1333 SvtSysLocaleOptions aOptions
;
1334 OUString sLocaleConfigString
= aOptions
.GetLanguageTag().getBcp47();
1335 aOptions
.SetLocaleConfigString("hu-HU");
1337 comphelper::ScopeGuard
g([&aOptions
, &sLocaleConfigString
] {
1338 aOptions
.SetLocaleConfigString(sLocaleConfigString
);
1342 createScDoc("xlsx/tdf122191.xlsx");
1344 ScDocument
* pDoc
= getScDoc();
1345 CPPUNIT_ASSERT_EQUAL(OUString("IGAZ"), pDoc
->GetString(0, 0, 0));
1347 saveAndReload("Calc Office Open XML");
1350 // Without the fix in place, this test would have failed with
1352 // - Actual : BOOL00AN
1353 CPPUNIT_ASSERT_EQUAL(OUString("IGAZ"), pDoc
->GetString(0, 0, 0));
1356 void ScExportTest2::testTdf142881()
1358 createScDoc("xlsx/tdf142881.xlsx");
1360 save("Calc Office Open XML");
1361 xmlDocUniquePtr pDrawing1
= parseExport("xl/drawings/drawing1.xml");
1362 CPPUNIT_ASSERT(pDrawing1
);
1364 // Verify that the shapes are rotated and positioned in the expected way
1365 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:from/xdr:col", "11");
1366 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:from/xdr:row", "0");
1367 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:to/xdr:col", "12");
1368 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:to/xdr:row", "19");
1370 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:from/xdr:col", "2");
1371 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:from/xdr:row", "8");
1372 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:to/xdr:col", "7");
1373 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:to/xdr:row", "10");
1375 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:from/xdr:col", "10");
1376 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:from/xdr:row", "9");
1377 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:to/xdr:col", "11");
1378 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:to/xdr:row", "26");
1380 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[4]/xdr:from/xdr:col", "2");
1381 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[4]/xdr:from/xdr:row", "17");
1382 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[4]/xdr:to/xdr:col", "8");
1383 assertXPathContent(pDrawing1
, "/xdr:wsDr/xdr:twoCellAnchor[4]/xdr:to/xdr:row", "19");
1386 void ScExportTest2::testTdf112567b()
1388 // Set the system locale to Hungarian (a language with different range separator)
1389 SvtSysLocaleOptions aOptions
;
1390 OUString sLocaleConfigString
= aOptions
.GetLanguageTag().getBcp47();
1391 aOptions
.SetLocaleConfigString("hu-HU");
1393 comphelper::ScopeGuard
g([&aOptions
, &sLocaleConfigString
] {
1394 aOptions
.SetLocaleConfigString(sLocaleConfigString
);
1398 createScDoc("ods/tdf112567.ods");
1400 save("Calc Office Open XML");
1401 xmlDocUniquePtr pDoc
= parseExport("xl/workbook.xml");
1402 CPPUNIT_ASSERT(pDoc
);
1404 //assert the existing OOXML built-in name is not duplicated
1405 assertXPath(pDoc
, "/x:workbook/x:definedNames/x:definedName", 1);
1407 //and it contains "," instead of ";"
1408 assertXPathContent(pDoc
, "/x:workbook/x:definedNames/x:definedName[1]",
1409 "Sheet1!$A:$A,Sheet1!$1:$1");
1412 void ScExportTest2::testTdf123645XLSX()
1414 createScDoc("xlsx/chart_hyperlink.xlsx");
1415 save("Calc Office Open XML");
1417 xmlDocUniquePtr pDoc
= parseExport("xl/drawings/drawing1.xml");
1418 CPPUNIT_ASSERT(pDoc
);
1420 "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/"
1424 "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/"
1428 "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/"
1432 xmlDocUniquePtr pXmlRels
= parseExport("xl/drawings/_rels/drawing1.xml.rels");
1433 CPPUNIT_ASSERT(pXmlRels
);
1434 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "TargetMode",
1436 assertXPathNoAttribute(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId3']",
1438 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId5']", "TargetMode",
1440 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "Target",
1441 "file:///C:/TEMP/test.xlsx");
1442 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId3']", "Target",
1444 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId5']", "Target",
1445 "https://bugs.documentfoundation.org/show_bug.cgi?id=123645");
1448 void ScExportTest2::testTdf125173XLSX()
1450 createScDoc("ods/text_box_hyperlink.ods");
1451 save("Calc Office Open XML");
1453 xmlDocUniquePtr pDoc
= parseExport("xl/drawings/drawing1.xml");
1454 CPPUNIT_ASSERT(pDoc
);
1455 assertXPath(pDoc
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr/a:hlinkClick", 1);
1457 xmlDocUniquePtr pXmlRels
= parseExport("xl/drawings/_rels/drawing1.xml.rels");
1458 CPPUNIT_ASSERT(pXmlRels
);
1459 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "Target",
1460 "http://www.google.com/");
1461 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship[@Id='rId1']", "TargetMode",
1465 void ScExportTest2::testTdf79972XLSX()
1467 createScDoc("xlsx/tdf79972.xlsx");
1468 save("Calc Office Open XML");
1470 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1471 CPPUNIT_ASSERT(pDoc
);
1472 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink", "ref", "A1");
1474 xmlDocUniquePtr pXmlRels
= parseExport("xl/worksheets/_rels/sheet1.xml.rels");
1475 CPPUNIT_ASSERT(pXmlRels
);
1476 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship", "Target",
1477 "https://bugs.documentfoundation.org/show_bug.cgi?id=79972");
1478 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship", "TargetMode", "External");
1481 void ScExportTest2::testTdf126024XLSX()
1483 createScDoc("xlsx/hyperlink_formula.xlsx");
1484 save("Calc Office Open XML");
1486 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1487 CPPUNIT_ASSERT(pDoc
);
1488 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink", "ref", "A2");
1490 xmlDocUniquePtr pXmlRels
= parseExport("xl/worksheets/_rels/sheet1.xml.rels");
1491 CPPUNIT_ASSERT(pXmlRels
);
1492 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship", "Target",
1493 "https://bugs.documentfoundation.org/");
1494 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship", "TargetMode", "External");
1497 void ScExportTest2::testTdf126177XLSX()
1499 createScDoc("xlsx/hyperlink_export.xlsx");
1500 save("Calc Office Open XML");
1502 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1503 CPPUNIT_ASSERT(pDoc
);
1504 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink", "location", "Munka1!A5");
1506 xmlDocUniquePtr pXmlRels
= parseExport("xl/worksheets/_rels/sheet1.xml.rels");
1507 CPPUNIT_ASSERT(pXmlRels
);
1508 OUString aTarget
= getXPath(pXmlRels
, "/rels:Relationships/rels:Relationship", "Target");
1509 CPPUNIT_ASSERT(aTarget
.endsWith("test.xlsx"));
1510 assertXPath(pXmlRels
, "/rels:Relationships/rels:Relationship", "TargetMode", "External");
1513 void ScExportTest2::testCommentTextVAlignment()
1515 // Testing comment text alignments.
1516 createScDoc("ods/CommentTextVAlign.ods");
1518 save("Calc Office Open XML");
1520 xmlDocUniquePtr pVmlDrawing
= parseExport("xl/drawings/vmlDrawing1.vml");
1521 CPPUNIT_ASSERT(pVmlDrawing
);
1523 assertXPathContent(pVmlDrawing
, "/xml/v:shape/xx:ClientData/xx:TextVAlign", "Center");
1526 void ScExportTest2::testCommentTextHAlignment()
1528 // Testing comment text alignments.
1529 createScDoc("ods/CommentTextHAlign.ods");
1531 save("Calc Office Open XML");
1533 xmlDocUniquePtr pVmlDrawing
= parseExport("xl/drawings/vmlDrawing1.vml");
1534 CPPUNIT_ASSERT(pVmlDrawing
);
1536 assertXPathContent(pVmlDrawing
, "/xml/v:shape/xx:ClientData/xx:TextHAlign", "Center");
1539 void ScExportTest2::testRotatedImageODS()
1541 // Error was, that the length values in shapes were not
1542 // written in the given unit into the file.
1543 css::uno::Reference
<css::sheet::XGlobalSheetSettings
> xGlobalSheetSettings
1544 = css::sheet::GlobalSheetSettings::create(comphelper::getProcessComponentContext());
1545 xGlobalSheetSettings
->setMetric(static_cast<sal_Int16
>(FieldUnit::MM
));
1547 createScDoc("ods/tdf103092_RotatedImage.ods");
1550 xmlDocUniquePtr pXmlDoc
= parseExport("content.xml");
1551 CPPUNIT_ASSERT(pXmlDoc
);
1553 const OUString sTransform
= getXPath(pXmlDoc
,
1554 "/office:document-content/office:body/office:spreadsheet/"
1555 "table:table/table:shapes/draw:frame",
1557 // Attribute transform has the structure skew (...) rotate (...) translate (x y)
1558 // parts are separated by blank
1559 OUString
sTranslate(sTransform
.copy(sTransform
.lastIndexOf('(')));
1560 sTranslate
= sTranslate
.copy(1, sTranslate
.getLength() - 2); // remove '(' and ')'
1561 const OUString
sX(sTranslate
.getToken(0, ' '));
1562 const OUString
sY(sTranslate
.getToken(1, ' '));
1563 CPPUNIT_ASSERT(sX
.endsWith("mm"));
1564 CPPUNIT_ASSERT(sY
.endsWith("mm"));
1567 void ScExportTest2::testTdf85553()
1569 createScDoc("ods/tdf85553.ods");
1571 saveAndReload("MS Excel 97");
1573 ScDocument
* pDoc
= getScDoc();
1575 // Without the fix in place, this test would have failed with
1578 CPPUNIT_ASSERT_EQUAL(OUString("4.5"), pDoc
->GetString(ScAddress(2, 2, 0)));
1581 void ScExportTest2::testTdf151484()
1583 std::vector
<OUString
> aFilterNames
{ "calc8", "MS Excel 97", "Calc Office Open XML" };
1585 for (size_t i
= 0; i
< aFilterNames
.size(); ++i
)
1587 createScDoc("ods/tdf151484.ods");
1589 const OString sFailedMessage
1590 = OString::Concat("Failed on filter: ") + aFilterNames
[i
].toUtf8();
1592 saveAndReload(aFilterNames
[i
]);
1594 ScDocument
* pDoc
= getScDoc();
1596 const ScValidationData
* pData
= pDoc
->GetValidationEntry(1);
1597 CPPUNIT_ASSERT(pData
);
1599 std::vector
<ScTypedStrData
> aList
;
1600 pData
->FillSelectionList(aList
, ScAddress(0, 1, 0));
1602 // Without the fix in place, this test would have failed with
1605 // - Failed on filter: MS Excel 97
1606 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage
.getStr(), size_t(4), aList
.size());
1607 for (size_t j
= 0; j
< 4; ++j
)
1608 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage
.getStr(), double(j
+ 1),
1609 aList
[j
].GetValue());
1613 void ScExportTest2::testTdf143979()
1617 ScDocument
* pDoc
= getScDoc();
1618 OUString aCode
= "YYYY-MM\"\"MMM-DDNN";
1619 sal_Int32 nCheckPos
;
1620 SvNumFormatType nType
;
1622 SvNumberFormatter
* pFormatter
= pDoc
->GetFormatTable();
1623 pFormatter
->PutEntry(aCode
, nCheckPos
, nType
, nFormat
);
1624 ScPatternAttr
aNewAttrs(pDoc
->GetPool());
1625 SfxItemSet
& rSet
= aNewAttrs
.GetItemSet();
1626 rSet
.Put(SfxUInt32Item(ATTR_VALUE_FORMAT
, nFormat
));
1627 pDoc
->ApplyPattern(0, 0, 0, aNewAttrs
);
1628 pDoc
->SetString(ScAddress(0, 0, 0), "08/30/2021");
1629 CPPUNIT_ASSERT_EQUAL(OUString("2021-08Aug-30Mon"), pDoc
->GetString(ScAddress(0, 0, 0)));
1632 saveAndReload("calc8");
1634 ScDocument
* pDoc
= getScDoc();
1635 // Without the fix in place, this test would have failed with
1636 // - Expected: 2021-08Aug-30Mon
1637 // - Actual : 2021-A-30Mon
1638 CPPUNIT_ASSERT_EQUAL(OUString("2021-08Aug-30Mon"), pDoc
->GetString(ScAddress(0, 0, 0)));
1641 void ScExportTest2::testTdf128976()
1643 createScDoc("xls/tdf128976.xls");
1645 saveAndReload("MS Excel 97");
1647 ScDocument
* pDoc
= getScDoc();
1649 // Trying to save very small fractional default column width to XLS (where only integer values
1650 // between 0 and 255 are allowed as default) resulted in negative (-1) value after correction,
1651 // and was written as 65535 (invalid default width). As the result, all columns had large width
1652 // when reopened: 28415 (and Excel warned about invalid format).
1653 const sal_uInt16 nColumn0Width
= pDoc
->GetColWidth(SCCOL(0), SCTAB(0), false);
1654 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16
>(45), nColumn0Width
);
1657 void ScExportTest2::testTdf120502()
1659 // Create an empty worksheet; resize last column on its first sheet; export to XLSX, and check
1660 // that the last exported column number is correct
1663 ScDocument
* pDoc
= getScDoc();
1664 const SCCOL nMaxCol
= pDoc
->MaxCol(); // 0-based
1666 const auto nOldWidth
= pDoc
->GetColWidth(nMaxCol
, 0);
1667 pDoc
->SetColWidth(nMaxCol
, 0, nOldWidth
+ 100);
1669 save("Calc Office Open XML");
1670 xmlDocUniquePtr pSheet1
= parseExport("xl/worksheets/sheet1.xml");
1671 CPPUNIT_ASSERT(pSheet1
);
1673 // This was 1025 when nMaxCol+1 was 1024
1674 assertXPath(pSheet1
, "/x:worksheet/x:cols/x:col", "max", OUString::number(nMaxCol
+ 1));
1677 void ScExportTest2::testTdf131372()
1679 createScDoc("ods/tdf131372.ods");
1681 save("Calc Office Open XML");
1683 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
1684 CPPUNIT_ASSERT(pSheet
);
1686 assertXPathContent(pSheet
, "/x:worksheet/x:sheetData/x:row/x:c[1]/x:f", "NA()");
1687 assertXPathContent(pSheet
, "/x:worksheet/x:sheetData/x:row/x:c[2]/x:f", "#N/A");
1689 void ScExportTest2::testTdf81470()
1691 createScDoc("xls/tdf81470.xls");
1693 //without the fix in place, it would have crashed at export time
1694 save("Calc Office Open XML");
1696 //also check revisions are exported
1697 xmlDocUniquePtr pHeaders
= parseExport("xl/revisions/revisionHeaders.xml");
1698 CPPUNIT_ASSERT(pHeaders
);
1700 assertXPath(pHeaders
, "/x:headers/x:header[1]", "dateTime", "2014-07-11T13:46:00.000000000Z");
1701 assertXPath(pHeaders
, "/x:headers/x:header[1]", "userName", "Kohei Yoshida");
1702 assertXPath(pHeaders
, "/x:headers/x:header[2]", "dateTime", "2014-07-11T18:38:00.000000000Z");
1703 assertXPath(pHeaders
, "/x:headers/x:header[2]", "userName", "Kohei Yoshida");
1704 assertXPath(pHeaders
, "/x:headers/x:header[3]", "dateTime", "2014-07-11T18:43:00.000000000Z");
1705 assertXPath(pHeaders
, "/x:headers/x:header[3]", "userName", "Kohei Yoshida");
1708 void ScExportTest2::testTdf122331()
1710 createScDoc("ods/tdf122331.ods");
1712 save("Calc Office Open XML");
1714 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
1715 CPPUNIT_ASSERT(pSheet
);
1717 assertXPath(pSheet
, "/x:worksheet/x:sheetPr", "filterMode", "true");
1718 assertXPath(pSheet
, "/x:worksheet/x:autoFilter", "ref", "A1:B761");
1719 assertXPath(pSheet
, "/x:worksheet/x:autoFilter/x:filterColumn", "colId", "1");
1722 void ScExportTest2::testTdf83779()
1724 // Roundtripping TRUE/FALSE constants (not functions) must convert them to functions
1725 createScDoc("xlsx/tdf83779.xlsx");
1727 save("Calc Office Open XML");
1729 xmlDocUniquePtr pVmlDrawing
= parseExport("xl/worksheets/sheet1.xml");
1730 CPPUNIT_ASSERT(pVmlDrawing
);
1732 assertXPathContent(pVmlDrawing
, "/x:worksheet/x:sheetData/x:row[1]/x:c/x:f", "FALSE()");
1733 assertXPathContent(pVmlDrawing
, "/x:worksheet/x:sheetData/x:row[2]/x:c/x:f", "TRUE()");
1736 void ScExportTest2::testTdf121715_FirstPageHeaderFooterXLSX()
1738 // Check if first page header and footer are exported properly
1739 createScDoc("xlsx/tdf121715.xlsx");
1741 save("Calc Office Open XML");
1742 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1743 CPPUNIT_ASSERT(pDoc
);
1745 assertXPath(pDoc
, "/x:worksheet/x:headerFooter", "differentFirst", "true");
1746 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:firstHeader", "&CFirst Page Header");
1747 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:firstFooter", "&CFirst Page Footer");
1750 void ScExportTest2::testTdf121716_ExportEvenHeaderFooterXLSX()
1752 // Header and footer on even pages should be exported properly
1753 // If there are separate odd/even header, but only 1 footer for all pages (this is possible only in LibreOffice)
1754 // then the footer will be duplicated to have the same footer separately for even/odd pages
1756 createScDoc("ods/tdf121716_EvenHeaderFooter.ods");
1758 save("Calc Office Open XML");
1759 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1760 CPPUNIT_ASSERT(pDoc
);
1762 assertXPath(pDoc
, "/x:worksheet/x:headerFooter", "differentOddEven", "true");
1763 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddHeader",
1764 "&Lodd/right&Cpage&Rheader");
1765 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddFooter", "&Lboth&C&12page&Rfooter");
1766 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:evenHeader",
1767 "&Lpage&Cheader&Reven/left");
1768 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:evenFooter", "&Lboth&C&12page&Rfooter");
1770 pDoc
= parseExport("xl/worksheets/sheet2.xml");
1771 CPPUNIT_ASSERT(pDoc
);
1773 assertXPath(pDoc
, "/x:worksheet/x:headerFooter", "differentOddEven", "true");
1774 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddHeader", "&Coddh");
1775 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddFooter", "&Coddf");
1776 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:evenHeader", "&Cevenh");
1777 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:evenFooter", "&Levenf");
1780 void ScExportTest2::testTdf134459_HeaderFooterColorXLSX()
1782 // Colors in header and footer should be exported, and imported properly
1783 createScDoc("xlsx/tdf134459_HeaderFooterColor.xlsx");
1785 save("Calc Office Open XML");
1786 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1787 CPPUNIT_ASSERT(pDoc
);
1789 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddHeader",
1790 "&L&Kc06040l&C&K4c3789c&Rr");
1791 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddFooter",
1792 "&Ll&C&K64cf5fc&R&Kcd15aar");
1795 void ScExportTest2::testTdf134817_HeaderFooterTextWith2SectionXLSX()
1797 // Header/footer text with multiple selection should be exported, and imported properly
1798 createScDoc("xlsx/tdf134817_HeaderFooterTextWith2Section.xlsx");
1800 save("Calc Office Open XML");
1801 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1802 CPPUNIT_ASSERT(pDoc
);
1804 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddHeader",
1805 "&L&\"Abadi,Regular\"&11aaa&\"Bembo,Regular\"&20bbb");
1806 assertXPathContent(pDoc
, "/x:worksheet/x:headerFooter/x:oddFooter",
1807 "&R&\"Cambria,Regular\"&14camb&\"Dante,Regular\"&18dant");
1810 void ScExportTest2::testTdf121718_UseFirstPageNumberXLSX()
1812 // If "First page number" is not checked then useFirstPageNumb, and firstPageNumber should not be exported.
1813 createScDoc("ods/tdf121718_UseFirstPageNumber.ods");
1815 save("Calc Office Open XML");
1816 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1817 CPPUNIT_ASSERT(pDoc
);
1819 assertXPath(pDoc
, "/x:worksheet/x:pageSetup", "useFirstPageNumber", "true");
1820 assertXPath(pDoc
, "/x:worksheet/x:pageSetup", "firstPageNumber", "10");
1822 pDoc
= parseExport("xl/worksheets/sheet2.xml");
1823 CPPUNIT_ASSERT(pDoc
);
1825 assertXPathNoAttribute(pDoc
, "/x:worksheet/x:pageSetup", "useFirstPageNumber");
1826 assertXPathNoAttribute(pDoc
, "/x:worksheet/x:pageSetup", "firstPageNumber");
1829 void ScExportTest2::testHeaderFontStyleXLSX()
1831 createScDoc("xlsx/tdf134826.xlsx");
1833 ScDocument
* pDoc
= getScDoc();
1834 SfxStyleSheetBase
* pStyleSheet
1835 = pDoc
->GetStyleSheetPool()->Find(pDoc
->GetPageStyle(0), SfxStyleFamily::Page
);
1836 const SfxItemSet
& rItemSet
= pStyleSheet
->GetItemSet();
1837 const ScPageHFItem
& rHFItem
= rItemSet
.Get(ATTR_PAGE_HEADERRIGHT
);
1838 const EditTextObject
* pTextObj
= rHFItem
.GetLeftArea();
1840 std::vector
<EECharAttrib
> rLst
;
1842 // first line is bold.
1843 pTextObj
->GetCharAttribs(0, rLst
);
1844 bool bHasBold
= std::any_of(rLst
.begin(), rLst
.end(), [](const EECharAttrib
& rAttrib
) {
1845 return rAttrib
.pAttr
->Which() == EE_CHAR_WEIGHT
1846 && static_cast<const SvxWeightItem
&>(*rAttrib
.pAttr
).GetWeight() == WEIGHT_BOLD
;
1848 CPPUNIT_ASSERT_MESSAGE("First line should be bold.", bHasBold
);
1850 // second line is italic.
1851 pTextObj
->GetCharAttribs(1, rLst
);
1852 bool bHasItalic
= std::any_of(rLst
.begin(), rLst
.end(), [](const EECharAttrib
& rAttrib
) {
1853 return rAttrib
.pAttr
->Which() == EE_CHAR_ITALIC
1854 && static_cast<const SvxPostureItem
&>(*rAttrib
.pAttr
).GetPosture() == ITALIC_NORMAL
;
1856 CPPUNIT_ASSERT_MESSAGE("Second line should be italic.", bHasItalic
);
1859 void ScExportTest2::testTdf135828_Shape_Rect()
1861 if (!IsDefaultDPI())
1863 // tdf#135828 Check that the width and the height of rectangle of the shape is correct.
1864 // tdf#123613 Check the positioning, and allow massive rounding errors because of the back and
1865 // forth conversion between emu and hmm.
1866 createScDoc("xlsx/tdf135828_Shape_Rect.xlsx");
1868 save("Calc Office Open XML");
1870 xmlDocUniquePtr pDrawing
= parseExport("xl/drawings/drawing1.xml");
1871 CPPUNIT_ASSERT(pDrawing
);
1873 double nXPosOfTopleft
1874 = getXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:off", "x")
1876 double nYPosOfTopleft
1877 = getXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:off", "y")
1880 = getXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cx")
1883 = getXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cy")
1886 CPPUNIT_ASSERT_DOUBLES_EQUAL(854640, nXPosOfTopleft
, 10000);
1887 CPPUNIT_ASSERT_DOUBLES_EQUAL(-570600, nYPosOfTopleft
, 10000);
1888 CPPUNIT_ASSERT_DOUBLES_EQUAL(294840, nWidth
, 10000);
1889 CPPUNIT_ASSERT_DOUBLES_EQUAL(1988280, nHeight
, 10000);
1892 void ScExportTest2::testTdf123139XLSX()
1894 createScDoc("xlsx/tdf123139_applyAlignment.xlsx");
1896 ScDocument
* pDoc
= getScDoc();
1897 const ScPatternAttr
* pAttr
= pDoc
->GetPattern(0, 0, 0); //A1
1900 const SvxHorJustifyItem
& rJustify
= pAttr
->GetItem(ATTR_HOR_JUSTIFY
);
1901 CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Repeat
, rJustify
.GetValue());
1904 pAttr
= pDoc
->GetPattern(0, 1, 0); //A2
1907 const SfxPoolItem
& rItem
= pAttr
->GetItem(ATTR_HOR_JUSTIFY
);
1908 const SvxHorJustifyItem
& rJustify
= static_cast<const SvxHorJustifyItem
&>(rItem
);
1909 CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Center
, rJustify
.GetValue());
1913 const ScProtectionAttr
& rItem
= pAttr
->GetItem(ATTR_PROTECTION
);
1914 CPPUNIT_ASSERT(rItem
.GetProtection());
1915 CPPUNIT_ASSERT(!rItem
.GetHideFormula());
1918 pAttr
= pDoc
->GetPattern(2, 0, 0); //C1
1921 const SfxPoolItem
& rItem
= pAttr
->GetItem(ATTR_HOR_JUSTIFY
);
1922 const SvxHorJustifyItem
& rJustify
= static_cast<const SvxHorJustifyItem
&>(rItem
);
1923 CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Standard
, rJustify
.GetValue());
1927 const ScProtectionAttr
& rItem
= pAttr
->GetItem(ATTR_PROTECTION
);
1928 CPPUNIT_ASSERT(rItem
.GetProtection());
1929 CPPUNIT_ASSERT(rItem
.GetHideFormula());
1932 pAttr
= pDoc
->GetPattern(2, 1, 0); //C2
1935 const SfxPoolItem
& rItem
= pAttr
->GetItem(ATTR_HOR_JUSTIFY
);
1936 const SvxHorJustifyItem
& rJustify
= static_cast<const SvxHorJustifyItem
&>(rItem
);
1937 CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Block
, rJustify
.GetValue());
1941 const ScProtectionAttr
& rItem
= pAttr
->GetItem(ATTR_PROTECTION
);
1942 CPPUNIT_ASSERT(!rItem
.GetProtection());
1943 CPPUNIT_ASSERT(!rItem
.GetHideFormula());
1947 void ScExportTest2::testTdf123353()
1949 createScDoc("xlsx/tdf123353.xlsx");
1951 save("Calc Office Open XML");
1953 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1954 CPPUNIT_ASSERT(pDoc
);
1956 assertXPath(pDoc
, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1");
1959 void ScExportTest2::testTdf140098()
1961 createScDoc("ods/tdf140098.ods");
1963 save("Calc Office Open XML");
1965 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
1966 CPPUNIT_ASSERT(pDoc
);
1968 assertXPath(pDoc
, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1");
1971 void ScExportTest2::testTdf133688_precedents()
1973 // tdf#133688 Check that we do not export detective shapes.
1974 createScDoc("ods/tdf133688_dont_save_precedents_to_xlsx.ods");
1976 save("Calc Office Open XML");
1977 xmlDocUniquePtr pDrawing
= parseExport("xl/drawings/drawing1.xml");
1978 CPPUNIT_ASSERT(pDrawing
);
1980 // We do not export any shapes.
1981 assertXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor[1]", 0);
1984 void ScExportTest2::testTdf91251_missingOverflowRoundtrip()
1986 // tdf#91251 check whether textBox overflow property (horzOverflow and vertOverflow) is
1987 // getting preserved after roundtrip
1988 createScDoc("xlsx/tdf91251_missingOverflowRoundtrip.xlsx");
1990 save("Calc Office Open XML");
1992 xmlDocUniquePtr pDrawing
= parseExport("xl/drawings/drawing1.xml");
1993 CPPUNIT_ASSERT(pDrawing
);
1995 assertXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "horzOverflow",
1997 assertXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "horzOverflow",
2001 void ScExportTest2::testTdf137000_handle_upright()
2003 // Upright is an xml attribute of xdr:txBody/a:bodyPr. It is set when in a textbox menu we
2004 // choose, 'do not rotate this element'. Implementations are in tdf#106197 with followup
2005 // tdf#137000. tdf#149538, tdf#149551 improve the implementation to export 'upright' instead
2006 // of workaround 'rot'.
2007 createScDoc("xlsx/tdf137000_export_upright.xlsx");
2009 save("Calc Office Open XML");
2010 xmlDocUniquePtr pDrawing
= parseExport("xl/drawings/drawing1.xml");
2011 CPPUNIT_ASSERT(pDrawing
);
2013 assertXPath(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "upright", "1");
2016 void ScExportTest2::testTdf126305_DataValidatyErrorAlert()
2018 createScDoc("ods/tdf126305.ods");
2020 save("Calc Office Open XML");
2021 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
2022 CPPUNIT_ASSERT(pDoc
);
2024 assertXPath(pDoc
, "/x:worksheet/x:dataValidations/x:dataValidation[1]", "errorStyle", "stop");
2025 assertXPath(pDoc
, "/x:worksheet/x:dataValidations/x:dataValidation[2]", "errorStyle",
2027 assertXPath(pDoc
, "/x:worksheet/x:dataValidations/x:dataValidation[3]", "errorStyle",
2031 void ScExportTest2::testTdf76047_externalLink()
2033 createScDoc("xlsx/tdf76047_externalLink.xlsx");
2035 // load data from external links. (tdf76047_externalLinkSource.ods)
2036 // that file has to be in the same directory as tdf76047_externalLink.xlsx
2037 ScDocShell
* pDocSh
= getScDocShell();
2038 pDocSh
->ReloadAllLinks();
2039 ScDocument
* pDoc
= getScDoc();
2041 // compare the data loaded from external links with the expected result stored in the test file
2042 for (int nCol
= 1; nCol
<= 5; nCol
++)
2044 for (int nRow
= 3; nRow
<= 5; nRow
++)
2046 OUString aStr1
= pDoc
->GetString(ScAddress(nCol
, nRow
, 0));
2047 OUString aStr2
= pDoc
->GetString(ScAddress(nCol
, nRow
+ 5, 0));
2048 OUString aStr3
= pDoc
->GetString(ScAddress(nCol
, nRow
+ 11, 0));
2050 CPPUNIT_ASSERT_EQUAL(aStr1
, aStr3
);
2051 CPPUNIT_ASSERT_EQUAL(aStr2
, aStr3
);
2056 void ScExportTest2::testTdf87973_externalLinkSkipUnuseds()
2058 createScDoc("ods/tdf87973_externalLinkSkipUnuseds.ods");
2060 // try to load data from external link: tdf132105_external.ods
2061 // that file has to be in the same directory as tdf87973_externalLinkSkipUnuseds.ods
2062 ScDocShell
* pDocSh
= getScDocShell();
2063 pDocSh
->ReloadAllLinks();
2064 ScDocument
* pDoc
= getScDoc();
2066 // change external link to: 87973_externalSource.ods
2067 OUString aFormula
= pDoc
->GetFormula(3, 1, 0);
2068 auto nIdxOfFilename
= aFormula
.indexOf("tdf132105_external.ods");
2069 aFormula
= aFormula
.replaceAt(nIdxOfFilename
, 22, u
"87973_externalSource.ods");
2070 auto nIdxOfFile
= aFormula
.indexOf("file");
2072 // saveAndReload save the file to a temporary directory
2073 // the link must be changed to point to that directory
2074 OUString aTempFilename
= utl::CreateTempURL();
2075 auto nIdxOfTmpFile
= aTempFilename
.lastIndexOf('/');
2076 aTempFilename
= aTempFilename
.copy(0, nIdxOfTmpFile
+ 1);
2078 aFormula
= aFormula
.replaceAt(nIdxOfFile
, nIdxOfFilename
- nIdxOfFile
, aTempFilename
);
2079 pDoc
->SetFormula(ScAddress(3, 1, 0), aFormula
, formula::FormulaGrammar::GRAM_NATIVE_UI
);
2081 // tdf#138832: test the same thing with singleref link
2082 aFormula
= pDoc
->GetFormula(3, 2, 0);
2083 nIdxOfFilename
= aFormula
.indexOf("tdf132105_external.ods");
2084 aFormula
= aFormula
.replaceAt(nIdxOfFilename
, 22, u
"87973_externalSource.ods");
2085 nIdxOfFile
= aFormula
.indexOf("file");
2087 aFormula
= aFormula
.replaceAt(nIdxOfFile
, nIdxOfFilename
- nIdxOfFile
, aTempFilename
);
2088 pDoc
->SetFormula(ScAddress(3, 2, 0), aFormula
, formula::FormulaGrammar::GRAM_NATIVE_UI
);
2090 // save and load back
2091 saveAndReload("Calc Office Open XML");
2093 // check if the new filename is present in the link (and not replaced by '[2]')
2095 OUString aFormula2
= pDoc
->GetFormula(3, 1, 0);
2096 CPPUNIT_ASSERT(aFormula2
.indexOf("tdf132105_external.ods") < 0);
2097 CPPUNIT_ASSERT(aFormula2
.indexOf("87973_externalSource.ods") >= 0);
2098 aFormula2
= pDoc
->GetFormula(3, 2, 0);
2099 CPPUNIT_ASSERT(aFormula2
.indexOf("tdf132105_external.ods") < 0);
2100 CPPUNIT_ASSERT(aFormula2
.indexOf("87973_externalSource.ods") >= 0);
2103 void ScExportTest2::testTdf51022_lostPrintRange()
2105 createScDoc("ods/tdf87973_externalLinkSkipUnuseds.ods");
2107 ScDocShell
* pDocSh
= getScDocShell();
2108 pDocSh
->ReloadAllLinks();
2109 ScDocument
* pDoc
= getScDoc();
2112 ScRange
aRange1(1, 2, 0, 3, 4, 0);
2113 ScRange
aRange2(1, 6, 0, 3, 7, 0);
2114 pDoc
->AddPrintRange(0, aRange1
);
2115 pDoc
->AddPrintRange(0, aRange2
);
2117 // save and load back
2118 saveAndReload("calc8");
2120 // check if the same print ranges are present
2122 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16
>(2), pDoc
->GetPrintRangeCount(0));
2123 CPPUNIT_ASSERT_EQUAL(aRange1
, *pDoc
->GetPrintRange(0, 0));
2124 CPPUNIT_ASSERT_EQUAL(aRange2
, *pDoc
->GetPrintRange(0, 1));
2127 void ScExportTest2::testTdf138741_externalLinkSkipUnusedsCrash()
2129 createScDoc("xlsx/tdf138741_externalLinkSkipUnusedsCrash.xlsx");
2131 //without the fix in place, it would have crashed at export time
2132 save("Calc Office Open XML");
2135 void ScExportTest2::testTdf138824_linkToParentDirectory()
2137 createScDoc("ods/childDir/tdf138824_linkToParentDirectory.ods");
2139 ScDocument
* pDoc
= getScDoc();
2141 // saveAndReload save the file to a temporary directory
2142 // the link must be changed to point to that parent directory
2143 OUString aTempFilename
= utl::CreateTempURL();
2144 auto nIdxOfTmpFile
= aTempFilename
.lastIndexOf('/');
2145 nIdxOfTmpFile
= aTempFilename
.lastIndexOf('/', nIdxOfTmpFile
);
2146 aTempFilename
= aTempFilename
.copy(0, nIdxOfTmpFile
+ 1);
2148 // change external link to tmp directory
2149 OUString aFormula
= pDoc
->GetFormula(3, 1, 0);
2150 auto nIdxOfFilename
= aFormula
.indexOf("tdf138824_externalSource.ods");
2151 auto nIdxOfFile
= aFormula
.indexOf("file");
2153 aFormula
= aFormula
.replaceAt(nIdxOfFile
, nIdxOfFilename
- nIdxOfFile
, aTempFilename
);
2154 pDoc
->SetFormula(ScAddress(3, 1, 0), aFormula
, formula::FormulaGrammar::GRAM_NATIVE_UI
);
2156 save("Calc Office Open XML");
2157 xmlDocUniquePtr pDocXml
= parseExport("xl/externalLinks/_rels/externalLink1.xml.rels");
2158 CPPUNIT_ASSERT(pDocXml
);
2160 // test also the Linux specific bug tdf#121472
2161 assertXPath(pDocXml
, "/rels:Relationships/rels:Relationship", "Target",
2162 "../tdf138824_externalSource.ods");
2165 void ScExportTest2::testTdf129969()
2167 createScDoc("ods/external_hyperlink.ods");
2169 saveAndReload("Calc Office Open XML");
2170 ScDocument
* pDoc
= getScDoc();
2171 ScAddress
aPos(0, 0, 0);
2172 const EditTextObject
* pEditText
= pDoc
->GetEditText(aPos
);
2173 const SvxFieldData
* pData
= pEditText
->GetFieldData(0, 0, text::textfield::Type::URL
);
2174 const SvxURLField
* pURLData
= static_cast<const SvxURLField
*>(pData
);
2175 CPPUNIT_ASSERT(pURLData
->GetURL().endsWith("/%23folder/test.ods#Sheet2.B10"));
2178 void ScExportTest2::testTdf147088()
2180 createScDoc("fods/tdf147088.fods");
2182 saveAndReload("Calc Office Open XML");
2184 ScDocument
* pDoc
= getScDoc();
2186 // Without the fix in place, this test would have failed with
2187 // - Expected: _xffff_
2189 CPPUNIT_ASSERT_EQUAL(OUString("_xffff_"), pDoc
->GetString(0, 0, 0));
2192 void ScExportTest2::testTdf84874()
2194 createScDoc("ods/tdf84874.ods");
2196 saveAndReload("Calc Office Open XML");
2198 ScDocument
* pDoc
= getScDoc();
2200 const ScValidationData
* pData
= pDoc
->GetValidationEntry(1);
2201 OUString aTitle
, aText
;
2202 pData
->GetInput(aTitle
, aText
);
2203 sal_uInt32 nPromptTitleLen
= aTitle
.getLength();
2204 sal_uInt32 nPromptTextLen
= aText
.getLength();
2206 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(255), nPromptTitleLen
);
2207 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(255), nPromptTextLen
);
2209 ScValidErrorStyle eErrStyle
= SC_VALERR_STOP
;
2210 pData
->GetErrMsg(aTitle
, aText
, eErrStyle
);
2211 sal_uInt32 nErrorTitleLen
= aTitle
.getLength();
2212 sal_uInt32 nErrorTextLen
= aText
.getLength();
2214 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(255), nErrorTitleLen
);
2215 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(255), nErrorTextLen
);
2218 void ScExportTest2::testTdf136721_paper_size()
2220 createScDoc("xlsx/tdf136721_letter_sized_paper.xlsx");
2222 save("Calc Office Open XML");
2223 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
2224 CPPUNIT_ASSERT(pDoc
);
2226 assertXPath(pDoc
, "/x:worksheet/x:pageSetup", "paperSize", "70");
2229 void ScExportTest2::testTdf139258_rotated_image()
2231 // Check that the topleft position of the image is correct.
2232 createScDoc("ods/tdf139258_rotated_image.ods");
2234 save("Calc Office Open XML");
2236 xmlDocUniquePtr pDrawing
= parseExport("xl/drawings/drawing1.xml");
2237 CPPUNIT_ASSERT(pDrawing
);
2239 assertXPathContent(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:from/xdr:col", "1");
2240 assertXPathContent(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:from/xdr:row", "12");
2241 assertXPathContent(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:col", "6");
2242 assertXPathContent(pDrawing
, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:row", "25");
2245 void ScExportTest2::testTdf144642_RowHeightRounding()
2247 // MS Excel round down row heights to 0.75pt
2248 // MS Excel can save a row height of 28.35pt, but will display it as a row height of 27.75pt.
2249 // Calc simulates this roundings but only if the xlsx file was saved in MS Excel.
2251 createScDoc("xlsx/tdf144642_RowHeight_10mm_SavedByCalc.xlsx");
2252 ScDocument
* pDoc
= getScDoc();
2253 // 10mm == 567 twips == 28.35pt
2254 CPPUNIT_ASSERT_EQUAL(sal_uInt16(567), pDoc
->GetRowHeight(0, 0));
2255 CPPUNIT_ASSERT_EQUAL(tools::Long(567 * 26), pDoc
->GetRowHeight(0, 25, 0, true));
2257 createScDoc("xlsx/tdf144642_RowHeight_28.35pt_SavedByExcel.xlsx");
2259 // 555twips == 27.75pt == 9.79mm
2260 CPPUNIT_ASSERT_EQUAL(sal_uInt16(555), pDoc
->GetRowHeight(0, 0));
2261 CPPUNIT_ASSERT_EQUAL(tools::Long(555 * 26), pDoc
->GetRowHeight(0, 25, 0, true));
2264 void ScExportTest2::testTdf145129_DefaultRowHeightRounding()
2266 // MS Excel round down row heights to 0.75pt
2267 // Same as Tdf144642 but with default row height.
2269 createScDoc("xlsx/tdf145129_DefaultRowHeight_28.35pt_SavedByExcel.xlsx");
2270 ScDocument
* pDoc
= getScDoc();
2271 // 555twips == 27.75pt == 9.79mm
2272 CPPUNIT_ASSERT_EQUAL(sal_uInt16(555), pDoc
->GetRowHeight(0, 0));
2273 CPPUNIT_ASSERT_EQUAL(tools::Long(555 * 52), pDoc
->GetRowHeight(0, 51, 0, true));
2276 void ScExportTest2::testTdf151755_stylesLostOnXLSXExport()
2278 // Check if empty cells with custom sytle are exported, even if
2279 // there is other empty cells with default style, left of it.
2280 createScDoc("xlsx/tdf151755_stylesLostOnXLSXExport.xlsx");
2282 // Resave the xlsx file without any modification.
2283 save("Calc Office Open XML");
2284 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
2285 CPPUNIT_ASSERT(pSheet
);
2287 // Check if all the 3 empty cells with styles are saved, and have the same style id.
2288 assertXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[4]/x:c", 4);
2289 OUString aCellStyleId
= getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[4]/x:c[2]", "s");
2290 assertXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[4]/x:c[2]", "s", aCellStyleId
);
2291 assertXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[4]/x:c[3]", "s", aCellStyleId
);
2292 assertXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[4]/x:c[4]", "s", aCellStyleId
);
2295 void ScExportTest2::testTdf152581_bordercolorNotExportedToXLSX()
2297 createScDoc("xlsx/tdf152581_bordercolorNotExportedToXLSX.xlsx");
2299 // Resave the xlsx file without any modification.
2300 save("Calc Office Open XML");
2301 xmlDocUniquePtr pStyles
= parseExport("xl/styles.xml");
2302 CPPUNIT_ASSERT(pStyles
);
2304 // Check if conditional format border color is exported
2305 assertXPath(pStyles
, "/x:styleSheet/x:dxfs/x:dxf/x:border/x:left/x:color", "rgb", "FFED7D31");
2308 void ScExportTest2::testTdf140431()
2310 createScDoc("xlsx/129969-min.xlsx");
2312 saveAndReload("Calc Office Open XML");
2313 ScDocument
* pDoc
= getScDoc();
2314 ScAddress
aPos(0, 2, 0);
2315 const EditTextObject
* pEditText
= pDoc
->GetEditText(aPos
);
2316 const SvxFieldData
* pData
= pEditText
->GetFieldData(0, 0, text::textfield::Type::URL
);
2317 const SvxURLField
* pURLData
= static_cast<const SvxURLField
*>(pData
);
2318 CPPUNIT_ASSERT(pURLData
->GetURL().startsWith("file://ndhlis"));
2321 void ScExportTest2::testCheckboxFormControlXlsxExport()
2323 if (!IsDefaultDPI())
2325 // Given a document that has a checkbox form control:
2326 createScDoc("xlsx/checkbox-form-control.xlsx");
2328 // When exporting to XLSX:
2329 save("Calc Office Open XML");
2331 // Then make sure its VML markup is written and it has a correct position + size:
2332 xmlDocUniquePtr pDoc
= parseExport("xl/drawings/vmlDrawing1.vml");
2333 // Without the fix in place, this test would have failed as there was no such stream.
2334 CPPUNIT_ASSERT(pDoc
);
2335 assertXPathContent(pDoc
, "/xml/v:shape/xx:ClientData/xx:Anchor", "1, 22, 3, 3, 3, 30, 6, 1");
2338 void ScExportTest2::testButtonFormControlXlsxExport()
2340 // Given a document that has a checkbox form control:
2341 createScDoc("xlsx/button-form-control.xlsx");
2343 // When exporting to XLSX:
2344 save("Calc Office Open XML");
2346 // Then make sure its control markup is written and it has a correct position + size:
2347 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
2348 CPPUNIT_ASSERT(pDoc
);
2349 // Without the fix in place, this test would have failed with:
2350 // - XPath '//x:anchor/x:from/xdr:col' not found
2351 // i.e. the control markup was missing, the button was lost on export.
2352 assertXPathContent(pDoc
, "//x:anchor/x:from/xdr:col", "1");
2353 assertXPathContent(pDoc
, "//x:anchor/x:from/xdr:row", "3");
2354 assertXPathContent(pDoc
, "//x:anchor/x:to/xdr:col", "3");
2355 assertXPathContent(pDoc
, "//x:anchor/x:to/xdr:row", "7");
2357 // Also make sure that an empty macro attribute is not written.
2358 // Without the fix in place, this test would have failed with:
2359 // - XPath '//x:controlPr' unexpected 'macro' attribute
2360 // i.e. macro in an xlsx file was not omitted, which is considered invalid by Excel.
2361 assertXPathNoAttribute(pDoc
, "//x:controlPr", "macro");
2364 void ScExportTest2::testTdf142929_filterLessThanXLSX()
2366 // Document contains a standard filter with '<' condition.
2367 createScDoc("xlsx/tdf142929.xlsx");
2369 save("Calc Office Open XML");
2370 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
2371 CPPUNIT_ASSERT(pDoc
);
2372 assertXPath(pDoc
, "//x:customFilters/x:customFilter", "val", "2");
2373 assertXPath(pDoc
, "//x:customFilters/x:customFilter", "operator", "lessThan");
2376 void ScExportTest2::testInvalidNamedRange()
2378 // Given a document which has a named range (myname) that refers to the "1" external link, but
2379 // the link's type is xlPathMissing, when importing that document:
2380 createScDoc("xlsx/invalid-named-range.xlsx");
2382 // Then make sure that named range is ignored, as "1" can't be resolved, and exporting it back
2383 // to XLSX (without the xlPathMissing link) would corrupt the document:
2384 uno::Reference
<beans::XPropertySet
> xDocProps(mxComponent
, uno::UNO_QUERY
);
2385 uno::Reference
<container::XNameAccess
> xNamedRanges(xDocProps
->getPropertyValue("NamedRanges"),
2387 // Without the fix in place, this test would have failed, we didn't ignore the problematic named
2389 CPPUNIT_ASSERT(!xNamedRanges
->hasByName("myname"));
2392 void ScExportTest2::testExternalDefinedNameXLSX()
2394 createScDoc("xlsx/tdf144397.xlsx");
2395 saveAndReload("Calc Office Open XML");
2397 ScDocShell
* pDocSh
= getScDocShell();
2398 pDocSh
->ReloadAllLinks();
2399 ScDocument
* pDoc
= getScDoc();
2404 const ScFormulaCell
* pFC
= pDoc
->GetFormulaCell(ScAddress(1, 1, 0));
2405 sc::FormulaResultValue aRes
= pFC
->GetResult();
2406 CPPUNIT_ASSERT_EQUAL(sc::FormulaResultValue::String
, aRes
.meType
);
2407 CPPUNIT_ASSERT_EQUAL(OUString("January"), aRes
.maString
.getString());
2411 const ScFormulaCell
* pFC
= pDoc
->GetFormulaCell(ScAddress(1, 3, 0));
2412 sc::FormulaResultValue aRes
= pFC
->GetResult();
2413 CPPUNIT_ASSERT_EQUAL(sc::FormulaResultValue::String
, aRes
.meType
);
2414 CPPUNIT_ASSERT_EQUAL(OUString("March"), aRes
.maString
.getString());
2418 const ScFormulaCell
* pFC
= pDoc
->GetFormulaCell(ScAddress(1, 5, 0));
2419 sc::FormulaResultValue aRes
= pFC
->GetResult();
2420 CPPUNIT_ASSERT_EQUAL(sc::FormulaResultValue::Error
, aRes
.meType
);
2421 CPPUNIT_ASSERT_EQUAL(OUString(""), aRes
.maString
.getString());
2425 const ScFormulaCell
* pFC
= pDoc
->GetFormulaCell(ScAddress(1, 6, 0));
2426 sc::FormulaResultValue aRes
= pFC
->GetResult();
2427 CPPUNIT_ASSERT_EQUAL(sc::FormulaResultValue::String
, aRes
.meType
);
2428 CPPUNIT_ASSERT_EQUAL(OUString("June"), aRes
.maString
.getString());
2431 save("Calc Office Open XML");
2432 xmlDocUniquePtr pDocXml
= parseExport("xl/externalLinks/externalLink1.xml");
2434 CPPUNIT_ASSERT(pDocXml
);
2435 assertXPath(pDocXml
, "/x:externalLink/x:externalBook/x:sheetNames/x:sheetName", "val",
2437 assertXPath(pDocXml
, "/x:externalLink/x:externalBook/x:definedNames/x:definedName", "name",
2439 // TODO: no need for the [1] external document identifier
2440 assertXPath(pDocXml
, "/x:externalLink/x:externalBook/x:definedNames/x:definedName", "refersTo",
2441 "[1]Munka1!$A$2:$A$13");
2442 assertXPath(pDocXml
, "/x:externalLink/x:externalBook/x:sheetDataSet/x:sheetData", "sheetId",
2444 assertXPath(pDocXml
, "/x:externalLink/x:externalBook/x:sheetDataSet/x:sheetData/x:row[2]", "r",
2447 pDocXml
, "/x:externalLink/x:externalBook/x:sheetDataSet/x:sheetData/x:row[2]/x:cell/x:v",
2451 void ScExportTest2::testHyperlinkLocationXLSX()
2453 createScDoc("ods/tdf143220.ods");
2455 save("Calc Office Open XML");
2456 xmlDocUniquePtr pDoc
= parseExport("xl/worksheets/sheet1.xml");
2457 CPPUNIT_ASSERT(pDoc
);
2459 // tdf#143220 link to sheet not valid without cell reference
2460 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink[@ref='A1']", "location", "Sheet2!A1");
2462 // tdf#145079 link with defined name target didn't work because Calc added "A1" at the end
2463 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink[@ref='A2']", "location", "name");
2464 assertXPath(pDoc
, "/x:worksheet/x:hyperlinks/x:hyperlink[@ref='A3']", "location", "db");
2467 void ScExportTest2::testTdf142264ManyChartsToXLSX()
2469 // The cache size for the test should be small enough, to make sure that some charts get
2470 // unloaded in the process, and then loaded on demand properly (default is currently 200)
2471 comphelper::ScopeGuard
g([]() {
2472 std::shared_ptr
<comphelper::ConfigurationChanges
> pBatch(
2473 comphelper::ConfigurationChanges::create());
2474 officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(200, pBatch
);
2475 return pBatch
->commit();
2477 std::shared_ptr
<comphelper::ConfigurationChanges
> pBatch(
2478 comphelper::ConfigurationChanges::create());
2479 officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(20, pBatch
);
2482 createScDoc("ods/many_charts.ods");
2483 saveAndReload("Calc Office Open XML");
2485 css::uno::Reference
<css::drawing::XDrawPagesSupplier
> xSupplier(mxComponent
,
2486 css::uno::UNO_QUERY_THROW
);
2487 auto xDrawPages
= xSupplier
->getDrawPages();
2489 // No charts (or other objects) on the first sheet, and resp. first draw page
2490 css::uno::Reference
<css::drawing::XDrawPage
> xPage(xDrawPages
->getByIndex(0),
2491 css::uno::UNO_QUERY_THROW
);
2492 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xPage
->getCount());
2494 // 20 charts on the second sheet, and resp. second draw page
2495 xPage
.set(xDrawPages
->getByIndex(1), css::uno::UNO_QUERY_THROW
);
2496 // Without the fix in place, this test would have failed with
2499 // Because only the last 20 charts would get exported, all on the third sheet
2500 CPPUNIT_ASSERT_EQUAL(sal_Int32(20), xPage
->getCount());
2501 for (sal_Int32 i
= 0; i
< xPage
->getCount(); ++i
)
2503 css::uno::Reference
<css::beans::XPropertySet
> xProps(xPage
->getByIndex(i
),
2504 css::uno::UNO_QUERY_THROW
);
2505 css::uno::Reference
<css::chart2::XChartDocument
> xChart(xProps
->getPropertyValue("Model"),
2506 css::uno::UNO_QUERY_THROW
);
2507 const auto xDiagram
= xChart
->getFirstDiagram();
2508 CPPUNIT_ASSERT(xDiagram
);
2510 css::uno::Reference
<css::chart2::XCoordinateSystemContainer
> xCooSysContainer(
2511 xDiagram
, uno::UNO_QUERY_THROW
);
2513 const auto xCooSysSeq
= xCooSysContainer
->getCoordinateSystems();
2514 for (const auto& rCooSys
: xCooSysSeq
)
2516 css::uno::Reference
<css::chart2::XChartTypeContainer
> xChartTypeCont(
2517 rCooSys
, uno::UNO_QUERY_THROW
);
2518 uno::Sequence
<uno::Reference
<chart2::XChartType
>> xChartTypeSeq
2519 = xChartTypeCont
->getChartTypes();
2520 CPPUNIT_ASSERT(xChartTypeSeq
.hasElements());
2524 // 20 charts on the third sheet, and resp. third draw page
2525 xPage
.set(xDrawPages
->getByIndex(2), css::uno::UNO_QUERY_THROW
);
2526 CPPUNIT_ASSERT_EQUAL(sal_Int32(20), xPage
->getCount());
2527 for (sal_Int32 i
= 0; i
< xPage
->getCount(); ++i
)
2529 css::uno::Reference
<css::beans::XPropertySet
> xProps(xPage
->getByIndex(i
),
2530 css::uno::UNO_QUERY_THROW
);
2531 css::uno::Reference
<css::chart2::XChartDocument
> xChart(xProps
->getPropertyValue("Model"),
2532 css::uno::UNO_QUERY_THROW
);
2533 const auto xDiagram
= xChart
->getFirstDiagram();
2534 CPPUNIT_ASSERT(xDiagram
);
2536 css::uno::Reference
<css::chart2::XCoordinateSystemContainer
> xCooSysContainer(
2537 xDiagram
, uno::UNO_QUERY_THROW
);
2539 const auto xCooSysSeq
= xCooSysContainer
->getCoordinateSystems();
2540 for (const auto& rCooSys
: xCooSysSeq
)
2542 css::uno::Reference
<css::chart2::XChartTypeContainer
> xChartTypeCont(
2543 rCooSys
, uno::UNO_QUERY_THROW
);
2544 uno::Sequence
<uno::Reference
<chart2::XChartType
>> xChartTypeSeq
2545 = xChartTypeCont
->getChartTypes();
2546 CPPUNIT_ASSERT(xChartTypeSeq
.hasElements());
2551 void ScExportTest2::testTdf143929MultiColumnToODS()
2553 createScDoc("ods/two-col-shape.ods");
2556 css::uno::Reference
<css::drawing::XDrawPagesSupplier
> xSupplier(mxComponent
,
2557 css::uno::UNO_QUERY_THROW
);
2558 css::uno::Reference
<css::drawing::XDrawPage
> xPage(xSupplier
->getDrawPages()->getByIndex(0),
2559 css::uno::UNO_QUERY_THROW
);
2560 css::uno::Reference
<css::container::XIndexAccess
> xIndexAccess(xPage
,
2561 css::uno::UNO_QUERY_THROW
);
2562 css::uno::Reference
<css::drawing::XShape
> xShape(xIndexAccess
->getByIndex(0),
2563 css::uno::UNO_QUERY_THROW
);
2564 css::uno::Reference
<css::beans::XPropertySet
> xProps(xShape
, css::uno::UNO_QUERY_THROW
);
2565 css::uno::Reference
<css::text::XTextColumns
> xCols(xProps
->getPropertyValue("TextColumns"),
2566 css::uno::UNO_QUERY_THROW
);
2567 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCols
->getColumnCount());
2568 css::uno::Reference
<css::beans::XPropertySet
> xColProps(xCols
, css::uno::UNO_QUERY_THROW
);
2569 CPPUNIT_ASSERT_EQUAL(css::uno::Any(sal_Int32(1000)),
2570 xColProps
->getPropertyValue("AutomaticDistance"));
2573 saveAndReload("calc8");
2575 css::uno::Reference
<css::drawing::XDrawPagesSupplier
> xSupplier(mxComponent
,
2576 css::uno::UNO_QUERY_THROW
);
2577 css::uno::Reference
<css::drawing::XDrawPage
> xPage(xSupplier
->getDrawPages()->getByIndex(0),
2578 css::uno::UNO_QUERY_THROW
);
2579 css::uno::Reference
<css::container::XIndexAccess
> xIndexAccess(xPage
,
2580 css::uno::UNO_QUERY_THROW
);
2581 css::uno::Reference
<css::drawing::XShape
> xShape(xIndexAccess
->getByIndex(0),
2582 css::uno::UNO_QUERY_THROW
);
2583 css::uno::Reference
<css::beans::XPropertySet
> xProps(xShape
, css::uno::UNO_QUERY_THROW
);
2585 // Without the fix in place, this would have failed with:
2586 // An uncaught exception of type com.sun.star.uno.RuntimeException
2587 // - unsatisfied query for interface of type com.sun.star.text.XTextColumns!
2588 css::uno::Reference
<css::text::XTextColumns
> xCols(xProps
->getPropertyValue("TextColumns"),
2589 css::uno::UNO_QUERY_THROW
);
2590 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCols
->getColumnCount());
2591 css::uno::Reference
<css::beans::XPropertySet
> xColProps(xCols
, css::uno::UNO_QUERY_THROW
);
2592 CPPUNIT_ASSERT_EQUAL(css::uno::Any(sal_Int32(1000)),
2593 xColProps
->getPropertyValue("AutomaticDistance"));
2596 xmlDocUniquePtr pXmlDoc
= parseExport("content.xml");
2597 CPPUNIT_ASSERT(pXmlDoc
);
2598 // Without the fix in place, this would have failed with:
2601 // - In <>, XPath '/office:document-content/office:automatic-styles/style:style[@style:family='graphic']/
2602 // style:graphic-properties/style:columns' number of nodes is incorrect
2605 "/office:document-content/office:automatic-styles/style:style[@style:family='graphic']/"
2606 "style:graphic-properties/style:columns",
2607 "column-count", "2");
2608 // Only test that "column-gap" attribute exists, not its value that depends on locale (cm, in)
2611 "/office:document-content/office:automatic-styles/style:style[@style:family='graphic']/"
2612 "style:graphic-properties/style:columns",
2616 void ScExportTest2::testTdf142578()
2618 createScDoc("ods/tdf142578.ods");
2620 save("Calc Office Open XML");
2621 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
2622 CPPUNIT_ASSERT(pSheet
);
2624 // Get DxfId for color filter
2625 sal_Int32 nDxfIdColorFilter
2626 = getXPath(pSheet
, "/x:worksheet/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId")
2630 // Get DxfId for conditional formatting
2631 sal_Int32 nDxfIdCondFormat
2632 = getXPath(pSheet
, "/x:worksheet/x:conditionalFormatting/x:cfRule", "dxfId").toInt32() + 1;
2634 // Ensure they are using different dxfs
2635 CPPUNIT_ASSERT_MESSAGE("dxfID's should be different!", nDxfIdColorFilter
!= nDxfIdCondFormat
);
2637 // Check colors used by these dxfs
2638 xmlDocUniquePtr pStyles
= parseExport("xl/styles.xml");
2639 CPPUNIT_ASSERT(pStyles
);
2641 OString
sDxfColorFilterXPath("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfIdColorFilter
)
2642 + "]/x:fill/x:patternFill/x:fgColor");
2643 assertXPath(pStyles
, sDxfColorFilterXPath
, "rgb", "FF81D41A");
2645 OString
sDxfCondFormatXPath("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfIdCondFormat
)
2646 + "]/x:fill/x:patternFill/x:bgColor");
2647 assertXPath(pStyles
, sDxfCondFormatXPath
, "rgb", "FFFFCCCC");
2650 void ScExportTest2::testTdf145059()
2652 createScDoc("ods/tdf145059.ods");
2655 save("Calc Office Open XML");
2656 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
2657 CPPUNIT_ASSERT(pSheet
);
2658 xmlDocUniquePtr pStyle
= parseExport("xl/styles.xml");
2659 CPPUNIT_ASSERT(pStyle
);
2661 sal_Int32 nColorFilterDxdId
2662 = getXPath(pSheet
, "/x:worksheet/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId")
2665 // Ensure that dxf id is not -1
2666 CPPUNIT_ASSERT(nColorFilterDxdId
>= 0);
2668 // Find color by this dxfid
2669 OString sDxfIdPath
= "/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nColorFilterDxdId
+ 1)
2670 + "]/x:fill/x:patternFill/x:fgColor";
2671 assertXPath(pStyle
, sDxfIdPath
, "rgb", "FF4472C4");
2674 void ScExportTest2::testTdf130104_XLSXIndent()
2676 createScDoc("xlsx/tdf130104_indent.xlsx");
2678 // Resave the xlsx file without any modification.
2679 save("Calc Office Open XML");
2680 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
2681 CPPUNIT_ASSERT(pSheet
);
2682 xmlDocUniquePtr pStyle
= parseExport("xl/styles.xml");
2683 CPPUNIT_ASSERT(pStyle
);
2685 // Check to see whether the indents remain the same as the original ones:
2687 // Get the style index number for cell A1
2688 sal_Int32 nCellA1StyleIndex
2689 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[1]/x:c[1]", "s").toInt32() + 1;
2690 // The indent for cell A1 should be 0
2691 OString sStyleA1XPath
2692 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA1StyleIndex
) + "]/x:alignment";
2693 // (if this assertion fails, you should first check whether there is no style index set for this cell)
2694 assertXPath(pStyle
, sStyleA1XPath
, "indent", "0");
2696 sal_Int32 nCellA3StyleIndex
2697 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[3]/x:c[1]", "s").toInt32() + 1;
2698 // The indent for cell A3 should be 1
2699 OString sStyleA3XPath
2700 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA3StyleIndex
) + "]/x:alignment";
2701 assertXPath(pStyle
, sStyleA3XPath
, "indent", "1");
2703 sal_Int32 nCellA6StyleIndex
2704 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[6]/x:c[1]", "s").toInt32() + 1;
2705 OString sStyleA6XPath
2706 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA6StyleIndex
) + "]/x:alignment";
2707 assertXPath(pStyle
, sStyleA6XPath
, "indent", "2");
2709 sal_Int32 nCellA9StyleIndex
2710 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[9]/x:c[1]", "s").toInt32() + 1;
2711 OString sStyleA9XPath
2712 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA9StyleIndex
) + "]/x:alignment";
2713 assertXPath(pStyle
, sStyleA9XPath
, "indent", "3");
2715 sal_Int32 nCellA12StyleIndex
2716 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[12]/x:c[1]", "s").toInt32() + 1;
2717 OString sStyleA12XPath
2718 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA12StyleIndex
) + "]/x:alignment";
2719 assertXPath(pStyle
, sStyleA12XPath
, "indent", "4");
2721 sal_Int32 nCellA15StyleIndex
2722 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[15]/x:c[1]", "s").toInt32() + 1;
2723 OString sStyleA15XPath
2724 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA15StyleIndex
) + "]/x:alignment";
2725 assertXPath(pStyle
, sStyleA15XPath
, "indent", "5");
2727 sal_Int32 nCellA18StyleIndex
2728 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[18]/x:c[1]", "s").toInt32() + 1;
2729 OString sStyleA18XPath
2730 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA18StyleIndex
) + "]/x:alignment";
2731 assertXPath(pStyle
, sStyleA18XPath
, "indent", "6");
2733 sal_Int32 nCellA21StyleIndex
2734 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[21]/x:c[1]", "s").toInt32() + 1;
2735 OString sStyleA21XPath
2736 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA21StyleIndex
) + "]/x:alignment";
2737 assertXPath(pStyle
, sStyleA21XPath
, "indent", "7");
2739 sal_Int32 nCellA24StyleIndex
2740 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[24]/x:c[1]", "s").toInt32() + 1;
2741 OString sStyleA24XPath
2742 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA24StyleIndex
) + "]/x:alignment";
2743 assertXPath(pStyle
, sStyleA24XPath
, "indent", "8");
2745 sal_Int32 nCellA27StyleIndex
2746 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[27]/x:c[1]", "s").toInt32() + 1;
2747 OString sStyleA27XPath
2748 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA27StyleIndex
) + "]/x:alignment";
2749 assertXPath(pStyle
, sStyleA27XPath
, "indent", "9");
2751 sal_Int32 nCellA30StyleIndex
2752 = getXPath(pSheet
, "/x:worksheet/x:sheetData/x:row[30]/x:c[1]", "s").toInt32() + 1;
2753 OString sStyleA30XPath
2754 = "/x:styleSheet/x:cellXfs/x:xf[" + OString::number(nCellA30StyleIndex
) + "]/x:alignment";
2755 assertXPath(pStyle
, sStyleA30XPath
, "indent", "10");
2758 void ScExportTest2::testWholeRowBold()
2763 ScDocument
* pDoc
= getScDoc();
2765 // Make entire second row bold.
2766 ScPatternAttr
boldAttr(pDoc
->GetPool());
2767 boldAttr
.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD
, ATTR_FONT_WEIGHT
));
2768 pDoc
->ApplyPatternAreaTab(0, 1, pDoc
->MaxCol(), 1, 0, boldAttr
);
2771 saveAndReload("calc8");
2772 ScDocument
* pDoc
= getScDoc();
2773 CPPUNIT_ASSERT_EQUAL(SCCOL(INITIALCOLCOUNT
), pDoc
->GetAllocatedColumnsCount(0));
2775 pDoc
->GetPattern(pDoc
->MaxCol(), 1, 0)->GetFont(aFont
, SC_AUTOCOL_RAW
);
2776 CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD
, aFont
.GetWeight());
2778 saveAndReload("Calc Office Open XML");
2780 CPPUNIT_ASSERT_EQUAL(SCCOL(INITIALCOLCOUNT
), pDoc
->GetAllocatedColumnsCount(0));
2781 pDoc
->GetPattern(pDoc
->MaxCol(), 1, 0)->GetFont(aFont
, SC_AUTOCOL_RAW
);
2782 CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD
, aFont
.GetWeight());
2785 void ScExportTest2::testXlsxRowsOrder()
2787 createScDoc("xlsx/tdf58243.xlsx");
2788 // Make sure code in SheetDataBuffer doesn't assert columns/rows sorting.
2789 save("Calc Office Open XML");
2792 void ScExportTest2::testTdf91286()
2794 createScDoc("ods/tdf91286.ods");
2795 save("Calc Office Open XML");
2797 Reference
<packages::zip::XZipFileAccess2
> xNameAccess
2798 = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory
),
2799 maTempFile
.GetURL());
2800 const Sequence
<OUString
> aNames(xNameAccess
->getElementNames());
2801 int nImageFiles
= 0;
2802 for (const auto& rElementName
: aNames
)
2803 if (rElementName
.startsWith("xl/media/image"))
2806 // Without the accompanying fix in place, this test would have failed with:
2809 // i.e. the embedded picture would have been saved twice.
2810 CPPUNIT_ASSERT_EQUAL(1, nImageFiles
);
2813 void ScExportTest2::testTdf148820()
2815 createScDoc("xlsx/tdf148820.xlsx");
2816 save("Calc Office Open XML");
2817 xmlDocUniquePtr pSheet
= parseExport("xl/worksheets/sheet1.xml");
2818 CPPUNIT_ASSERT(pSheet
);
2820 sal_Int32 nDxfIdCondFormatFirst
2821 = getXPath(pSheet
, "/x:worksheet/x:conditionalFormatting[1]/x:cfRule", "dxfId").toInt32()
2823 sal_Int32 nDxfIdCondFormatLast
2824 = getXPath(pSheet
, "/x:worksheet/x:conditionalFormatting[20]/x:cfRule", "dxfId").toInt32()
2827 xmlDocUniquePtr pStyles
= parseExport("xl/styles.xml");
2828 CPPUNIT_ASSERT(pStyles
);
2830 OString
sDxfCondFormatXPath("/x:styleSheet/x:dxfs/x:dxf["
2831 + OString::number(nDxfIdCondFormatFirst
)
2832 + "]/x:fill/x:patternFill/x:bgColor");
2833 assertXPath(pStyles
, sDxfCondFormatXPath
, "rgb", "FF53B5A9");
2835 = OString("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfIdCondFormatLast
)
2836 + "]/x:fill/x:patternFill/x:bgColor");
2837 assertXPath(pStyles
, sDxfCondFormatXPath
, "rgb", "FFA30000");
2842 void lcl_TestEmbeddedTextInDecimal(ScDocument
& rDoc
)
2844 sal_uInt32 nNumberFormat
= rDoc
.GetNumberFormat(0, 0, 0);
2845 const SvNumberformat
* pNumberFormat
= rDoc
.GetFormatTable()->GetEntry(nNumberFormat
);
2846 const OUString
& rFormatStr
= pNumberFormat
->GetFormatstring();
2848 CPPUNIT_ASSERT_EQUAL(OUString("#,##0.000\" \"###\" \"###"), rFormatStr
);
2852 void ScExportTest2::testEmbeddedTextInDecimal()
2854 createScDoc("xlsx/embedded-text-in-decimal.xlsx");
2855 lcl_TestEmbeddedTextInDecimal(*getScDoc());
2857 // save to ODS and reload
2858 saveAndReload("calc8");
2859 lcl_TestEmbeddedTextInDecimal(*getScDoc());
2862 void ScExportTest2::testTotalsRowFunction()
2864 createScDoc("xlsx/totalsRowFunction.xlsx");
2865 saveAndReload("Calc Office Open XML");
2867 xmlDocUniquePtr pDocXml
= parseExport("xl/tables/table1.xml");
2868 CPPUNIT_ASSERT(pDocXml
);
2869 assertXPath(pDocXml
, "/x:table/x:tableColumns/x:tableColumn[5]", "totalsRowFunction",
2872 ScDocument
* pDoc
= getScDoc();
2873 pDoc
->InsertCol(ScRange(3, 0, 0, 3, pDoc
->MaxRow(), 0)); // Insert col 4
2874 saveAndReload("Calc Office Open XML");
2876 xmlDocUniquePtr pDocXml
= parseExport("xl/tables/table1.xml");
2877 CPPUNIT_ASSERT(pDocXml
);
2878 assertXPathNoAttribute(pDocXml
, "/x:table/x:tableColumns/x:tableColumn[5]",
2879 "totalsRowFunction");
2880 assertXPath(pDocXml
, "/x:table/x:tableColumns/x:tableColumn[6]", "totalsRowFunction",
2885 void ScExportTest2::testAutofilterHiddenButton()
2887 createScDoc("xlsx/hiddenButton.xlsx");
2888 saveAndReload("Calc Office Open XML");
2889 xmlDocUniquePtr pDocXml
= parseExport("xl/tables/table1.xml");
2890 CPPUNIT_ASSERT(pDocXml
);
2891 for (int i
= 1; i
<= 5; i
++)
2893 auto sPath
= "/x:table/x:autoFilter/x:filterColumn[" + std::to_string(i
) + "]";
2894 assertXPath(pDocXml
, sPath
.c_str(), "hiddenButton", "1");
2898 CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest2
);
2900 CPPUNIT_PLUGIN_IMPLEMENT();
2902 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */