⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extformat.cpp

📁 xls文件格式分析基础库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) Yeico S. A. de C. V. * xlsLib -- A multiplatform, C++ library for dynamic generation of Excel (TM)  * files. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *   * $Source: /cvsroot/xlslib/xlslib/src/xlslib/extformat.cpp,v $ * $Revision: 1.1.1.1 $ * $Author: darioglz $ * $Date: 2004/08/27 16:31:48 $ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * File description: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */#include "extformat.h"#include "crc.h"// TODO: Implement the handling of BIFF8 ./* **********************************CExtFormat class implementation***********************************/using namespace std;using namespace xlslib_core;CExtFormat::CExtFormat(bool is_cell){   SetRecordType(RECTYPE_XF);   InitDummy(is_cell);   SetRecordLength(GetDataSize()-4);}CExtFormat::CExtFormat(xf_t* xfdef){   SetRecordType(RECTYPE_XF);   InitDummy(xfdef->IsCell());   SetRecordLength(GetDataSize()-4);// Here initialize the record with the values from the input structure         SetFontIndex(xfdef->GetFontIndex());   SetFormatIndex(xfdef->GetFormatIndex());   SetHorizAlign(xfdef->GetHAlign());   SetVertAlign(xfdef->GetVAlign());   SetTxtOrientation(xfdef->GetTxtOrientation());   SetFGColorIndex(xfdef->GetFillFGColor());   SetBGColorIndex(xfdef->GetFillBGColor());   SetFillPattern(xfdef->GetFillStyle());   if(xfdef->IsLocked()) SetLocked();   if(xfdef->IsHidden()) SetHidden();    if(xfdef->IsWrap()) SetWrap();    SetBorder(BORDER_BOTTOM, xfdef->GetBorderStyle(BORDER_BOTTOM),              xfdef->GetBorderColor(BORDER_BOTTOM));   SetBorder(BORDER_TOP, xfdef->GetBorderStyle(BORDER_TOP),              xfdef->GetBorderColor(BORDER_TOP));   SetBorder(BORDER_LEFT, xfdef->GetBorderStyle(BORDER_LEFT),              xfdef->GetBorderColor(BORDER_LEFT));   SetBorder(BORDER_RIGHT, xfdef->GetBorderStyle(BORDER_RIGHT),              xfdef->GetBorderColor(BORDER_RIGHT));}CExtFormat::~CExtFormat(){}/* *********************************************************************/void CExtFormat::InitDummy(bool is_cell){   // An style-XF record is set by default.   // Each field has to be modified individually before use it   //The default style is a dummy. The flags that indicate what the style affects (byte 11)   // are disabled (set to 1).   unsigned8_t xfdefault[] = {/*  4         6         8         10        12        14        16        18*/      0x00,0x00,0x00,0x00,0xf4,0xff,0x20,0xf0,0xc0,0x00,0x01,0x00,0x00,0x00,0x00,0x00   };   AddDataArray(xfdefault, sizeof(xfdefault));       if(is_cell)   {      unsigned16_t value;      // Get the field where options are set      GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);      // Set the cell's style parent to Normal      value &= (~XF_PROP_XFPARENT);       // Set the style = cell.      value &= (~XF_PROP_STYLE);       SetValueAt((signed16_t)value, XF_OFFSET_PROP);      // The cell doesn't heritage anything from its parent style       GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);      value &= (~(XF_ALIGN_ATRFONT|XF_ALIGN_ATRALC|XF_ALIGN_ATRBDR|                  XF_ALIGN_ATRPAT|XF_ALIGN_ATRPROT));       SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);          }}/* *********************************************************************/bool CExtFormat::IsCell(){   unsigned16_t val;   GetValue16From((signed16_t*)&val, XF_OFFSET_PROP);      return(val&XF_PROP_STYLE?true:false);}/* *********************************************************************/void CExtFormat::SetFlag(unsigned16_t flag){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);   if(IsCell())   {      // Cells indicate that a characteristic is not equal      //  from its parent with the flag set.      value |= flag;    }   else   {      // Styles indicate that a characteristic is       // being implemented with the flag cleared.      value &= (~flag);   }   SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);}/* *********************************************************************/void CExtFormat::ClearFlag(unsigned16_t flag){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);   if(!IsCell())   {      // Cells indicate that a characteristic is not equal      //  from its parent with the flag set.      value |= flag;    }   else   {      // Styles indicate that a characteristic is       // being implemented with the flag cleared.      value &= (~flag);   }   SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);}/* *********************************************************************/int CExtFormat::SetFontIndex(unsigned16_t fontindex){   // Set the index value   int errcode = SetValueAt((signed16_t)fontindex, XF_OFFSET_FONT);      // Set the related flag.   SetFlag(XF_ALIGN_ATRFONT);      return errcode;}/* *********************************************************************/unsigned16_t CExtFormat::GetFontIndex(void){   unsigned16_t fontval;   GetValue16From((signed16_t*)&fontval, XF_OFFSET_FONT);   return(fontval);}/* *********************************************************************/int CExtFormat::SetFormatIndex(unsigned16_t formatindex){   // Set the index value   int errcode = SetValueAt((signed16_t)formatindex, XF_OFFSET_FORMAT);      // Set the related flag.   SetFlag(XF_ALIGN_ATRNUM);      return errcode;}/* *********************************************************************/unsigned16_t CExtFormat::GetFormatIndex(void){   unsigned16_t formatval;   GetValue16From((signed16_t*)&formatval, XF_OFFSET_FORMAT);   return(formatval);}/* *********************************************************************/void CExtFormat::SetLocked(){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);   value |= XF_PROP_LOCKED;   SetValueAt((signed16_t)value, XF_OFFSET_PROP);   SetFlag(XF_ALIGN_ATRPROT);}/* *********************************************************************/void CExtFormat::SetHidden(){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);   value |= XF_PROP_HIDDEN;   SetValueAt((signed16_t)value, XF_OFFSET_PROP);   SetFlag(XF_ALIGN_ATRPROT);}/* *********************************************************************/void CExtFormat::SetHorizAlign(unsigned8_t alignval){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);   value = (value&(~XF_ALIGN_HORIZONTAL))|(alignval & XF_ALIGN_HORIZONTAL);   SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);   SetFlag(XF_ALIGN_ATRALC);}/* *********************************************************************/void CExtFormat::SetWrap(){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);   value |= XF_ALIGN_WRAP;   SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);   SetFlag(XF_ALIGN_ATRALC);}/* *********************************************************************/void CExtFormat::SetVertAlign(unsigned8_t alignval){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);   unsigned16_t alignval16 = alignval << XF_ALIGN_SHIFTPOS_VALIGN; // Place the option at the right bit position   value = (value&(~XF_ALIGN_VERTICAL))|(alignval16 & XF_ALIGN_VERTICAL);   SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);   SetFlag(XF_ALIGN_ATRALC);}/* *********************************************************************/void CExtFormat::SetTxtOrientation(unsigned8_t alignval){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);   unsigned16_t alignval16 = alignval << XF_ALIGN_SHIFTPOS_ORI; // Place the option at the right bit position   value = (value&(~XF_ALIGN_ORIENTATION))|(alignval16 & XF_ALIGN_ORIENTATION);   SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);}/* *********************************************************************/void CExtFormat::SetFGColorIndex(unsigned8_t color){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_COLOR);      // value = (value&(~XF_COLOR_FOREGROUND))|(color & XF_COLOR_FOREGROUND);   // Clear the field for Foreground color   value &= (~XF_COLOR_FOREGROUND);   // Set the new color   value |= (color & XF_COLOR_FOREGROUND);   SetValueAt((signed16_t)value, XF_OFFSET_COLOR);   SetFlag(XF_ALIGN_ATRPAT);}/* *********************************************************************/void CExtFormat::SetBGColorIndex(unsigned8_t color){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_COLOR);   unsigned16_t color16 = color <<  XF_COLOR_SHIFTPOS_BG;//   value = (value&(~XF_COLOR_FOREGROUND))|(color16 & XF_COLOR_FOREGROUND);   // Clear the field for Foreground color   value &= (~XF_COLOR_BACKGROUND);   // Set the new color   value |= (color16 & XF_COLOR_BACKGROUND);   SetValueAt((signed16_t)value, XF_OFFSET_COLOR);   SetFlag(XF_ALIGN_ATRPAT);}/* *********************************************************************/void CExtFormat::SetFillPattern(unsigned8_t color){   unsigned16_t value;   GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER0);   value = (value&(~XF_BORDER0_FILLPATTERN))|(color & XF_BORDER0_FILLPATTERN);   SetValueAt((signed16_t)value, XF_OFFSET_BORDER0);   SetFlag(XF_ALIGN_ATRPAT);}/* *********************************************************************/void CExtFormat::SetBorder(border_side_t border, unsigned16_t style, unsigned16_t color){   unsigned16_t value;      switch(border)   {      case BORDER_BOTTOM:      {         unsigned16_t color16 = color;         GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER0);         value = (value&(~XF_BORDER0_BOTTOMSTYLE))|            ((style<<XF_SHIFTPOS_BOTTOMSTYLE)             & XF_BORDER0_BOTTOMSTYLE);         value &= (~XF_BORDER0_BOTTOMCOLOR);         color16 <<= XF_SHIFTPOS_BOTTOMCOLOR;         value  |= (color16 & XF_BORDER0_BOTTOMCOLOR);             SetValueAt((signed16_t)value, XF_OFFSET_BORDER0);         break;      }      case BORDER_TOP:      {         unsigned16_t color16 = color;             GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER1);         value = (value&(~XF_BORDER1_TOPSTYLE))|            ((style<<XF_SHIFTPOS_TOPSTYLE) & XF_BORDER1_TOPSTYLE);         value &= (~XF_BORDER1_TOPCOLOR);         color16 <<= XF_SHIFTPOS_TOPCOLOR;         value |=   (color16  & XF_BORDER1_TOPCOLOR);         SetValueAt((signed16_t)value, XF_OFFSET_BORDER1);         break;      }      case BORDER_LEFT:         {         unsigned16_t color16 = color;         unsigned16_t style16 = style;         GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER1);         value &= (~XF_BORDER1_LEFTSTYLE);         style16 <<= XF_SHIFTPOS_LEFTSTYLE;         value |= (style16 & XF_BORDER1_LEFTSTYLE);         SetValueAt((signed16_t)value, XF_OFFSET_BORDER1);         GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER2);         color16 <<= XF_SHIFTPOS_LEFTCOLOR;         value &= (~XF_BORDER2_LEFTCOLOR);         value |= (color16  & XF_BORDER2_LEFTCOLOR);         SetValueAt((signed16_t)value, XF_OFFSET_BORDER2);         break;      }      case BORDER_RIGHT:        {         unsigned16_t color16 = color;         unsigned16_t style16 = style;         GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER1);         value &= (~XF_BORDER1_RIGHTSTYLE);         style16 <<= XF_SHIFTPOS_RIGHTSTYLE;         value |= (style16 & XF_BORDER1_RIGHTSTYLE);         SetValueAt((signed16_t)value, XF_OFFSET_BORDER1);         GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER2);         color16 <<= XF_SHIFTPOS_RIGHTCOLOR;         value &= (~XF_BORDER2_RIGHTCOLOR);         value |= (color16 & XF_BORDER2_RIGHTCOLOR);         SetValueAt((signed16_t)value, XF_OFFSET_BORDER2);         break;      }      default:         break;       }      SetFlag(XF_ALIGN_ATRBDR);}/* *********************************************************************/void CExtFormat::SetXFParent(unsigned16_t parent){      if(IsCell())   {      unsigned8_t value;            // Set the cell's style parent to Normal      GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);      value = (value&(~XF_PROP_XFPARENT))|         ((parent<<XF_PROP_SHIFTPOS_PARENT) & XF_ALIGN_HORIZONTAL);      SetValueAt((signed16_t)value, XF_OFFSET_PROP);          }   else   {      /*Do nothing: Styles don't have parent... but still clear the flags...*/   }   ClearFlag(XF_ALIGN_ATRFONT|XF_ALIGN_ATRALC|XF_ALIGN_ATRBDR|             XF_ALIGN_ATRPAT|XF_ALIGN_ATRPROT);}/* **********************************xf_t class implementation***********************************//* *********************************************************************/const unsigned8_t xf_t::HALIGN_OPTIONS_TABLE[] = {   XF_HALIGN_GENERAL      ,   XF_HALIGN_LEFT         ,   XF_HALIGN_CENTER       ,   XF_HALIGN_RIGHT        ,   XF_HALIGN_FILL         ,   XF_HALIGN_JUSTIFY      ,   XF_HALIGN_CENTERACCROSS};/* *********************************************************************/const unsigned8_t xf_t::VALIGN_OPTIONS_TABLE[] = {   XF_VALIGN_TOP    ,   XF_VALIGN_CENTER ,   XF_VALIGN_BOTTOM ,   XF_VALIGN_JUSTIFY};/* *********************************************************************/const unsigned8_t xf_t::TXTORI_OPTIONS_TABLE[] = {   XF_ORI_NONE        ,   XF_ORI_TOPBOTTOMTXT,   XF_ORI_90NOCLOCKTXT,   XF_ORI_90CLOCKTXT  };/* *********************************************************************/const unsigned8_t xf_t::COLOR_OPTIONS_TABLE[] ={   XF_COLOR_CODE_BLACK,   XF_COLOR_CODE_DARK_RED,   XF_COLOR_CODE_RED,   XF_COLOR_CODE_FUCSIA,   XF_COLOR_CODE_COMBINED01,   XF_COLOR_CODE_COMBINED02,   XF_COLOR_CODE_COMBINED03,   XF_COLOR_CODE_COMBINED04,   XF_COLOR_CODE_COMBINED05,   XF_COLOR_CODE_COMBINED06,   XF_COLOR_CODE_OLIVE,   XF_COLOR_CODE_DARK_YELLOW,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -