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 #pragma once
21 
22 #include <types.hxx>
23 #include "ftools.hxx"
24 
25 #include <tools/long.hxx>
26 #include <tools/degree.hxx>
27 
28 class SfxObjectShell;
29 enum class FormulaError : sal_uInt16;
30 
31 // BIFF versions ==============================================================
32 
33 #define DBG_ERROR_BIFF() OSL_FAIL( "Unknown BIFF type!" )
34 #define OSL_ENSURE_BIFF( c ) OSL_ENSURE( c, "Unknown BIFF type!" )
35 
36 // Enumerations ===============================================================
37 
40 {
51 };
52 
53 // GUID import/export =========================================================
54 
55 class XclImpStream;
56 class XclExpStream;
57 
59 struct XclGuid
60 {
62 
63  explicit XclGuid();
64  explicit XclGuid(
65  sal_uInt32 nData1,
66  sal_uInt16 nData2, sal_uInt16 nData3,
67  sal_uInt8 nData41, sal_uInt8 nData42,
68  sal_uInt8 nData43, sal_uInt8 nData44,
69  sal_uInt8 nData45, sal_uInt8 nData46,
70  sal_uInt8 nData47, sal_uInt8 nData48 );
71 };
72 
73 bool operator==( const XclGuid& rCmp1, const XclGuid& rCmp2 );
74 
75 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
76 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
77 
78 // Excel Tools ================================================================
79 
81 class XclTools
82 {
83 public:
84  // noncopyable nonconstructable -------------------------------------------
85 
86  XclTools(const XclTools&) = delete;
87  const XclTools& operator=(const XclTools&) = delete;
90  XclTools() = delete;
91 
92 
93  // GUID's -----------------------------------------------------------------
94 
95  static const XclGuid maGuidStdLink;
96  static const XclGuid maGuidUrlMoniker;
97  static const XclGuid maGuidFileMoniker;
98 
99  // numeric conversion -----------------------------------------------------
100 
102  static double GetDoubleFromRK( sal_Int32 nRKValue );
107  static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
108 
111  static Degree100 GetScRotation( sal_uInt16 nXclRot, Degree100 nRotForStacked );
113  static sal_uInt8 GetXclRotation( Degree100 nScRot );
114 
116  static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
118  static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
119 
121  static sal_uInt8 GetXclErrorCode( FormulaError nScError );
123  static FormulaError GetScErrorCode( sal_uInt8 nXclError );
124 
126  static double ErrorToDouble( sal_uInt8 nXclError );
131  static XclBoolError ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uInt8 nValue );
132 
134  static sal_uInt16 GetTwipsFromInch( double fInches );
136  static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
137 
139  static double GetInchFromTwips( sal_Int32 nTwips );
141  static double GetInchFromHmm( sal_Int32 nHmm );
142 
144  static sal_Int32 GetHmmFromInch( double fInches );
146  static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
147 
151  static sal_uInt16 GetScColumnWidth( sal_uInt16 nXclWidth, tools::Long nScCharWidth );
154  static sal_uInt16 GetXclColumnWidth( sal_uInt16 nScWidth, tools::Long nScCharWidth );
155 
158  static double GetXclDefColWidthCorrection( tools::Long nXclDefFontHeight );
159 
160  // formatting -------------------------------------------------------------
161 
163  static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
164 
165  // text encoding ----------------------------------------------------------
166 
169  static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
170 
172  static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
173 
174  // font names -------------------------------------------------------------
175 
177  static OUString GetXclFontName( const OUString& rFontName );
178 
179  // built-in defined names -------------------------------------------------
180 
183  static OUString GetXclBuiltInDefName( sal_Unicode cBuiltIn );
187  static OUString GetBuiltInDefName( sal_Unicode cBuiltIn );
191  static OUString GetBuiltInDefNameXml( sal_Unicode cBuiltIn );
196  static sal_Unicode GetBuiltInDefNameIndex( const OUString& rDefName );
197 
198  // built-in style names ---------------------------------------------------
199 
205  static OUString GetBuiltInStyleName( sal_uInt8 nStyleId, std::u16string_view rName, sal_uInt8 nLevel );
206 
210  static bool IsBuiltInStyleName( const OUString& rStyleName, sal_uInt8* pnStyleId = nullptr, sal_Int32* pnNextChar = nullptr );
216  static bool GetBuiltInStyleId(
217  sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
218  const OUString& rStyleName );
219 
220  // conditional formatting style names -------------------------------------
221 
227  static OUString GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
230  static bool IsCondFormatStyleName( const OUString& rStyleName );
231 
232  // stream handling --------------------------------------------------------
233 
235  static void SkipSubStream( XclImpStream& rStrm );
236 
237  // Basic macro names ------------------------------------------------------
238 
240  static OUString GetSbMacroUrl( const OUString& rMacroName, SfxObjectShell* pDocShell );
242  static OUString GetXclMacroName( const OUString& rSbMacroUrl );
243 
244 };
245 
246 // read/write colors ----------------------------------------------------------
247 
250 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
251 
254 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const XclGuid maGuidUrlMoniker
GUID of StdLink (HLINK record).
Definition: xltools.hxx:96
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:247
static sal_Int32 GetHmmFromInch(double fInches)
Returns the length in 1/100 mm calculated from a length in inches.
Definition: xltools.cxx:297
static double GetXclDefColWidthCorrection(tools::Long nXclDefFontHeight)
Returns a correction value to convert column widths from/to default column widths.
Definition: xltools.cxx:321
This class is used to export Excel record streams.
Definition: xestream.hxx:72
static const XclGuid maGuidFileMoniker
GUID of URL moniker (HLINK record).
Definition: xltools.hxx:97
XclGuid()
Stores GUID always in little endian.
Definition: xltools.cxx:43
static sal_uInt8 GetXclRotation(Degree100 nScRot)
Calculates the Excel angle value from an angle in 1/100 of degrees.
Definition: xltools.cxx:162
static sal_uInt8 GetXclOrientFromRot(sal_uInt16 nXclRot)
Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle.
Definition: xltools.cxx:189
XclBoolError
An enumeration for all Excel error codes and the values true and false.
Definition: xltools.hxx:39
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:629
static sal_uInt16 GetTwipsFromInch(double fInches)
Returns the length in twips calculated from a length in inches.
Definition: xltools.cxx:277
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:176
The Boolean value false.
Definition: xltools.hxx:50
static double ErrorToDouble(sal_uInt8 nXclError)
Converts the passed BIFF error to a double containing the respective Calc error code.
Definition: xltools.cxx:242
static bool GetRKFromDouble(sal_Int32 &rnRKValue, double fValue)
Calculates an RK value (encoded integer or double) from a double value.
Definition: xltools.cxx:124
The error code #REF!
Definition: xltools.hxx:45
The Boolean value true.
Definition: xltools.hxx:49
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:502
sal_uInt16 sal_Unicode
The error code NULL!
Definition: xltools.hxx:42
static OUString GetXclFontName(const OUString &rFontName)
Returns the matching Excel font name for a passed Calc font name.
Definition: xltools.cxx:455
static Degree100 GetScRotation(sal_uInt16 nXclRot, Degree100 nRotForStacked)
Calculates an angle (in 1/100 of degrees) from an Excel angle value.
Definition: xltools.cxx:154
This class contains static helper methods for the Excel import and export filters.
Definition: xltools.hxx:81
static const XclGuid maGuidStdLink
Definition: xltools.hxx:95
XclExpStream & operator<<(XclExpStream &rStrm, const XclGuid &rGuid)
Definition: xltools.cxx:78
static OUString GetXclMacroName(const OUString &rSbMacroUrl)
Returns the Excel macro name from a full StarBasic macro URL.
Definition: xltools.cxx:718
static FormulaError GetScErrorCode(sal_uInt8 nXclError)
Converts an Excel error code to a Calc error code.
Definition: xltools.cxx:226
static OUString GetBuiltInDefName(sal_Unicode cBuiltIn)
Returns the Calc UI representation of a built-in defined name used in NAME records.
Definition: xltools.cxx:495
The error code #NUM!
Definition: xltools.hxx:47
static sal_Int32 GetHmmFromTwips(sal_Int32 nTwips)
Returns the length in 1/100 mm calculated from a length in twips.
Definition: xltools.cxx:302
static sal_uInt16 GetScColumnWidth(sal_uInt16 nXclWidth, tools::Long nScCharWidth)
Returns the Calc column width (twips) for the passed Excel width.
Definition: xltools.cxx:307
static sal_uInt16 GetTwipsFromHmm(sal_Int32 nHmm)
Returns the length in twips calculated from a length in 1/100 mm.
Definition: xltools.cxx:282
XclImpStream & operator>>(XclImpStream &rStrm, XclGuid &rGuid)
Definition: xltools.cxx:72
static sal_Unicode GetBuiltInDefNameIndex(const OUString &rDefName)
Returns the Excel built-in name index of the passed defined name from Calc.
Definition: xltools.cxx:509
static double GetDoubleFromRK(sal_Int32 nRKValue)
GUID of file moniker (HLINK record).
Definition: xltools.cxx:98
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:201
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:676
static rtl_TextEncoding GetTextEncoding(sal_uInt16 nCodePage)
Returns a text encoding from an Excel code page.
Definition: xltools.cxx:430
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:350
sal_uInt8 mpnData[16]
Definition: xltools.hxx:61
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:581
static OUString GetBuiltInStyleName(sal_uInt8 nStyleId, std::u16string_view rName, sal_uInt8 nLevel)
Returns the specified built-in cell style name.
Definition: xltools.cxx:554
static double GetInchFromTwips(sal_Int32 nTwips)
Returns the length in inches calculated from a length in twips.
Definition: xltools.cxx:287
bool operator==(const XclGuid &rCmp1, const XclGuid &rCmp2)
Definition: xltools.cxx:67
static void SkipSubStream(XclImpStream &rStrm)
Skips a substream (BOF/EOF record block).
Definition: xltools.cxx:692
static sal_uInt16 GetXclCodePage(rtl_TextEncoding eTextEnc)
Returns an Excel code page from a text encoding.
Definition: xltools.cxx:441
FormulaError
The error code #VALUE!
Definition: xltools.hxx:44
The error code #DIV/0!
Definition: xltools.hxx:43
static double GetInchFromHmm(sal_Int32 nHmm)
Returns the length in inches calculated from a length in 1/100 mm.
Definition: xltools.cxx:292
This struct stores a GUID (class ID) and supports reading, writing and comparison.
Definition: xltools.hxx:59
static OUString GetSbMacroUrl(const OUString &rMacroName, SfxObjectShell *pDocShell)
Returns the full StarBasic macro URL from an Excel macro name.
Definition: xltools.cxx:709
The error code N/A!
Definition: xltools.hxx:48
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:313
This class is used to import record oriented streams.
Definition: xistream.hxx:277
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:666
sal_Int16 SCTAB
Definition: types.hxx:22
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:484
The error code #NAME?
Definition: xltools.hxx:46