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 #include <tools/long.hxx>
27 #include <tools/degree.hxx>
29 class SfxObjectShell;
30 enum class FormulaError : sal_uInt16;
32 // BIFF versions ==============================================================
34 #define DBG_ERROR_BIFF() OSL_FAIL( "Unknown BIFF type!" )
35 #define OSL_ENSURE_BIFF( c ) OSL_ENSURE( c, "Unknown BIFF type!" )
37 // Enumerations ===============================================================
41 {
52 };
54 // GUID import/export =========================================================
56 class XclImpStream;
57 class XclExpStream;
60 struct XclGuid
61 {
64  explicit XclGuid();
65  explicit XclGuid(
66  sal_uInt32 nData1,
67  sal_uInt16 nData2, sal_uInt16 nData3,
68  sal_uInt8 nData41, sal_uInt8 nData42,
69  sal_uInt8 nData43, sal_uInt8 nData44,
70  sal_uInt8 nData45, sal_uInt8 nData46,
71  sal_uInt8 nData47, sal_uInt8 nData48 );
72 };
74 bool operator==( const XclGuid& rCmp1, const XclGuid& rCmp2 );
76 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
77 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
79 // Excel Tools ================================================================
82 class XclTools
83 {
84 public:
85  // noncopyable nonconstructable -------------------------------------------
87  XclTools(const XclTools&) = delete;
88  const XclTools& operator=(const XclTools&) = delete;
91  XclTools() = delete;
94  // GUID's -----------------------------------------------------------------
96  static const XclGuid maGuidStdLink;
97  static const XclGuid maGuidUrlMoniker;
98  static const XclGuid maGuidFileMoniker;
100  // numeric conversion -----------------------------------------------------
103  static double GetDoubleFromRK( sal_Int32 nRKValue );
108  static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
112  static Degree100 GetScRotation( sal_uInt16 nXclRot, Degree100 nRotForStacked );
114  static sal_uInt8 GetXclRotation( Degree100 nScRot );
117  static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
119  static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
122  static sal_uInt8 GetXclErrorCode( FormulaError nScError );
124  static FormulaError GetScErrorCode( sal_uInt8 nXclError );
127  static double ErrorToDouble( sal_uInt8 nXclError );
132  static XclBoolError ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uInt8 nValue );
135  static sal_uInt16 GetTwipsFromInch( double fInches );
137  static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
140  static double GetInchFromTwips( sal_Int32 nTwips );
142  static double GetInchFromHmm( sal_Int32 nHmm );
145  static sal_Int32 GetHmmFromInch( double fInches );
147  static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
152  static sal_uInt16 GetScColumnWidth( sal_uInt16 nXclWidth, tools::Long nScCharWidth );
155  static sal_uInt16 GetXclColumnWidth( sal_uInt16 nScWidth, tools::Long nScCharWidth );
159  static double GetXclDefColWidthCorrection( tools::Long nXclDefFontHeight );
161  // formatting -------------------------------------------------------------
164  static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
166  // text encoding ----------------------------------------------------------
170  static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
173  static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
175  // font names -------------------------------------------------------------
178  static OUString GetXclFontName( const OUString& rFontName );
180  // built-in defined names -------------------------------------------------
184  static OUString GetXclBuiltInDefName( sal_Unicode cBuiltIn );
188  static OUString GetBuiltInDefName( sal_Unicode cBuiltIn );
192  static OUString GetBuiltInDefNameXml( sal_Unicode cBuiltIn );
197  static sal_Unicode GetBuiltInDefNameIndex( const OUString& rDefName );
199  // built-in style names ---------------------------------------------------
206  static OUString GetBuiltInStyleName( sal_uInt8 nStyleId, const OUString& rName, sal_uInt8 nLevel );
211  static bool IsBuiltInStyleName( const OUString& rStyleName, sal_uInt8* pnStyleId = nullptr, sal_Int32* pnNextChar = nullptr );
217  static bool GetBuiltInStyleId(
218  sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
219  const OUString& rStyleName );
221  // conditional formatting style names -------------------------------------
228  static OUString GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
231  static bool IsCondFormatStyleName( const OUString& rStyleName );
233  // stream handling --------------------------------------------------------
236  static void SkipSubStream( XclImpStream& rStrm );
238  // Basic macro names ------------------------------------------------------
241  static OUString GetSbMacroUrl( const OUString& rMacroName, SfxObjectShell* pDocShell );
243  static OUString GetXclMacroName( const OUString& rSbMacroUrl );
245 };
247 // read/write colors ----------------------------------------------------------
251 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
255 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
257 #endif
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const XclGuid maGuidUrlMoniker
GUID of StdLink (HLINK record).
Definition: xltools.hxx:97
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:73
static const XclGuid maGuidFileMoniker
GUID of URL moniker (HLINK record).
Definition: xltools.hxx:98
Stores GUID always in little endian.
Definition: xltools.cxx:42
static sal_uInt8 GetXclRotation(Degree100 nScRot)
Calculates the Excel angle value from an angle in 1/100 of degrees.
Definition: xltools.cxx:161
static sal_uInt8 GetXclOrientFromRot(sal_uInt16 nXclRot)
Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle.
Definition: xltools.cxx:188
An enumeration for all Excel error codes and the values true and false.
Definition: xltools.hxx:40
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
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:51
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:46
The Boolean value true.
Definition: xltools.hxx:50
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:43
static OUString GetXclFontName(const OUString &rFontName)
Returns the matching Excel font name for a passed Calc font name.
Definition: xltools.cxx:453
static Degree100 GetScRotation(sal_uInt16 nXclRot, Degree100 nRotForStacked)
Calculates an angle (in 1/100 of degrees) from an Excel angle value.
Definition: xltools.cxx:153
This class contains static helper methods for the Excel import and export filters.
Definition: xltools.hxx:82
static const XclGuid maGuidStdLink
Definition: xltools.hxx:96
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:48
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:62
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
The error code #VALUE!
Definition: xltools.hxx:45
The error code #DIV/0!
Definition: xltools.hxx:44
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:60
static OUString GetSbMacroUrl(const OUString &rMacroName, SfxObjectShell *pDocShell)
Returns the full StarBasic macro URL from an Excel macro name.
Definition: xltools.cxx:703
The error code N/A!
Definition: xltools.hxx:49
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:47