LibreOffice Module sc (master)  1
xltools.hxx
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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XLTOOLS_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XLTOOLS_HXX
22 
23 #include <types.hxx>
24 #include "ftools.hxx"
25 
26 class SfxObjectShell;
27 enum class FormulaError : sal_uInt16;
28 
29 // BIFF versions ==============================================================
30 
31 #define DBG_ERROR_BIFF() OSL_FAIL( "Unknown BIFF type!" )
32 #define OSL_ENSURE_BIFF( c ) OSL_ENSURE( c, "Unknown BIFF type!" )
33 
34 // Enumerations ===============================================================
35 
38 {
49 };
50 
51 // GUID import/export =========================================================
52 
53 class XclImpStream;
54 class XclExpStream;
55 
57 struct XclGuid
58 {
60 
61  explicit XclGuid();
62  explicit XclGuid(
63  sal_uInt32 nData1,
64  sal_uInt16 nData2, sal_uInt16 nData3,
65  sal_uInt8 nData41, sal_uInt8 nData42,
66  sal_uInt8 nData43, sal_uInt8 nData44,
67  sal_uInt8 nData45, sal_uInt8 nData46,
68  sal_uInt8 nData47, sal_uInt8 nData48 );
69 };
70 
71 bool operator==( const XclGuid& rCmp1, const XclGuid& rCmp2 );
72 
73 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
74 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
75 
76 // Excel Tools ================================================================
77 
79 class XclTools
80 {
81 public:
82  // noncopyable nonconstructable -------------------------------------------
83 
84  XclTools(const XclTools&) = delete;
85  const XclTools& operator=(const XclTools&) = delete;
88  XclTools() = delete;
89 
90 
91  // GUID's -----------------------------------------------------------------
92 
93  static const XclGuid maGuidStdLink;
94  static const XclGuid maGuidUrlMoniker;
95  static const XclGuid maGuidFileMoniker;
96 
97  // numeric conversion -----------------------------------------------------
98 
100  static double GetDoubleFromRK( sal_Int32 nRKValue );
105  static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
106 
109  static sal_Int32 GetScRotation( sal_uInt16 nXclRot, sal_Int32 nRotForStacked );
111  static sal_uInt8 GetXclRotation( sal_Int32 nScRot );
112 
114  static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
116  static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
117 
119  static sal_uInt8 GetXclErrorCode( FormulaError nScError );
121  static FormulaError GetScErrorCode( sal_uInt8 nXclError );
122 
124  static double ErrorToDouble( sal_uInt8 nXclError );
129  static XclBoolError ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uInt8 nValue );
130 
132  static sal_uInt16 GetTwipsFromInch( double fInches );
134  static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
135 
137  static double GetInchFromTwips( sal_Int32 nTwips );
139  static double GetInchFromHmm( sal_Int32 nHmm );
140 
142  static sal_Int32 GetHmmFromInch( double fInches );
144  static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
145 
149  static sal_uInt16 GetScColumnWidth( sal_uInt16 nXclWidth, tools::Long nScCharWidth );
152  static sal_uInt16 GetXclColumnWidth( sal_uInt16 nScWidth, tools::Long nScCharWidth );
153 
156  static double GetXclDefColWidthCorrection( tools::Long nXclDefFontHeight );
157 
158  // formatting -------------------------------------------------------------
159 
161  static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
162 
163  // text encoding ----------------------------------------------------------
164 
167  static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
168 
170  static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
171 
172  // font names -------------------------------------------------------------
173 
175  static OUString GetXclFontName( const OUString& rFontName );
176 
177  // built-in defined names -------------------------------------------------
178 
181  static OUString GetXclBuiltInDefName( sal_Unicode cBuiltIn );
185  static OUString GetBuiltInDefName( sal_Unicode cBuiltIn );
189  static OUString GetBuiltInDefNameXml( sal_Unicode cBuiltIn );
194  static sal_Unicode GetBuiltInDefNameIndex( const OUString& rDefName );
195 
196  // built-in style names ---------------------------------------------------
197 
203  static OUString GetBuiltInStyleName( sal_uInt8 nStyleId, const OUString& rName, sal_uInt8 nLevel );
204 
208  static bool IsBuiltInStyleName( const OUString& rStyleName, sal_uInt8* pnStyleId = nullptr, sal_Int32* pnNextChar = nullptr );
214  static bool GetBuiltInStyleId(
215  sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
216  const OUString& rStyleName );
217 
218  // conditional formatting style names -------------------------------------
219 
225  static OUString GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
228  static bool IsCondFormatStyleName( const OUString& rStyleName );
229 
230  // stream handling --------------------------------------------------------
231 
233  static void SkipSubStream( XclImpStream& rStrm );
234 
235  // Basic macro names ------------------------------------------------------
236 
238  static OUString GetSbMacroUrl( const OUString& rMacroName, SfxObjectShell* pDocShell );
240  static OUString GetXclMacroName( const OUString& rSbMacroUrl );
241 
242 };
243 
244 // read/write colors ----------------------------------------------------------
245 
248 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
249 
252 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
253 
254 #endif
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const XclGuid maGuidUrlMoniker
GUID of StdLink (HLINK record).
Definition: xltools.hxx:94
static XclBoolError ErrorToEnum(double &rfDblValue, bool bErrOrBool, sal_uInt8 nValue)
Gets a translated error code or Boolean value from Excel error codes.
Definition: xltools.cxx:246
static sal_Int32 GetHmmFromInch(double fInches)
Returns the length in 1/100 mm calculated from a length in inches.
Definition: xltools.cxx:295
static double GetXclDefColWidthCorrection(tools::Long nXclDefFontHeight)
Returns a correction value to convert column widths from/to default column widths.
Definition: xltools.cxx:319
This class is used to export Excel record streams.
Definition: xestream.hxx:71
static const XclGuid maGuidFileMoniker
GUID of URL moniker (HLINK record).
Definition: xltools.hxx:95
XclGuid()
Stores GUID always in little endian.
Definition: xltools.cxx:42
static sal_uInt8 GetXclOrientFromRot(sal_uInt16 nXclRot)
Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle.
Definition: xltools.cxx:188
XclBoolError
An enumeration for all Excel error codes and the values true and false.
Definition: xltools.hxx:37
long Long
static bool GetBuiltInStyleId(sal_uInt8 &rnStyleId, sal_uInt8 &rnLevel, const OUString &rStyleName)
Returns the Excel built-in style identifier of a passed style name.
Definition: xltools.cxx:627
static sal_uInt16 GetTwipsFromInch(double fInches)
Returns the length in twips calculated from a length in inches.
Definition: xltools.cxx:274
XclTools()=delete
We don't want anybody to instantiate this class, since it is just a collection of static items...
static sal_uInt8 GetXclRotFromOrient(sal_uInt8 nXclOrient)
Calculates BIFF8 rotation angle from BIFF2-BIFF5 text orientation.
Definition: xltools.cxx:175
The Boolean value false.
Definition: xltools.hxx:48
static double ErrorToDouble(sal_uInt8 nXclError)
Converts the passed BIFF error to a double containing the respective Calc error code.
Definition: xltools.cxx:241
static bool GetRKFromDouble(sal_Int32 &rnRKValue, double fValue)
Calculates an RK value (encoded integer or double) from a double value.
Definition: xltools.cxx:123
The error code #REF!
Definition: xltools.hxx:43
The Boolean value true.
Definition: xltools.hxx:47
static OUString GetBuiltInDefNameXml(sal_Unicode cBuiltIn)
Returns the Excel built-in name with OOXML prefix Adds the "_xlnm." prefix to the representation ret...
Definition: xltools.cxx:500
sal_uInt16 sal_Unicode
The error code NULL!
Definition: xltools.hxx:40
static OUString GetXclFontName(const OUString &rFontName)
Returns the matching Excel font name for a passed Calc font name.
Definition: xltools.cxx:453
This class contains static helper methods for the Excel import and export filters.
Definition: xltools.hxx:79
static const XclGuid maGuidStdLink
Definition: xltools.hxx:93
XclExpStream & operator<<(XclExpStream &rStrm, const XclGuid &rGuid)
Definition: xltools.cxx:77
static OUString GetXclMacroName(const OUString &rSbMacroUrl)
Returns the Excel macro name from a full StarBasic macro URL.
Definition: xltools.cxx:712
static FormulaError GetScErrorCode(sal_uInt8 nXclError)
Converts an Excel error code to a Calc error code.
Definition: xltools.cxx:225
static OUString GetBuiltInDefName(sal_Unicode cBuiltIn)
Returns the Calc UI representation of a built-in defined name used in NAME records.
Definition: xltools.cxx:493
The error code #NUM!
Definition: xltools.hxx:45
static sal_Int32 GetHmmFromTwips(sal_Int32 nTwips)
Returns the length in 1/100 mm calculated from a length in twips.
Definition: xltools.cxx:300
static sal_uInt16 GetScColumnWidth(sal_uInt16 nXclWidth, tools::Long nScCharWidth)
Returns the Calc column width (twips) for the passed Excel width.
Definition: xltools.cxx:305
static sal_uInt16 GetTwipsFromHmm(sal_Int32 nHmm)
Returns the length in twips calculated from a length in 1/100 mm.
Definition: xltools.cxx:280
XclImpStream & operator>>(XclImpStream &rStrm, XclGuid &rGuid)
Definition: xltools.cxx:71
static sal_Unicode GetBuiltInDefNameIndex(const OUString &rDefName)
Returns the Excel built-in name index of the passed defined name from Calc.
Definition: xltools.cxx:507
static double GetDoubleFromRK(sal_Int32 nRKValue)
GUID of file moniker (HLINK record).
Definition: xltools.cxx:97
const XclTools & operator=(const XclTools &)=delete
static sal_uInt8 GetXclErrorCode(FormulaError nScError)
Converts a Calc error code to an Excel error code.
Definition: xltools.cxx:200
static bool IsCondFormatStyleName(const OUString &rStyleName)
Returns true, if the passed string is a name of a conditional format style created by Excel import...
Definition: xltools.cxx:673
static rtl_TextEncoding GetTextEncoding(sal_uInt16 nCodePage)
Returns a text encoding from an Excel code page.
Definition: xltools.cxx:428
static Color GetPatternColor(const Color &rPattColor, const Color &rBackColor, sal_uInt16 nXclPattern)
Returns the best fitting color for an Excel pattern area format.
Definition: xltools.cxx:348
sal_uInt8 mpnData[16]
Definition: xltools.hxx:59
static bool IsBuiltInStyleName(const OUString &rStyleName, sal_uInt8 *pnStyleId=nullptr, sal_Int32 *pnNextChar=nullptr)
Returns true, if the passed string is a name of an Excel built-in style.
Definition: xltools.cxx:579
static double GetInchFromTwips(sal_Int32 nTwips)
Returns the length in inches calculated from a length in twips.
Definition: xltools.cxx:285
static OUString GetBuiltInStyleName(sal_uInt8 nStyleId, const OUString &rName, sal_uInt8 nLevel)
Returns the specified built-in cell style name.
Definition: xltools.cxx:552
bool operator==(const XclGuid &rCmp1, const XclGuid &rCmp2)
Definition: xltools.cxx:66
static void SkipSubStream(XclImpStream &rStrm)
Skips a substream (BOF/EOF record block).
Definition: xltools.cxx:686
static sal_uInt16 GetXclCodePage(rtl_TextEncoding eTextEnc)
Returns an Excel code page from a text encoding.
Definition: xltools.cxx:439
static sal_uInt8 GetXclRotation(sal_Int32 nScRot)
Calculates the Excel angle value from an angle in 1/100 of degrees.
Definition: xltools.cxx:161
FormulaError
The error code #VALUE!
Definition: xltools.hxx:42
The error code #DIV/0!
Definition: xltools.hxx:41
static double GetInchFromHmm(sal_Int32 nHmm)
Returns the length in inches calculated from a length in 1/100 mm.
Definition: xltools.cxx:290
This struct stores a GUID (class ID) and supports reading, writing and comparison.
Definition: xltools.hxx:57
static OUString GetSbMacroUrl(const OUString &rMacroName, SfxObjectShell *pDocShell)
Returns the full StarBasic macro URL from an Excel macro name.
Definition: xltools.cxx:703
static sal_Int32 GetScRotation(sal_uInt16 nXclRot, sal_Int32 nRotForStacked)
Calculates an angle (in 1/100 of degrees) from an Excel angle value.
Definition: xltools.cxx:153
The error code N/A!
Definition: xltools.hxx:46
unsigned char sal_uInt8
static sal_uInt16 GetXclColumnWidth(sal_uInt16 nScWidth, tools::Long nScCharWidth)
Returns the Excel column width for the passed Calc width (twips).
Definition: xltools.cxx:311
This class is used to import record oriented streams.
Definition: xistream.hxx:278
static OUString GetCondFormatStyleName(SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition)
Returns the style name for a single condition of a conditional formatting.
Definition: xltools.cxx:663
sal_Int16 SCTAB
Definition: types.hxx:23
static OUString GetXclBuiltInDefName(sal_Unicode cBuiltIn)
Returns the raw English UI representation of a built-in defined name used in NAME records...
Definition: xltools.cxx:482
The error code #NAME?
Definition: xltools.hxx:44