LibreOffice Module sc (master) 1
XMLExportDDELinks.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "XMLExportDDELinks.hxx"
21#include <xmloff/xmltoken.hxx>
24#include "xmlexprt.hxx"
25#include <unonames.hxx>
26#include <document.hxx>
27#include <scmatrix.hxx>
28#include <com/sun/star/sheet/XDDELink.hpp>
29#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
30#include <com/sun/star/container/XIndexAccess.hpp>
31#include <com/sun/star/beans/XPropertySet.hpp>
32
33using namespace com::sun::star;
34using namespace xmloff::token;
35
37 : rExport(rTempExport)
38{
39}
40
41void ScXMLExportDDELinks::WriteCell(const ScMatrixValue& aVal, sal_Int32 nRepeat)
42{
43 bool bString = ScMatrix::IsNonValueType(aVal.nType);
44 bool bEmpty = ScMatrix::IsEmptyType(aVal.nType);
45
46 if (!bEmpty)
47 {
48 if (bString)
49 {
52 }
53 else
54 {
55 OUStringBuffer aBuf;
59 }
60 }
61
62 if (nRepeat > 1)
63 {
65 }
67}
68
69void ScXMLExportDDELinks::WriteTable(const sal_Int32 nPos)
70{
72 if (!pDoc)
73 return;
74
75 const ScMatrix* pMatrix = pDoc->GetDdeLinkResultMatrix(static_cast<sal_uInt16>(nPos));
76 if (!pMatrix)
77 return;
78
79 SCSIZE nCols, nRows;
80 pMatrix->GetDimensions(nCols, nRows);
81
83 if (nCols > 1)
84 {
86 }
87 {
89 }
90
91 for (SCSIZE nRow = 0; nRow < nRows; ++nRow)
92 {
93 sal_Int32 nRepeat = 0;
94 ScMatrixValue aPrevVal;
96 for (SCSIZE nCol = 0; nCol < nCols; ++nCol, ++nRepeat)
97 {
98 ScMatrixValue aVal = pMatrix->Get(nCol, nRow);
99 if (nCol > 0 && aVal != aPrevVal)
100 {
101 // Cell value differs. Flush the cell content.
102 WriteCell(aPrevVal, nRepeat);
103 nRepeat = 0;
104 }
105 aPrevVal = aVal;
106 }
107
108 WriteCell(aPrevVal, nRepeat);
109 }
110}
111
112void ScXMLExportDDELinks::WriteDDELinks(const uno::Reference<sheet::XSpreadsheetDocument>& xSpreadDoc)
113{
114 uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
115 if (!xPropertySet.is())
116 return;
117
118 uno::Reference<container::XIndexAccess> xIndex(xPropertySet->getPropertyValue(SC_UNO_DDELINKS), uno::UNO_QUERY);
119 if (!xIndex.is())
120 return;
121
122 sal_Int32 nCount = xIndex->getCount();
123 if (!nCount)
124 return;
125
127 for (sal_Int32 nDDELink = 0; nDDELink < nCount; ++nDDELink)
128 {
129 uno::Reference<sheet::XDDELink> xDDELink(xIndex->getByIndex(nDDELink), uno::UNO_QUERY);
130 if (xDDELink.is())
131 {
133 {
134 rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, xDDELink->getApplication());
138 sal_uInt8 nMode;
139 if (rExport.GetDocument() &&
140 rExport.GetDocument()->GetDdeLinkMode(nDDELink, nMode))
141 {
142 switch (nMode)
143 {
144 case SC_DDE_ENGLISH :
146 break;
147 case SC_DDE_TEXT :
149 break;
150 }
151 }
153 }
154 WriteTable(nDDELink);
155 }
156 }
157}
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
SC_DLLPUBLIC const ScMatrix * GetDdeLinkResultMatrix(size_t nDdePos) const
Returns the result matrix of the specified DDE link.
Definition: documen8.cxx:982
bool GetDdeLinkMode(size_t nDdePos, sal_uInt8 &rnMode) const
Returns the link mode of the specified DDE link.
Definition: documen8.cxx:972
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:101
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
@ATTENTION: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string!
Definition: scmatrix.cxx:3253
static bool IsEmptyType(ScMatValType nType)
Empty, but not empty path or any other type.
Definition: scmatrix.hxx:193
static bool IsNonValueType(ScMatValType nType)
String, empty or empty path, but not value nor boolean.
Definition: scmatrix.hxx:179
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
Definition: scmatrix.cxx:3143
ScDocument * GetDocument()
Definition: xmlexprt.hxx:240
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
const OUString & getString() const
int nCount
const sal_uInt8 SC_DDE_TEXT
Definition: document.hxx:303
const sal_uInt8 SC_DDE_ENGLISH
Definition: document.hxx:302
sal_uInt16 nPos
aBuf
XML_TABLE_ROW
XML_TABLE
XML_INTO_ENGLISH_NUMBER
XML_DDE_SOURCE
XML_AUTOMATIC_UPDATE
XML_TRUE
XML_TABLE_COLUMN
XML_DDE_APPLICATION
XML_CONVERSION_MODE
XML_DDE_LINKS
XML_FLOAT
XML_KEEP_TEXT
XML_STRING
XML_VALUE
XML_STRING_VALUE
XML_VALUE_TYPE
XML_NUMBER_COLUMNS_REPEATED
XML_DDE_LINK
XML_TABLE_CELL
XML_DDE_TOPIC
XML_DDE_ITEM
Try NOT to use this struct.
Definition: scmatrix.hxx:53
ScMatValType nType
Definition: scmatrix.hxx:56
double fVal
Definition: scmatrix.hxx:54
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
Definition: scmatrix.hxx:59
unsigned char sal_uInt8
constexpr OUStringLiteral SC_UNO_DDELINKS
Definition: unonames.hxx:40
constexpr sal_uInt16 XML_NAMESPACE_TABLE
constexpr sal_uInt16 XML_NAMESPACE_OFFICE