add error to office:value-type for calc cells and fdo#51810

For cached value import we need the information which cells are error
cells. For ODF 1.2 extended we therefore export now calcext:office-value
with the additional value "error".

Change-Id: I9bc988ea4924bea767ba5e504b77f6a16e51a82e
This commit is contained in:
Markus Mohrhard 2013-04-24 18:45:15 +02:00
parent 6bec369008
commit a8b7c72425
3 changed files with 59 additions and 20 deletions

View File

@ -21,6 +21,7 @@
#define XMLOFF_NUMEHELP_HXX
#include "sal/config.h"
#include "xmloff/xmlnmspe.hxx"
#include "xmloff/dllapi.h"
#include <sal/types.h>
#include <com/sun/star/frame/XModel.hpp>
@ -59,7 +60,6 @@ class XMLOFF_DLLPUBLIC XMLNumberFormatAttributesExportHelper
const OUString sEmpty;
const OUString sStandardFormat;
const OUString sType;
const OUString sAttrValueType;
const OUString sAttrValue;
const OUString sAttrDateValue;
const OUString sAttrTimeValue;
@ -101,14 +101,15 @@ public :
void WriteAttributes(const sal_Int16 nTypeKey,
const double& rValue,
const OUString& rCurrencySymbol,
sal_Bool bExportValue = sal_True);
sal_Bool bExportValue = sal_True, sal_uInt16 nNamespace = XML_NAMESPACE_OFFICE);
void SetNumberFormatAttributes(const sal_Int32 nNumberFormat,
const double& rValue,
sal_Bool bExportValue = sal_True);
sal_Bool bExportValue = sal_True, sal_uInt16 nNamespace = XML_NAMESPACE_OFFICE);
void SetNumberFormatAttributes(const OUString& rValue,
const OUString& rCharacters,
sal_Bool bExportValue = sal_True,
sal_Bool bExportTypeAttribute = sal_True);
sal_Bool bExportTypeAttribute = sal_True,
sal_uInt16 nNamespace = XML_NAMESPACE_OFFICE);
};
#endif

View File

@ -2884,6 +2884,9 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
}
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
aCell.nNumberFormat, aCell.fValue);
if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
aCell.nNumberFormat, aCell.fValue, false, XML_NAMESPACE_CALC_EXT);
}
break;
case table::CellContentType_TEXT :
@ -2893,6 +2896,9 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
OUString sFormula(lcl_GetRawString(pDoc, aCellPos));
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
sFormula, aCell.sStringValue, true, true);
if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
sFormula, aCell.sStringValue, false, true, XML_NAMESPACE_CALC_EXT);
}
}
break;
@ -2919,7 +2925,18 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula.copy(1, sOUFormula.getLength() - 2), false ));
}
}
if (pFormulaCell->IsValue())
if (pFormulaCell->GetErrCode())
{
GetCellText(aCell, aCellPos);
AddAttribute(sAttrValueType, XML_STRING);
AddAttribute(sAttrStringValue, aCell.sStringValue);
if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
{
//export calcext:value-type="error"
AddAttribute(XML_NAMESPACE_CALC_EXT,XML_VALUE_TYPE, OUString("error"));
}
}
else if (pFormulaCell->IsValue())
{
bool bIsStandard;
OUString sCurrency;
@ -2927,15 +2944,31 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
if (bIsStandard)
{
if (pDoc)
{
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
pFormulaCell->GetStandardFormat(*pDoc->GetFormatTable(), 0),
pDoc->GetValue( aCellPos ));
if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
{
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
pFormulaCell->GetStandardFormat(*pDoc->GetFormatTable(), 0),
pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT);
}
}
}
else
{
if (pDoc)
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
{
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
{
GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
aCell.nNumberFormat, pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT );
}
}
}
}
else
@ -2945,6 +2978,10 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
{
AddAttribute(sAttrValueType, XML_STRING);
AddAttribute(sAttrStringValue, aCell.sStringValue);
if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
{
AddAttribute(XML_NAMESPACE_CALC_EXT,XML_VALUE_TYPE, XML_STRING);
}
}
}
}

View File

@ -60,7 +60,6 @@ XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper(
pExport(&rTempExport),
sStandardFormat(XML_STANDARDFORMAT),
sType(XML_TYPE),
sAttrValueType(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE))),
sAttrValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE))),
sAttrDateValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_DATE_VALUE))),
sAttrTimeValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_TIME_VALUE))),
@ -384,12 +383,13 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
const sal_Int16 nTypeKey,
const double& rValue,
const OUString& rCurrency,
sal_Bool bExportValue)
sal_Bool bExportValue, sal_uInt16 nNamespace)
{
if (!pExport)
return;
sal_Bool bWasSetTypeAttribute = sal_False;
OUString sAttrValType = pExport->GetNamespaceMap().GetQNameByKey( nNamespace, GetXMLToken(XML_VALUE_TYPE));
switch(nTypeKey & ~util::NumberFormat::DEFINED)
{
case 0:
@ -399,7 +399,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_FLOAT);
pExport->AddAttribute(sAttrValType, XML_FLOAT);
bWasSetTypeAttribute = sal_True;
}
} // No Break
@ -407,7 +407,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_PERCENTAGE);
pExport->AddAttribute(sAttrValType, XML_PERCENTAGE);
bWasSetTypeAttribute = sal_True;
}
} // No Break
@ -415,7 +415,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_CURRENCY);
pExport->AddAttribute(sAttrValType, XML_CURRENCY);
if (!rCurrency.isEmpty())
pExport->AddAttribute(sAttrCurrency, rCurrency);
bWasSetTypeAttribute = sal_True;
@ -435,7 +435,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_DATE);
pExport->AddAttribute(sAttrValType, XML_DATE);
bWasSetTypeAttribute = sal_True;
}
if (bExportValue)
@ -453,7 +453,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_TIME);
pExport->AddAttribute(sAttrValType, XML_TIME);
bWasSetTypeAttribute = sal_True;
}
if (bExportValue)
@ -468,7 +468,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_BOOLEAN);
pExport->AddAttribute(sAttrValType, XML_BOOLEAN);
bWasSetTypeAttribute = sal_True;
}
if (bExportValue)
@ -501,7 +501,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
{
if (!bWasSetTypeAttribute)
{
pExport->AddAttribute(sAttrValueType, XML_FLOAT);
pExport->AddAttribute(sAttrValType, XML_FLOAT);
bWasSetTypeAttribute = sal_True;
if (bExportValue)
{
@ -517,14 +517,14 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(
}
void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue)
const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue, sal_uInt16 nNamespace)
{
if (pExport)
{
bool bIsStandard;
OUString sCurrency;
sal_Int16 nTypeKey = GetCellType(nNumberFormat, sCurrency, bIsStandard);
WriteAttributes(nTypeKey, rValue, sCurrency, bExportValue);
WriteAttributes(nTypeKey, rValue, sCurrency, bExportValue, nNamespace);
}
else {
OSL_FAIL("no SvXMLExport given");
@ -533,12 +533,13 @@ void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
const OUString& rValue, const OUString& rCharacters,
sal_Bool bExportValue, sal_Bool bExportTypeAttribute)
sal_Bool bExportValue, sal_Bool bExportTypeAttribute,
sal_uInt16 nNamespace)
{
if (pExport)
{
if (bExportTypeAttribute)
pExport->AddAttribute(sAttrValueType, XML_STRING);
pExport->AddAttribute(nNamespace, XML_VALUE_TYPE, XML_STRING);
if (bExportValue && !rValue.isEmpty() && (rValue != rCharacters))
pExport->AddAttribute(sAttrStringValue, rValue);
}