summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-08-24 23:24:13 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-08-25 14:51:10 -0400
commit882bee5ede38b6ed4e1ec870d835546868c6586d (patch)
tree843940070a83491b73f1ff9d964e044ad80b90d2
parent0d57434180db6c8eda8c5b9b704f8a1c18b371df (diff)
fdo#60740: Export edit cells to ods without using UNO API.
Change-Id: If571d99060f87fd00e215fd93da1654fdcb50197
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx90
-rw-r--r--sc/source/filter/xml/xmlexprt.hxx2
2 files changed, 88 insertions, 4 deletions
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index b94ccc245fe8..1f0e2529058a 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3059,6 +3059,55 @@ void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadshe
}
}
+namespace {
+
+void flushParagraph(
+ ScXMLExport& rExport, const OUString& rParaText,
+ UniReference<XMLPropertySetMapper> xMapper, UniReference<SvXMLAutoStylePoolP> xStylePool,
+ const ScXMLEditAttributeMap& rAttrMap,
+ std::vector<editeng::SectionAttribute>::const_iterator it, std::vector<editeng::SectionAttribute>::const_iterator itEnd )
+{
+ if (it == itEnd)
+ return;
+
+ OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
+ XML_NAMESPACE_TEXT, GetXMLToken(XML_P));
+ SvXMLElementExport aElemP(rExport, aElemName, false, false);
+
+ for (; it != itEnd; ++it)
+ {
+ const editeng::SectionAttribute& rSec = *it;
+
+ const sal_Unicode* pBeg = rParaText.getStr();
+ std::advance(pBeg, rSec.mnStart);
+ const sal_Unicode* pEnd = pBeg;
+ std::advance(pEnd, rSec.mnEnd-rSec.mnStart);
+
+ OUString aContent(pBeg, pEnd-pBeg);
+
+ std::vector<XMLPropertyState> aPropStates;
+ toXMLPropertyStates(aPropStates, rSec.maAttributes, xMapper, rAttrMap);
+ OUString aStyleName = xStylePool->Find(XML_STYLE_FAMILY_TEXT_TEXT, OUString(), aPropStates);
+
+ if (aStyleName.isEmpty())
+ {
+ // Unformatted section.
+ rExport.Characters(aContent);
+ }
+ else
+ {
+ // Formatted section with automatic style.
+ rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, aStyleName);
+ aElemName = rExport.GetNamespaceMap().GetQNameByKey(
+ XML_NAMESPACE_TEXT, GetXMLToken(XML_SPAN));
+ SvXMLElementExport aElem(rExport, aElemName, false, false);
+ rExport.Characters(aContent);
+ }
+ }
+}
+
+}
+
void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
{
// nEqualCellCount is the number of additional cells
@@ -3214,12 +3263,10 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
if (!bIsEmpty)
{
- if (aCell.nType == table::CellContentType_TEXT && IsEditCell(aCell))
+ if (aCell.nType == table::CellContentType_TEXT && aCell.maBaseCell.meType == CELLTYPE_EDIT)
{
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);
+ WriteEditCell(aCell.maBaseCell.mpEditText);
}
else if (aCell.nType == table::CellContentType_FORMULA && IsMultiLineFormulaCell(aCell))
{
@@ -3241,6 +3288,41 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
IncrementProgressBar(bEditCell);
}
+void ScXMLExport::WriteEditCell(const EditTextObject* pText)
+{
+ UniReference<XMLPropertySetMapper> xMapper = GetTextParagraphExport()->GetTextPropMapper()->getPropertySetMapper();
+ UniReference<SvXMLAutoStylePoolP> xStylePool = GetAutoStylePool();
+ const ScXMLEditAttributeMap& rAttrMap = GetEditAttributeMap();
+
+ // Get raw paragraph texts first.
+ std::vector<OUString> aParaTexts;
+ sal_Int32 nParaCount = pText->GetParagraphCount();
+ aParaTexts.reserve(nParaCount);
+ for (sal_Int32 i = 0; i < nParaCount; ++i)
+ aParaTexts.push_back(pText->GetText(i));
+
+ // Get all section data and iterate through them.
+ std::vector<editeng::SectionAttribute> aAttrs;
+ pText->GetAllSectionAttributes(aAttrs);
+ std::vector<editeng::SectionAttribute>::const_iterator itSec = aAttrs.begin(), itSecEnd = aAttrs.end();
+ std::vector<editeng::SectionAttribute>::const_iterator itPara = itSec;
+ size_t nCurPara = 0; // current paragraph
+ for (; itSec != itSecEnd; ++itSec)
+ {
+ const editeng::SectionAttribute& rSec = *itSec;
+ if (nCurPara == rSec.mnParagraph)
+ // Still in the same paragraph.
+ continue;
+
+ // Start of a new paragraph. Flush the old paragraph.
+ flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSec);
+ nCurPara = rSec.mnParagraph;
+ itPara = itSec;
+ }
+
+ flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSecEnd);
+}
+
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 3f01dfee50b4..7a52297ff7a9 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -60,6 +60,7 @@ class ScAddress;
class ScXMLCachedRowAttrAccess;
class ScRangeName;
class ScXMLEditAttributeMap;
+class EditTextObject;
typedef std::vector< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > > ScMyXShapesVec;
@@ -178,6 +179,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 WriteAreaLink(const ScMyCell& rMyCell);
void WriteAnnotation(ScMyCell& rMyCell);
void WriteDetective(const ScMyCell& rMyCell);