Description: Wrote a function in BASIC that formats a Calc range using .autoformat function, see documentation here: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1table_1_1XAutoFormattable.html In the API reference it says it throws the error com::sun::star::lang::IllegalArgumentException if the specified AutoFormat does not exist. However, calling .autoformat("Default") throws this error, even though "Default" is an autoformat that exists. Steps to Reproduce: 1. Open a calc document 2. In any BASIC macro routine, copy in the following line of code: thisComponent.Sheets(0).getCellRangeByName("A1:F14").autoformat("Default") 3. Running this macro results in the IllegalArgumentException 4. Confirm that the syntax is correct by using a different autoformat like: thisComponent.Sheets(0).getCellRangeByName("A1:F14").autoformat("Green") Actual Results: IllegalArgumentException Expected Results: Calc Range Autoformatted using "Default" autoformatting Reproducible: Always User Profile Reset: Yes Additional Info: User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Reproduced in Version: 5.4.0.0.alpha0+ Build ID: 597a2f5d5bd37443262b0775b8439bc3502aef1b CPU threads: 4; OS: Linux 4.8; UI render: default; VCL: gtk2; Locale: ca-ES (ca_ES.UTF-8); Calc: group and Version: 5.2.0.0.alpha1+ Build ID: 5b168b3fa568e48e795234dc5fa454bf24c9805e CPU Threads: 4; OS Version: Linux 4.8; UI Render: default; Locale: ca-ES (ca_ES.UTF-8) but not in Version: 5.0.0.0.alpha1+ Build ID: 0db96caf0fcce09b87621c11b584a6d81cc7df86 Locale: ca-ES (ca_ES.UTF-8)
I submitted this patch for review: https://gerrit.libreoffice.org/#/c/37362/
Some explanation: autoformat code in macro is called here: 5424 ScAutoFormat* pAutoFormat = ScGlobal::GetOrCreateAutoFormat(); 5425 ScAutoFormat::const_iterator it = pAutoFormat->find(aName); 5426 if (it != pAutoFormat->end()) 5427 { 5428 ScAutoFormat::const_iterator itBeg = pAutoFormat->begin(); 5429 size_t nIndex = std::distance(itBeg, it); 5430 pDocSh->GetDocFunc().AutoFormat(aRange, nullptr, nIndex, true); 5431 } 5432 else 5433 throw lang::IllegalArgumentException(); (see http://opengrok.libreoffice.org/xref/core/sc/source/ui/unoobj/cellsuno.cxx#5418) pAutoFormat contains a map (m_Data) which indeed includes "Default" when testing on gdb 310 class SC_DLLPUBLIC ScAutoFormat 311 { 312 typedef std::map<OUString, std::unique_ptr<ScAutoFormatData>, DefaultFirstEntry> MapType; 313 MapType m_Data; (see http://opengrok.libreoffice.org/xref/core/sc/inc/autoform.hxx#ScAutoFormat) find call line 5425 from cellsuno.cxx can't find "Default" entry in the map and always returns itEnd The problem is DefaultFirstEntry 911 bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) const 912 { 913 OUString aStrStandard(ScGlobal::GetRscString(STR_STYLENAME_STANDARD)); 914 if ( ScGlobal::GetpTransliteration()->isEqual( left, aStrStandard ) ) 915 return true; 916 if ( ScGlobal::GetpTransliteration()->isEqual( right, aStrStandard ) ) 917 return false; 918 return ScGlobal::GetCollator()->compareString( left, right) < 0; 919 } (see http://opengrok.libreoffice.org/xref/core/sc/source/core/tool/autoform.cxx#911) If a parameter corresponds to aStrStandard, it can return true or false (according if it's left or right parameter). In my case, it always return true. So we must first check if left and right parameter are equal and return false in this case.
Julien Nabet committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=965494c544dd8f35ae83b7cf38549009da06c367 tdf#107572: retrieve Default autoformat It will be available in 5.4.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
For 5.3 branch: https://gerrit.libreoffice.org/#/c/37487/
Julien Nabet committed a patch related to this issue. It has been pushed to "libreoffice-5-3": http://cgit.freedesktop.org/libreoffice/core/commit/?id=9fd3f402e7a6dfe133433d05de7452f32e1c41ba&h=libreoffice-5-3 tdf#107572: retrieve Default autoformat It will be available in 5.3.4. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Xisco Fauli committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/4c9be555e4a12e4c4440b941d3de72644683fb0e tdf#107572: sc_macros: Add unittest It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.