21#include <document.hxx>
26#include <progress.hxx>
27#include <rtl/tencinfo.h>
30#include <rtl/strbuf.hxx>
31#include <osl/diagnose.h>
36 const ScAddress& rOutPos,
const rtl_TextEncoding eNach )
50 const ScRange&rRange,
const rtl_TextEncoding eCharSet )
52 OSL_ENSURE( rRange.
aStart <= rRange.
aEnd,
"*ScExportDif(): Range not sorted!" );
54 "ScExportDif(): only one table please!" );
57 if ( eStreamCharSet != eCharSet )
61 OString aStrDelimEncoded;
62 OUString aStrDelimDecoded;
63 bool bContextOrNotAsciiEncoding;
64 if ( eCharSet == RTL_TEXTENCODING_UNICODE )
67 bContextOrNotAsciiEncoding =
false;
71 aStrDelimEncoded = OString(&cStrDelim, 1, eCharSet);
72 rtl_TextEncodingInfo aInfo;
73 aInfo.StructSize =
sizeof(aInfo);
74 if ( rtl_getTextEncodingInfo( eCharSet, &aInfo ) )
76 bContextOrNotAsciiEncoding =
77 (((aInfo.Flags & RTL_TEXTENCODING_INFO_CONTEXT) != 0) ||
78 ((aInfo.Flags & RTL_TEXTENCODING_INFO_ASCII) == 0));
79 if ( bContextOrNotAsciiEncoding )
80 aStrDelimDecoded = OStringToOUString(aStrDelimEncoded, eCharSet);
83 bContextOrNotAsciiEncoding =
false;
86 const char p2DoubleQuotes_LF[] =
"\"\"\n";
87 const char pSpecDataType_LF[] =
"-1,0\n";
88 const char pEmptyData[] =
"1,0\n\"\"\n";
89 const char pStringData[] =
"1,0\n";
90 const char pNumData[] =
"0,";
91 const char pNumDataERROR[] =
"0,0\nERROR\n";
106 OSL_ENSURE( pDoc->
HasTable( nTab ),
"*ScExportDif(): Table not existent!" );
108 pDoc->
GetName( nTab, aString );
119 + OUString::number(
static_cast<sal_Int32
>(nNumCols))
121 + p2DoubleQuotes_LF);
128 + OUString::number(
static_cast<sal_Int32
>(nNumRows))
130 + p2DoubleQuotes_LF);
135 aOS.append(OUString::Concat(
pKeyDATA)
137 + p2DoubleQuotes_LF);
144 for( nRowCnt = rRange.
aStart.
Row() ; nRowCnt <= nEndRow ; nRowCnt++ )
146 assert( aOS.isEmpty() &&
"aOS should be empty");
147 aOS.append(OUString::Concat(pSpecDataType_LF)
152 for( nColCnt = rRange.
aStart.
Col() ; nColCnt <= nEndCol ; nColCnt++ )
154 assert( aOS.isEmpty() &&
"aOS should be empty");
155 bool bWriteStringData =
false;
161 aOS.append(pEmptyData);
165 aOS.append(pNumData + aString +
"\nV\n");
170 bWriteStringData =
true;
174 aOS.append(pNumDataERROR);
178 aOS.append(pNumData + aString +
"\nV\n");
183 bWriteStringData =
true;
190 if ( !bWriteStringData )
201 assert( aOS.isEmpty() &&
"aOS should be empty");
202 OUString aTmpStr = aString;
203 aOS.append(pStringData);
206 if ( eCharSet == RTL_TEXTENCODING_UNICODE )
209 OUString strFrom(cStrDelim);
210 OUString strTo = strFrom + strFrom;
211 aTmpStr = aTmpStr.replaceAll(strFrom, strTo);
216 else if ( bContextOrNotAsciiEncoding )
221 OUString aStrDec = OStringToOUString(aStrEnc, eCharSet);
223 OUString aStrTo = aStrDelimDecoded + aStrDelimDecoded;
224 aStrDec = aStrDec.replaceAll(aStrDelimDecoded, aStrTo);
234 OString aStrTo = aStrDelimEncoded + aStrDelimEncoded;
235 aStrEnc = aStrEnc.replaceAll(aStrDelimEncoded, aStrTo);
237 rOut.
WriteBytes(aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
238 rOut.
WriteBytes(aStrEnc.getStr(), aStrEnc.getLength());
239 rOut.
WriteBytes(aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
247 assert( aOS.isEmpty() &&
"aOS should be empty");
248 aOS.append(OUString::Concat(pSpecDataType_LF)
void PutInOrder(ScAddress &rAddress)
SC_DLLPUBLIC bool GetTableArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bCalcHiddens=false) const
SC_DLLPUBLIC OUString GetInputString(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bForceSystemLocale=false) const
SfxObjectShell * GetDocumentShell() const
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
void SetState(sal_uInt64 nVal, sal_uInt64 nNewRange=0)
void StartWritingUnicodeText()
std::size_t WriteBytes(const void *pData, std::size_t nSize)
bool WriteUnicodeOrByteText(std::u16string_view rStr, rtl_TextEncoding eDestCharSet)
bool WriteUniOrByteChar(sal_Unicode ch, rtl_TextEncoding eDestCharSet)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
rtl_TextEncoding GetStreamCharSet() const
const OUString & getString() const
const std::u16string_view pKeyTABLE
const std::u16string_view pKeyVECTORS
const std::u16string_view pKeyTUPLES
const std::u16string_view pKeyDATA
const std::u16string_view pKeyEOD
const std::u16string_view pKeyBOT
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
OUString ScResId(TranslateId aId)
TOOLS_DLLPUBLIC std::size_t write_uInt16s_FromOUString(SvStream &rStrm, std::u16string_view rStr, std::size_t nUnits)
This is very similar to ScCellValue, except that it references the original value instead of copying ...
ScFormulaCell * getFormula() const
OUString getString(const ScDocument *pDoc) const
Retrieve string value.