diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-25 14:38:30 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-25 14:51:11 -0400 |
commit | d5d96b15551fb685a99a4ee4217a152e00bc0dbf (patch) | |
tree | e48ab5b3d765b4344d14ee997b7d907201513612 | |
parent | a8bf709911f84492624d8ebb12cb0d92bc2ee730 (diff) |
fdo#60740: Export multi-line formula results to ods without UNO API.
Change-Id: I69391a9d2ffb0afae7f40c8449196c986375db3f
-rw-r--r-- | sc/inc/formulacell.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 5 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.cxx | 40 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.hxx | 2 |
4 files changed, 45 insertions, 3 deletions
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 985aebe5f4bf..c8a7414e4528 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -310,6 +310,7 @@ public: void SetResultToken( const formula::FormulaToken* pToken ); double GetResultDouble() const; + OUString GetResultString() const; void SetErrCode( sal_uInt16 n ); bool IsHyperLinkCell() const; diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index a7491a224ffb..32238cda798d 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -1705,6 +1705,11 @@ double ScFormulaCell::GetResultDouble() const return aResult.GetDouble(); } +OUString ScFormulaCell::GetResultString() const +{ + return aResult.GetString(); +} + void ScFormulaCell::SetResultMatrix( SCCOL nCols, SCROW nRows, const ScConstMatrixRef& pMat, formula::FormulaToken* pUL ) { aResult.SetMatrix(nCols, nRows, pMat, pUL); diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index 10da5ff58889..42cac6d5cfb2 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -3352,9 +3352,7 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount) else if (aCell.nType == table::CellContentType_FORMULA && IsMultiLineFormulaCell(aCell)) { bEditCell = true; - uno::Reference<text::XText> xText(xCurrentTableCellRange->getCellByPosition(aCell.aCellAddress.Column, aCell.aCellAddress.Row), uno::UNO_QUERY); - if ( xText.is()) - GetTextParagraphExport()->exportText(xText, false, false); + WriteMultiLineFormulaResult(aCell.maBaseCell.mpFormula); } else { @@ -3404,6 +3402,42 @@ void ScXMLExport::WriteEditCell(const EditTextObject* pText) flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSecEnd); } +void ScXMLExport::WriteMultiLineFormulaResult(const ScFormulaCell* pCell) +{ + OUString aElemName = GetNamespaceMap().GetQNameByKey(XML_NAMESPACE_TEXT, GetXMLToken(XML_P)); + + OUString aResStr = pCell->GetResultString(); + const sal_Unicode* p = aResStr.getStr(); + const sal_Unicode* pEnd = p + static_cast<size_t>(aResStr.getLength()); + const sal_Unicode* pPara = p; // paragraph head. + for (; p != pEnd; ++p) + { + if (*p != '\n') + continue; + + // flush the paragraph. + OUString aContent; + if (*pPara == '\n') + ++pPara; + if (p > pPara) + aContent = OUString(pPara, p-pPara); + + SvXMLElementExport aElem(*this, aElemName, false, false); + Characters(aContent); + + pPara = p; + } + + OUString aContent; + if (*pPara == '\n') + ++pPara; + if (pEnd > pPara) + aContent = OUString(pPara, pEnd-pPara); + + SvXMLElementExport aElem(*this, aElemName, false, false); + Characters(aContent); +} + void ScXMLExport::ExportShape(const uno::Reference < drawing::XShape >& xShape, awt::Point* pPoint) { uno::Reference < beans::XPropertySet > xShapeProps ( xShape, uno::UNO_QUERY ); diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx index 7a52297ff7a9..4276e8eb9a0e 100644 --- a/sc/source/filter/xml/xmlexprt.hxx +++ b/sc/source/filter/xml/xmlexprt.hxx @@ -61,6 +61,7 @@ class ScXMLCachedRowAttrAccess; class ScRangeName; class ScXMLEditAttributeMap; class EditTextObject; +class ScFormulaCell; typedef std::vector< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > > ScMyXShapesVec; @@ -180,6 +181,7 @@ class ScXMLExport : public SvXMLExport void WriteTable(sal_Int32 nTable, const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet>& xTable); void WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount); void WriteEditCell(const EditTextObject* pText); + void WriteMultiLineFormulaResult(const ScFormulaCell* pCell); void WriteAreaLink(const ScMyCell& rMyCell); void WriteAnnotation(ScMyCell& rMyCell); void WriteDetective(const ScMyCell& rMyCell); |