LibreOffice Module sc (master)  1
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
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 .
18  */
23 #include <types.hxx>
24 #include "ftools.hxx"
26 class SfxObjectShell;
27 enum class FormulaError : sal_uInt16;
29 // BIFF versions ==============================================================
31 #define DBG_ERROR_BIFF() OSL_FAIL( "Unknown BIFF type!" )
32 #define OSL_ENSURE_BIFF( c ) OSL_ENSURE( c, "Unknown BIFF type!" )
34 // Enumerations ===============================================================
38 {
49 };
51 // GUID import/export =========================================================
53 class XclImpStream;
54 class XclExpStream;
57 struct XclGuid
58 {
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 };
71 bool operator==( const XclGuid& rCmp1, const XclGuid& rCmp2 );
73 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
74 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
76 // Excel Tools ================================================================
79 class XclTools
80 {
81 public:
82  // noncopyable nonconstructable -------------------------------------------
84  XclTools(const XclTools&) = delete;
85  const XclTools& operator=(const XclTools&) = delete;
88  XclTools() = delete;
91  // GUID's -----------------------------------------------------------------
93  static const XclGuid maGuidStdLink;
94  static const XclGuid maGuidUrlMoniker;
95  static const XclGuid maGuidFileMoniker;
97  // numeric conversion -----------------------------------------------------
100  static double GetDoubleFromRK( sal_Int32 nRKValue );
105  static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
109  static sal_Int32 GetScRotation( sal_uInt16 nXclRot, sal_Int32 nRotForStacked );
111  static sal_uInt8 GetXclRotation( sal_Int32 nScRot );
114  static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
116  static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
119  static sal_uInt8 GetXclErrorCode( FormulaError nScError );
121  static FormulaError GetScErrorCode( sal_uInt8 nXclError );
124  static double ErrorToDouble( sal_uInt8 nXclError );
129  static XclBoolError ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uInt8 nValue );
132  static sal_uInt16 GetTwipsFromInch( double fInches );
134  static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
137  static double GetInchFromTwips( sal_Int32 nTwips );
139  static double GetInchFromHmm( sal_Int32 nHmm );
142  static sal_Int32 GetHmmFromInch( double fInches );
144  static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
149  static sal_uInt16 GetScColumnWidth( sal_uInt16 nXclWidth, long nScCharWidth );
152  static sal_uInt16 GetXclColumnWidth( sal_uInt16 nScWidth, long nScCharWidth );
156  static double GetXclDefColWidthCorrection( long nXclDefFontHeight );
158  // formatting -------------------------------------------------------------
161  static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
163  // text encoding ----------------------------------------------------------
167  static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
170  static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
172  // font names -------------------------------------------------------------
175  static OUString GetXclFontName( const OUString& rFontName );
177  // built-in defined names -------------------------------------------------
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 );
196  // built-in style names ---------------------------------------------------
203  static OUString GetBuiltInStyleName( sal_uInt8 nStyleId, const OUString& rName, sal_uInt8 nLevel );
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 );
218  // conditional formatting style names -------------------------------------
225  static OUString GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
228  static bool IsCondFormatStyleName( const OUString& rStyleName );
230  // stream handling --------------------------------------------------------
233  static void SkipSubStream( XclImpStream& rStrm );
235  // Basic macro names ------------------------------------------------------
238  static OUString GetSbMacroUrl( const OUString& rMacroName, SfxObjectShell* pDocShell );
240  static OUString GetXclMacroName( const OUString& rSbMacroUrl );
242 };
244 // read/write colors ----------------------------------------------------------
248 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
252 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
254 #endif
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:244
static sal_Int32 GetHmmFromInch(double fInches)
Returns the length in 1/100 mm calculated from a length in inches.
Definition: xltools.cxx:293
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
static double GetXclDefColWidthCorrection(long nXclDefFontHeight)
Returns a correction value to convert column widths from/to default column widths.
Definition: xltools.cxx:317
Stores GUID always in little endian.
Definition: xltools.cxx:40
static sal_uInt8 GetXclOrientFromRot(sal_uInt16 nXclRot)
Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle.
Definition: xltools.cxx:186
An enumeration for all Excel error codes and the values true and false.
Definition: xltools.hxx:37
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:625
static sal_uInt16 GetTwipsFromInch(double fInches)
Returns the length in twips calculated from a length in inches.
Definition: xltools.cxx:272
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:173
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:239
static bool GetRKFromDouble(sal_Int32 &rnRKValue, double fValue)
Calculates an RK value (encoded integer or double) from a double value.
Definition: xltools.cxx:121
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:498
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:451
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:75
static OUString GetXclMacroName(const OUString &rSbMacroUrl)
Returns the Excel macro name from a full StarBasic macro URL.
Definition: xltools.cxx:709
static FormulaError GetScErrorCode(sal_uInt8 nXclError)
Converts an Excel error code to a Calc error code.
Definition: xltools.cxx:223
static OUString GetBuiltInDefName(sal_Unicode cBuiltIn)
Returns the Calc UI representation of a built-in defined name used in NAME records.
Definition: xltools.cxx:491
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:298
static sal_uInt16 GetTwipsFromHmm(sal_Int32 nHmm)
Returns the length in twips calculated from a length in 1/100 mm.
Definition: xltools.cxx:278
XclImpStream & operator>>(XclImpStream &rStrm, XclGuid &rGuid)
Definition: xltools.cxx:69
static sal_Unicode GetBuiltInDefNameIndex(const OUString &rDefName)
Returns the Excel built-in name index of the passed defined name from Calc.
Definition: xltools.cxx:505
static double GetDoubleFromRK(sal_Int32 nRKValue)
GUID of file moniker (HLINK record).
Definition: xltools.cxx:95
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:198
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:670
static rtl_TextEncoding GetTextEncoding(sal_uInt16 nCodePage)
Returns a text encoding from an Excel code page.
Definition: xltools.cxx:426
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:346
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:577
static double GetInchFromTwips(sal_Int32 nTwips)
Returns the length in inches calculated from a length in twips.
Definition: xltools.cxx:283
static sal_uInt16 GetXclColumnWidth(sal_uInt16 nScWidth, long nScCharWidth)
Returns the Excel column width for the passed Calc width (twips).
Definition: xltools.cxx:309
static OUString GetBuiltInStyleName(sal_uInt8 nStyleId, const OUString &rName, sal_uInt8 nLevel)
Returns the specified built-in cell style name.
Definition: xltools.cxx:550
bool operator==(const XclGuid &rCmp1, const XclGuid &rCmp2)
Definition: xltools.cxx:64
static void SkipSubStream(XclImpStream &rStrm)
Skips a substream (BOF/EOF record block).
Definition: xltools.cxx:683
static sal_uInt16 GetXclCodePage(rtl_TextEncoding eTextEnc)
Returns an Excel code page from a text encoding.
Definition: xltools.cxx:437
static sal_uInt8 GetXclRotation(sal_Int32 nScRot)
Calculates the Excel angle value from an angle in 1/100 of degrees.
Definition: xltools.cxx:159
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:288
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:700
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:151
static sal_uInt16 GetScColumnWidth(sal_uInt16 nXclWidth, long nScCharWidth)
Returns the Calc column width (twips) for the passed Excel width.
Definition: xltools.cxx:303
The error code N/A!
Definition: xltools.hxx:46
unsigned char sal_uInt8
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:660
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:480
The error code #NAME?
Definition: xltools.hxx:44