]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Export to Excel. Special classes to export data in native XLS 95-2003 format. BR_HDF_dev_for_QT_QWT
authorsmh <smh@opencascade.com>
Tue, 1 Nov 2011 06:16:21 +0000 (06:16 +0000)
committersmh <smh@opencascade.com>
Tue, 1 Nov 2011 06:16:21 +0000 (06:16 +0000)
src/Qtx/QtxXlsBiff.cxx [new file with mode: 0755]
src/Qtx/QtxXlsBiff.h [new file with mode: 0755]
src/Qtx/QtxXlsBorderTool.cxx [new file with mode: 0755]
src/Qtx/QtxXlsBorderTool.h [new file with mode: 0755]
src/Qtx/QtxXlsWriter.cxx [new file with mode: 0755]
src/Qtx/QtxXlsWriter.h [new file with mode: 0755]

diff --git a/src/Qtx/QtxXlsBiff.cxx b/src/Qtx/QtxXlsBiff.cxx
new file mode 100755 (executable)
index 0000000..c7ee119
--- /dev/null
@@ -0,0 +1,661 @@
+// Name   : QtxXlsBiff.cpp\r
+// Purpose: Implementation of QtxXlsBiff class.\r
+//\r
+// History:\r
+// 17/10/11 - Oleg Agashin - Creation of the file\r
+\r
+#include <QtxXlsBiff.h>\r
+\r
+/**\r
+ *\r
+ */\r
+QtxXlsBiff::QtxXlsBiff()\r
+: myDefaultFontName("Arial"),\r
+  myDefaultFontSize(10),\r
+  mySheetName("Sheet1"),\r
+  myLabelsNum(0)\r
+{\r
+  clear();\r
+}\r
+\r
+/**\r
+ * Check that high bytes of string chars\r
+ * equal to 0 and can be skipped\r
+ */\r
+bool QtxXlsBiff::canBePacked( const QString& theStr )\r
+{\r
+  QString::const_iterator anIt = theStr.begin();\r
+  while( (anIt++) != theStr.end() )\r
+  {\r
+    if ( (anIt->unicode() & 0xFF00) > 0 )\r
+      return false;\r
+  }\r
+  return true;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::SetSheetName( const QString& theName )\r
+{\r
+  if( !theName.isEmpty() )\r
+    mySheetName = theName;\r
+}\r
+\r
+/**\r
+ * Clear all structures\r
+ */\r
+void QtxXlsBiff::clear()\r
+{\r
+  cleanBuffers();\r
+\r
+  myFontTable.clear();\r
+  myFontNames.clear();\r
+  addDefaultFonts();\r
+\r
+  myStyleTable.clear();\r
+  addDefaultStyles();\r
+\r
+  mySSTTable.clear();\r
+  myLabelsNum = 0;\r
+\r
+  myMergedCells.clear();\r
+\r
+  myBlankCells.clear();\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::cleanBuffers()\r
+{\r
+  myWbDataBuf.clear();\r
+  myShDataBuf.clear();\r
+}\r
+\r
+/**\r
+ * BOF record\r
+ */\r
+void QtxXlsBiff::createBOF()\r
+{\r
+  BIFF8_BOF aBOF;\r
+\r
+  //BOF for workbook\r
+  aBOF.biffRecord.biffNum = _BOF;\r
+  aBOF.biffRecord.length  = SIZEOF(BIFF8_BOF);\r
+  aBOF.verOfBIFF          = BIFF_ver;\r
+  aBOF.typeOfData         = WorkbookGlobals;\r
+  aBOF.buildID            = 0x0DBB;\r
+  aBOF.buildYear          = 0x07CC;\r
+  aBOF.historyFlags       = 0x41;\r
+  aBOF.lowestVer          = 0x6;\r
+  myWbDataBuf.append( BYTE_ARRAY(aBOF.buf, sizeof(BIFF8_BOF)) );\r
+\r
+  //BOF for worksheet\r
+  aBOF.typeOfData         = Sheet;\r
+  myShDataBuf.prepend( BYTE_ARRAY(aBOF.buf, sizeof(BIFF8_BOF)) );\r
+}\r
+\r
+/**\r
+ * WINDOW1 record\r
+ */\r
+void QtxXlsBiff::createWindow1()\r
+{\r
+  BIFF8_WINDOW1 aWND;\r
+\r
+  aWND.biffRecord.biffNum = WINDOW1;\r
+  aWND.biffRecord.length  = SIZEOF(BIFF8_WINDOW1);\r
+  aWND.xWnd               = 0;\r
+  aWND.yWnd               = 0;\r
+  aWND.dxWnd              = 0x25BC;\r
+  aWND.dyWnd              = 0x1572;\r
+  aWND.optionFlags        = None;\r
+    aWND.fDspHScroll      = 1;\r
+    aWND.fDspVScroll      = 1;\r
+    aWND.fDisplayWbTabs   = 1;\r
+  aWND.iSelWbTab          = 0;\r
+  aWND.iFirstDispWbTab    = 0;\r
+  aWND.selTabNum          = 1;\r
+  aWND.wTabRatio          = 0x0258;\r
+  \r
+  myWbDataBuf.append( BYTE_ARRAY(aWND.buf, sizeof(BIFF8_WINDOW1)) );\r
+}\r
+\r
+/**\r
+ * Date1904 record\r
+ */\r
+void QtxXlsBiff::createDate1904()\r
+{\r
+  BIFF8_DATE1904 aDate;\r
+  aDate.biffRecord.biffNum = DATE1904;\r
+  aDate.biffRecord.length  = SIZEOF(BIFF8_DATE1904);\r
+  aDate.f1904              = None;\r
+  myWbDataBuf.append( BYTE_ARRAY(aDate.buf, sizeof(BIFF8_DATE1904)) );\r
+}\r
+\r
+/**\r
+ * Adds user-defined font into the font table\r
+ */\r
+int QtxXlsBiff::addFont( const QString& theFontName,\r
+                      const XlsWORD theFontSize,\r
+                      const bool theIsBold,\r
+                      const XlsWORD theFontColor,\r
+                      const XlsWORD theFontStyle,\r
+                      const XlsWORD theSuperSubscriptType,\r
+                      const XlsWORD theUnderlineType )\r
+\r
+{\r
+  BIFF8_FONT aFont = formatFontRecord( theFontName,\r
+                                       theFontSize,\r
+                                       theIsBold,\r
+                                       theFontColor,\r
+                                       theFontStyle,\r
+                                       theSuperSubscriptType,\r
+                                       theUnderlineType );\r
+\r
+  myFontTable.append( aFont );\r
+  myFontNames.append( theFontName );\r
+  \r
+  return myFontTable.size() - 1;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+QtxXlsBiff::BIFF8_FONT QtxXlsBiff::formatFontRecord( const QString& theFontName,\r
+                                                     const XlsWORD theFontSize,\r
+                                                     const bool theIsBold,\r
+                                                     const XlsWORD theFontColor,\r
+                                                     const XlsWORD theFontStyle,\r
+                                                     const XlsWORD theSuperSubscriptType,\r
+                                                     const XlsWORD theUnderlineType )\r
+\r
+{\r
+  BIFF8_FONT aFont;\r
+  aFont.biffRecord.biffNum = FONT;\r
+  //Beacause unicode\r
+  aFont.biffRecord.length  = SIZEOF(BIFF8_FONT) + theFontName.length();\r
+  aFont.height             = theFontSize * 20;\r
+  aFont.fontAttr           = theFontStyle;\r
+  aFont.color              = theFontColor;\r
+  aFont.boldStyle          = theIsBold ? BoldText : NormalText;\r
+  aFont.superSubStyle      = theSuperSubscriptType;\r
+  aFont.underlineStyle     = theUnderlineType;\r
+  aFont.fontFamily         = None;\r
+  aFont.charSet            = ANSI_Latin;\r
+  aFont.reserved           = None;\r
+  aFont.fontNameLen        = theFontName.length();\r
+  aFont.unicodeStrFlags    = Compressed;\r
+\r
+  if ( !canBePacked( theFontName ) )\r
+  {\r
+    aFont.unicodeStrFlags    = Uncompressed;\r
+    aFont.biffRecord.length += theFontName.length();\r
+  }\r
+\r
+  return aFont;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::addDefaultFonts()\r
+{\r
+  BIFF8_FONT aFont = formatFontRecord( myDefaultFontName, myDefaultFontSize );\r
+  //MS Excel requires five font records at least\r
+  for( int i = 0; i < 5; i++ )\r
+  {\r
+    myFontTable.append( aFont );\r
+    myFontNames.append( myDefaultFontName );\r
+\r
+  }\r
+}\r
+\r
+/**\r
+ * Packs all font records into font table\r
+ */\r
+void QtxXlsBiff::createFontTable()\r
+{\r
+  QByteArray aUnicodeByteName;\r
+  int aCount = myFontTable.size();\r
+\r
+  for( int i = 0; i < aCount; i++ )\r
+  {\r
+    if ( myFontTable[i].unicodeStrFlags == Compressed )\r
+    {\r
+      aUnicodeByteName.append( myFontNames[i] );\r
+    }\r
+    else\r
+    {\r
+      aUnicodeByteName = unicodeToByteArray( myFontNames[i] );\r
+    }\r
+\r
+    myWbDataBuf.append( BYTE_ARRAY(myFontTable[i].buf, sizeof(BIFF8_FONT)) );\r
+    myWbDataBuf.append( aUnicodeByteName );\r
+\r
+    aUnicodeByteName.clear();\r
+  }\r
+}\r
+\r
+/**\r
+ * Adds user-defined cell format into the format table\r
+ */\r
+int QtxXlsBiff::addCellStyle( const XlsWORD theFontID,\r
+                              const XlsWORD theFormatID,\r
+                              const XlsWORD theAlign,\r
+                              const XlsWORD theVAlign,\r
+                              const QtxXlsBiff::Border* theBorders,\r
+                              const bool    theIsWrapped,\r
+                              const bool    theIsMerged,\r
+                              const XlsWORD theRotation,\r
+                              const XlsBYTE theForegrountColorID,\r
+                              const XlsBYTE theBackgrountColorID/*,\r
+                              const XlsWORD theParentStyleID*/ )\r
+{\r
+  BIFF8_XF aXF;\r
+  for( int i = 2; i < 24; i++ )\r
+    aXF.buf[i] = 0;\r
+\r
+  //Create default style formats\r
+  aXF.biffRecord.biffNum = XF;\r
+  aXF.biffRecord.length  = SIZEOF(BIFF8_XF);\r
+  aXF.fontID             = theFontID > 3 ? theFontID + 1 : theFontID;\r
+  aXF.formatID           = theFormatID;\r
+\r
+  aXF.fStyle             = Cell;\r
+  aXF.ixfParent          = NoParentStyle/*theParentStyleID*/;\r
+\r
+  aXF.align              = theAlign;\r
+  aXF.valign             = theVAlign;\r
+  aXF.fWrap              = theIsWrapped;\r
+  aXF.rotation           = theRotation;\r
+  aXF.mergeCell          = theIsMerged;\r
+\r
+\r
+  aXF.foregroundColor    = theForegrountColorID;\r
+  aXF.backgroundColor    = theBackgrountColorID;\r
+\r
+  if( theBorders )\r
+  {\r
+    aXF.left               = theBorders->leftBorderStyle;\r
+    aXF.right              = theBorders->rightBorderStyle;\r
+    aXF.top                = theBorders->topBorderStyle;\r
+    aXF.bottom             = theBorders->bottomBorderStyle;\r
+\r
+    aXF.colorLeft          = theBorders->leftBorderColor;\r
+    aXF.colorRight         = theBorders->rightBorderColor;\r
+    aXF.colorTop           = theBorders->topBorderColor;\r
+    aXF.colorBottom        = theBorders->bottomBorderColor;\r
+\r
+    aXF.diagBdrStyle       = theBorders->diagonalBorderStyle;\r
+    aXF.diagonalType       = theBorders->diagonalType;\r
+    aXF.colorDiagonal      = theBorders->diagonalColor;\r
+  }\r
+\r
+  myStyleTable.append( aXF );\r
+\r
+  return myStyleTable.size() - 1;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::addDefaultStyles()\r
+{\r
+  BIFF8_XF aXF;\r
+  for( int i = 2; i < 24; i++ )\r
+    aXF.buf[i] = 0;\r
+\r
+  //Create default style formats\r
+  aXF.biffRecord.biffNum = XF;\r
+  aXF.biffRecord.length  = SIZEOF(BIFF8_XF);\r
+  aXF.fStyle             = Style;\r
+  aXF.ixfParent          = NoParentStyle;\r
+  aXF.align              = AlignGeneral;\r
+  aXF.valign             = VAlignCenter;\r
+  aXF.foregroundColor    = DefaultForegroundColor;\r
+  aXF.backgroundColor    = DefaultBackgroundColor;\r
+\r
+  //Table contains 15 style format records at least\r
+  for( int i = 0; i < 15; i++ )\r
+    myStyleTable.append( aXF );\r
+\r
+  //Create default cell formats, \r
+  aXF.paramFlags         = Cell;\r
+  myStyleTable.append( aXF );\r
+}\r
+\r
+/**\r
+ * Packs all cell format records into cell format table\r
+ */\r
+void QtxXlsBiff::createFormatTable()\r
+{\r
+  // Write additional format records here\r
+  QVector<BIFF8_XF>::iterator anIt = myStyleTable.begin();\r
+  while( anIt != myStyleTable.end() )\r
+  {\r
+    myWbDataBuf.append( BYTE_ARRAY((*anIt).buf, sizeof(BIFF8_XF)) );\r
+    ++anIt;\r
+  }\r
+}\r
+\r
+/**\r
+ * STYLE record\r
+ */\r
+void QtxXlsBiff::createStyleInfoTable()\r
+{\r
+  //Each style in an Excel workbook, whether built-in\r
+  //or user-defined, requires a style record\r
+  BIFF8_STYLE aStyle;\r
+  aStyle.biffRecord.biffNum = STYLE;\r
+  aStyle.biffRecord.length  = SIZEOF(BIFF8_STYLE);\r
+  aStyle.iXF                = None;\r
+    aStyle.ixfe             = 0;\r
+    aStyle.fBuiltIn         = 1;\r
+  aStyle.builtInStyle       = Normal;\r
+  aStyle.level              = 0xFF;\r
+  myWbDataBuf.append( BYTE_ARRAY(aStyle.buf, sizeof(BIFF8_STYLE)) );\r
+}\r
+\r
+/**\r
+ * Stores unicode value of string into byte array\r
+ * ( QString converts unicode char into ASCII char )\r
+ */\r
+QByteArray QtxXlsBiff::unicodeToByteArray( const QString& theStr )\r
+{\r
+  QByteArray aUnicodeByteName;\r
+  xlsWORDExcange anExchanger;\r
+\r
+  for( int i = 0; i < theStr.length(); i++ )\r
+  {\r
+    anExchanger.value = theStr[i].unicode();\r
+    aUnicodeByteName.append( anExchanger.buf[0] );\r
+    aUnicodeByteName.append( anExchanger.buf[1] );\r
+  }\r
+\r
+  return aUnicodeByteName;\r
+}\r
+\r
+/**\r
+ * BOUNDSHEET record contains information about worksheet\r
+ */\r
+void QtxXlsBiff::createBoundsheet( const int theSSTLength )\r
+{\r
+  BIFF8_BOUNDSHEET aBoundsheet;\r
+  aBoundsheet.biffRecord.biffNum = BOUNDSHEET;\r
+  aBoundsheet.biffRecord.length  = SIZEOF(BIFF8_BOUNDSHEET) + mySheetName.length();\r
+\r
+  aBoundsheet.hiddenSate         = Visible;\r
+  aBoundsheet.reserved           = None;\r
+  aBoundsheet.sheetType          = WorksheetType;\r
+\r
+  aBoundsheet.sheetNameLen       = mySheetName.length();\r
+  aBoundsheet.unicodeStrFlags    = Compressed;\r
+\r
+  QByteArray aUnicodeByteName;\r
+  if ( canBePacked( mySheetName ) )\r
+  {\r
+    aUnicodeByteName.append( mySheetName );\r
+  }\r
+  else\r
+  {\r
+    aBoundsheet.unicodeStrFlags    = Uncompressed;\r
+    aBoundsheet.biffRecord.length += mySheetName.length();\r
+\r
+    aUnicodeByteName = unicodeToByteArray(mySheetName);\r
+  }\r
+\r
+  aBoundsheet.streamStartPos = myWbDataBuf.length() +\r
+                               sizeof(BIFF8_BOUNDSHEET)  + \r
+                               aUnicodeByteName.length() +\r
+                               sizeof(BIFF8_SST) +\r
+                               theSSTLength +\r
+                               sizeof(BIFF8_RECORD); //EOF\r
+\r
+  myWbDataBuf.append( BYTE_ARRAY(aBoundsheet.buf, sizeof(BIFF8_BOUNDSHEET)) );\r
+  myWbDataBuf.append( aUnicodeByteName );\r
+}\r
+\r
+/**\r
+ * SST record contains Shared String Table\r
+ */\r
+void QtxXlsBiff::createSSTTable( const QByteArray& theStringTable )\r
+{\r
+  BIFF8_SST aSST;\r
+  aSST.biffRecord.biffNum = SST;\r
+  aSST.biffRecord.length  = SIZEOF(BIFF8_SST) + theStringTable.size();\r
+  aSST.totalNum           = myLabelsNum;\r
+  aSST.uniqueNum          = mySSTTable.size();\r
+\r
+  myWbDataBuf.append( BYTE_ARRAY(aSST.buf, sizeof(BIFF8_SST)) );\r
+  myWbDataBuf.append( theStringTable );\r
+}\r
+\r
+/**\r
+ * \r
+ */\r
+void QtxXlsBiff::createMergeCellsRecord()\r
+{\r
+  if ( myMergedCells.isEmpty() )\r
+    return;\r
+\r
+  QVector<BIFF8_REF>::iterator anIt = myMergedCells.begin();\r
+\r
+  QByteArray aMergedCellsBuf;\r
+  BIFF8_RECORD aRec;\r
+  aRec.biffNum = MERGECELLS;\r
+  aRec.length  = sizeof(XlsWORD) + sizeof(BIFF8_REF) * myMergedCells.size();\r
+  aMergedCellsBuf.append( DWORD_BYTE_ARRAY(aRec.buf) );\r
+\r
+  xlsWORDExcange aCount;\r
+  aCount.value = myMergedCells.size();\r
+  aMergedCellsBuf.append( BYTE_ARRAY(aCount.buf, sizeof(XlsWORD)) );\r
+\r
+  while( anIt != myMergedCells.end() )\r
+  {\r
+    aMergedCellsBuf.append( BYTE_ARRAY(anIt->buf, sizeof(BIFF8_REF)) );\r
+    ++anIt;\r
+  }\r
+\r
+  myShDataBuf.append( aMergedCellsBuf );\r
+}\r
+\r
+/**\r
+ * Returns byte array with workbook and worksheet data\r
+ * prepared for writing\r
+ */\r
+QByteArray QtxXlsBiff::getBiffData()\r
+{\r
+  createBOF();\r
+  createWindow1();\r
+  createDate1904();\r
+\r
+  createFontTable();\r
+  createFormatTable();\r
+  createStyleInfoTable();\r
+\r
+  //SST len determination\r
+  QByteArray aUnicodeByteName;\r
+  QStringList::const_iterator anIt = mySSTTable.begin();\r
+  while( anIt != mySSTTable.end() )\r
+  {\r
+    xlsWORDExcange anExchanger;\r
+    anExchanger.value = anIt->length();\r
+    aUnicodeByteName.append( anExchanger.buf[0] );\r
+    aUnicodeByteName.append( anExchanger.buf[1] );\r
+\r
+    if ( canBePacked( *anIt ) )\r
+    {\r
+      aUnicodeByteName.append( Compressed );\r
+      aUnicodeByteName.append( *anIt );\r
+    }\r
+    else\r
+    {\r
+      aUnicodeByteName.append( Uncompressed );\r
+      aUnicodeByteName.append( unicodeToByteArray( *anIt ) );\r
+    }\r
+\r
+    ++anIt;\r
+  }\r
+\r
+  createBoundsheet( aUnicodeByteName.size() );\r
+  createSSTTable( aUnicodeByteName );\r
+\r
+  xlsDWORDExcange anExchanger;\r
+  anExchanger.value = _EOF;\r
+\r
+  QByteArray aEOF( TO_PCHAR(anExchanger.buf), sizeof(XlsDWORD) );\r
+\r
+  QByteArray aDataBuffer( myWbDataBuf );\r
+  aDataBuffer.append( aEOF );\r
+\r
+  createMergeCellsRecord();\r
+\r
+  aDataBuffer.append( myShDataBuf );\r
+  aDataBuffer.append( aEOF );\r
+\r
+  cleanBuffers();\r
+\r
+  return aDataBuffer;\r
+}\r
+\r
+/**\r
+ * Adds number value\r
+ */\r
+void QtxXlsBiff::addData( const double theNumber,\r
+                          const XlsWORD theRow,\r
+                          const XlsWORD theCol,\r
+                          const XlsWORD theStyleID )\r
+{\r
+  BIFF8_NUMBER aNumber;\r
+  aNumber.biffRecord.biffNum = NUMBER;\r
+  aNumber.biffRecord.length  = SIZEOF(BIFF8_NUMBER);\r
+\r
+  aNumber.row = theRow;\r
+  aNumber.col = theCol;\r
+  aNumber.iXF = theStyleID; //first cell format record having id = 15\r
+  aNumber.num = theNumber;\r
+\r
+  myShDataBuf.append( BYTE_ARRAY(aNumber.buf, sizeof(BIFF8_NUMBER)) );\r
+}\r
+\r
+/**\r
+ * Adds string or blank value\r
+ */\r
+void QtxXlsBiff::addData( const QString& theString,\r
+                          const XlsWORD  theRow,\r
+                          const XlsWORD  theCol,\r
+                          const XlsWORD  theStyleID )\r
+{\r
+  if ( theString.isEmpty() )\r
+  {\r
+    BIFF8_BLANK aBlank;\r
+    aBlank.biffRecord.biffNum = BLANK;\r
+    aBlank.biffRecord.length  = SIZEOF(BIFF8_BLANK);\r
+    aBlank.row                = theRow;\r
+    aBlank.col                = theCol;\r
+    aBlank.iXF                = theStyleID;\r
+\r
+    myShDataBuf.append( BYTE_ARRAY(aBlank.buf, sizeof(BIFF8_BLANK)) );\r
+    return;\r
+  }\r
+\r
+  int anIndex = mySSTTable.indexOf( theString );\r
+  \r
+  BIFF8_LABELSST aLabel;\r
+  aLabel.biffRecord.biffNum = LABELSST;\r
+  aLabel.biffRecord.length  = SIZEOF(BIFF8_LABELSST);\r
+  aLabel.row                = theRow;\r
+  aLabel.col                = theCol;\r
+  aLabel.iXF                = theStyleID; //first cell format record having id = 15\r
+\r
+  if ( anIndex < 0 )\r
+  {\r
+    mySSTTable.append( theString );\r
+    aLabel.iSST             = mySSTTable.size() - 1;\r
+  }\r
+  else\r
+  {\r
+    aLabel.iSST             = anIndex;\r
+  }\r
+\r
+  ++myLabelsNum;\r
+  myShDataBuf.append( BYTE_ARRAY(aLabel.buf, sizeof(BIFF8_LABELSST)) );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::mergeCells( const XlsWORD theFirstRow, const XlsWORD theLastRow,\r
+                             const XlsWORD theFirstCol, const XlsWORD theLastCol )\r
+{\r
+  BIFF8_REF aRef;\r
+  aRef.rowFirst = theFirstRow;\r
+  aRef.rowLast  = theLastRow;\r
+  aRef.colFirst = theFirstCol;\r
+  aRef.colLast  = theLastCol;\r
+\r
+  myMergedCells.append( aRef );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::setColWidth( const XlsWORD theWidth, const XlsWORD theFrom,\r
+                              const XlsWORD theTo, const XlsWORD theStyleID )\r
+{\r
+  BIFF8_COLINFO aColinfo;\r
+  aColinfo.biffRecord.biffNum = COLINFO;\r
+  aColinfo.biffRecord.length  = SIZEOF(BIFF8_COLINFO);\r
+  aColinfo.colFirst           = theFrom;\r
+  aColinfo.colLast            = theTo;\r
+  aColinfo.colDx              = 256 * theWidth;\r
+  aColinfo.iXF                = theStyleID;\r
+  aColinfo.options            = None;\r
+  aColinfo.reserved           = None;\r
+\r
+  myShDataBuf.append( BYTE_ARRAY(aColinfo.buf, sizeof(BIFF8_COLINFO)) );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::getFontParams( const XlsWORD theStyleID, QString& theFontName,\r
+                                int& theFontSize, bool& theIsBold )\r
+{\r
+  if ( myStyleTable.size() < theStyleID )\r
+  {\r
+    theFontName = "";\r
+    theFontSize = -1;\r
+    theIsBold   = false;\r
+    return;\r
+  }\r
+\r
+  int aFontId = myStyleTable[theStyleID].fontID;\r
+  if ( aFontId < MinFontNum + 1 )\r
+  {\r
+    theFontName = myDefaultFontName;\r
+    theFontSize = myDefaultFontSize;\r
+    theIsBold   = false;\r
+    return;\r
+  }\r
+\r
+  --aFontId;\r
+\r
+  theFontName = myFontNames[aFontId];\r
+  theFontSize = myFontTable[aFontId].height / 20;\r
+  theIsBold   = myFontTable[aFontId].boldStyle == BoldText;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsBiff::cleanBorderStruct( QtxXlsBiff::Border& theBorder )\r
+{\r
+  Border aBorder = { None, None, None,\r
+                     None, None, None,\r
+                     None, None, None,\r
+                     None, None };\r
+\r
+  theBorder = aBorder;\r
+}\r
diff --git a/src/Qtx/QtxXlsBiff.h b/src/Qtx/QtxXlsBiff.h
new file mode 100755 (executable)
index 0000000..15c57fe
--- /dev/null
@@ -0,0 +1,604 @@
+// Name   : QtxXlsBiff.h\r
+// Purpose: QtxXlsBiff is a class for storing main data to high-level *.XLS structures.\r
+//\r
+// History:\r
+// 17/10/11 - Oleg Agashin - Creation of the file\r
+\r
+#ifndef QTXXLSBIFF_HEADER\r
+#define QTXXLSBIFF_HEADER\r
+\r
+#include <QString>\r
+#include <QStringList>\r
+#include <QVector>\r
+\r
+//Own types\r
+typedef unsigned char  XlsBYTE;\r
+typedef unsigned short XlsWORD;\r
+typedef unsigned int   XlsDWORD;\r
+\r
+#define TO_PCHAR(x) reinterpret_cast<char*>(x)\r
+#define BYTE_ARRAY(x,y) QByteArray(TO_PCHAR(x), (y))\r
+#define DWORD_BYTE_ARRAY(x) BYTE_ARRAY((x), sizeof(XlsDWORD))\r
+\r
+union xlsWORDExcange\r
+{\r
+  XlsBYTE  buf[sizeof(XlsWORD)];\r
+  XlsWORD value;\r
+};\r
+\r
+union xlsDWORDExcange\r
+{\r
+  XlsBYTE  buf[sizeof(XlsDWORD)];\r
+  XlsDWORD value;\r
+};\r
+\r
+\r
+#pragma pack(push,1)\r
+\r
+#define SIZEOF(x) (sizeof(x) - sizeof(BIFF8_RECORD))\r
+\r
+/**\r
+ * Class for creating data model\r
+ *\r
+ * Format of *.XLS data model:\r
+ * +----------------------------+\r
+ * | BOF                        |\r
+ * +----------------------------+\r
+ * | Workbook Globals           |\r
+ * +----------------------------+\r
+ * | EOF                        |\r
+ * +----------------------------+\r
+ * +----------------------------+\r
+ * | BOF                        |\r
+ * +----------------------------+\r
+ * | Sheet stream               |\r
+ * |    getBiffBeforeData       |\r
+ * |      #Data                 |\r
+ * |    getBiffAfterData        |\r
+ * +----------------------------+\r
+ * | EOF                        |\r
+ * +----------------------------+\r
+ */\r
+class QtxXlsBiff\r
+{\r
+  //-------------- BIFF structure types ------------------------\r
+\r
+  union BIFF8_RECORD\r
+  {\r
+    XlsBYTE buf[4];\r
+    struct\r
+    {\r
+      XlsWORD biffNum;\r
+      XlsWORD length;\r
+    };\r
+  };\r
+\r
+  union BIFF8_BOF\r
+  {\r
+    XlsBYTE buf[20];\r
+    struct\r
+    {\r
+      BIFF8_RECORD  biffRecord;\r
+      XlsWORD       verOfBIFF;\r
+      XlsWORD       typeOfData;\r
+      XlsWORD       buildID;\r
+      XlsWORD       buildYear;\r
+      XlsDWORD      historyFlags;\r
+      XlsDWORD      lowestVer;\r
+    };\r
+  };\r
+\r
+  union BIFF8_DATE1904\r
+  {\r
+    XlsBYTE buf[6];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsWORD      f1904;\r
+    };\r
+  };\r
+\r
+  union BIFF8_XF\r
+  {\r
+    XlsBYTE buf[24];\r
+    struct\r
+    {\r
+      BIFF8_RECORD  biffRecord;\r
+      XlsWORD       fontID;\r
+      XlsWORD       formatID;\r
+      union\r
+      {\r
+        XlsWORD     paramFlags;\r
+        struct\r
+        {\r
+          XlsWORD fLocked    : 1;\r
+          XlsWORD fHidden    : 1;\r
+          XlsWORD fStyle     : 1;\r
+          XlsWORD f123Prefix : 1;\r
+          XlsWORD ixfParent  : 12;\r
+        };\r
+      };\r
+      union\r
+      {\r
+        XlsWORD     formatAlign;\r
+        struct\r
+        {\r
+          XlsWORD align     : 3;\r
+          XlsWORD fWrap     : 1;\r
+          XlsWORD valign    : 3;\r
+          XlsWORD fJustLast : 1;\r
+          XlsWORD rotation  : 8;\r
+        };\r
+      };\r
+      union\r
+      {\r
+        XlsWORD     formatView;\r
+        struct\r
+        {\r
+          XlsWORD indent      : 4;\r
+          XlsWORD shrinkToFit : 1;\r
+          XlsWORD mergeCell   : 1;\r
+          XlsWORD readOrder   : 2;\r
+          XlsWORD reserved1   : 2;\r
+          XlsWORD attrNum     : 1;\r
+          XlsWORD attrFnt     : 1;\r
+          XlsWORD attrAlign   : 1;\r
+          XlsWORD attrBdr     : 1;\r
+          XlsWORD attrPat     : 1;\r
+          XlsWORD attrProt    : 1;\r
+        };\r
+      };\r
+      union\r
+      {\r
+        XlsWORD     formatBorder;\r
+        struct\r
+        {\r
+          XlsWORD left   : 4;\r
+          XlsWORD right  : 4;\r
+          XlsWORD top    : 4;\r
+          XlsWORD bottom : 4;\r
+        };\r
+      };\r
+      union\r
+      {\r
+        XlsWORD     formatLRBdrColor;\r
+        struct\r
+        {\r
+          XlsWORD colorLeft    : 7;\r
+          XlsWORD colorRight   : 7;\r
+          XlsWORD diagonalType : 2;\r
+        };\r
+      };\r
+      union\r
+      {\r
+        XlsDWORD     formatTBBdrColor;\r
+        struct\r
+        {\r
+          XlsDWORD colorTop      : 7;\r
+          XlsDWORD colorBottom   : 7;\r
+          XlsDWORD colorDiagonal : 7;\r
+          XlsDWORD diagBdrStyle  : 4;\r
+          XlsDWORD hasXFExt      : 1;\r
+          XlsDWORD fillPattern   : 6;\r
+        };\r
+      };\r
+      union\r
+      {\r
+        XlsWORD     formatBGColor;\r
+        struct\r
+        {\r
+          XlsWORD foregroundColor : 7;\r
+          XlsWORD backgroundColor : 7;\r
+          XlsWORD sxButton        : 1;\r
+          XlsWORD reserved2       : 1;\r
+        };\r
+      };\r
+    };\r
+  };\r
+\r
+  union BIFF8_FONT\r
+  {\r
+    //XlsBYTE buf[19];\r
+    XlsBYTE buf[20];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsWORD      height;\r
+      union\r
+      {\r
+        XlsWORD    fontAttr;\r
+        struct\r
+        {\r
+          XlsWORD reserved1  : 1;\r
+          XlsWORD fItalic    : 1;\r
+          XlsWORD reserved2  : 1;\r
+          XlsWORD fStrikeout : 1;\r
+          XlsWORD fOutline   : 1;\r
+          XlsWORD fShadow    : 1;\r
+          XlsWORD reserved3  : 2;\r
+          XlsWORD unused     : 8;\r
+        };\r
+      };\r
+      XlsWORD      color;\r
+      XlsWORD      boldStyle;\r
+      XlsWORD      superSubStyle;\r
+      XlsBYTE      underlineStyle;\r
+      XlsBYTE      fontFamily;\r
+      XlsBYTE      charSet;\r
+      XlsBYTE      reserved; //zero\r
+      XlsBYTE      fontNameLen;\r
+      XlsBYTE      unicodeStrFlags;\r
+      //+ font name\r
+    };\r
+  };\r
+\r
+  union BIFF8_BOUNDSHEET\r
+  {\r
+    XlsBYTE buf[12];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsDWORD streamStartPos;\r
+      union\r
+      {\r
+        XlsWORD  sheetAttr;\r
+        struct\r
+        {\r
+          XlsWORD hiddenSate : 2;\r
+          XlsWORD reserved   : 6;\r
+          XlsWORD sheetType  : 8;\r
+        };\r
+      };\r
+      XlsBYTE  sheetNameLen;\r
+      XlsBYTE  unicodeStrFlags;\r
+      //+ sheet name\r
+    };\r
+  };\r
+\r
+  union BIFF8_STYLE\r
+  {\r
+    XlsBYTE buf[8];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      union\r
+      {\r
+        XlsWORD    iXF;\r
+        struct\r
+        {\r
+          XlsWORD ixfe     : 12;\r
+          XlsWORD unused   : 3;\r
+          XlsWORD fBuiltIn : 1;\r
+        };\r
+      };\r
+      XlsBYTE      builtInStyle;\r
+      XlsBYTE      level; \r
+    };\r
+  };\r
+\r
+  union BIFF8_SST\r
+  {\r
+    XlsBYTE buf[12];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsDWORD     totalNum;\r
+      XlsDWORD     uniqueNum;\r
+    };\r
+  };\r
+\r
+  union BIFF8_ROW\r
+  {\r
+    XlsBYTE buf[20];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsWORD      rowNum;\r
+      XlsWORD      firstCol;\r
+      XlsWORD      lastCol;\r
+      XlsWORD      rowHeight;\r
+      XlsWORD      irwMac;\r
+      XlsWORD      reserved;\r
+      union\r
+      {\r
+        XlsWORD    optionFlags;\r
+        struct\r
+        {\r
+          XlsWORD  fOutlineLevel: 3;\r
+          XlsWORD  reserved1    : 1;\r
+          XlsWORD  fCollapsed   : 1;\r
+          XlsWORD  fDyZero      : 1;\r
+          XlsWORD  fUnsynced    : 1;\r
+          XlsWORD  fGhostDirty  : 1;\r
+          XlsWORD  reserved2    : 8;\r
+        };\r
+      };\r
+      XlsWORD      iXF;\r
+    };\r
+  };\r
+\r
+  union BIFF8_WINDOW1\r
+  {\r
+    XlsBYTE buf[22];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsWORD      xWnd;\r
+      XlsWORD      yWnd;\r
+      XlsWORD      dxWnd;\r
+      XlsWORD      dyWnd;\r
+      union\r
+      {\r
+        XlsWORD    optionFlags;\r
+        struct\r
+        {\r
+          XlsWORD  fHidden        : 1;\r
+          XlsWORD  fIconic        : 1;\r
+          XlsWORD  reserved1      : 1;\r
+          XlsWORD  fDspHScroll    : 1;\r
+          XlsWORD  fDspVScroll    : 1;\r
+          XlsWORD  fDisplayWbTabs : 1;\r
+          XlsWORD  fNoAFDateGroup : 1;\r
+          XlsWORD  reserved2      : 1;\r
+          XlsWORD  reserved3      : 8;\r
+        };\r
+      };\r
+      XlsWORD      iSelWbTab;\r
+      XlsWORD      iFirstDispWbTab;\r
+      XlsWORD      selTabNum;\r
+      XlsWORD      wTabRatio;\r
+    };\r
+  };\r
+\r
+  union BIFF8_COLINFO\r
+  {\r
+    XlsBYTE buf[16];\r
+    struct\r
+    {\r
+      BIFF8_RECORD biffRecord;\r
+      XlsWORD      colFirst;\r
+      XlsWORD      colLast;\r
+      XlsWORD      colDx;\r
+      XlsWORD      iXF;\r
+      XlsWORD      options;\r
+      XlsWORD      reserved;\r
+    };\r
+  };\r
+\r
+  union BIFF8_REF\r
+  {\r
+    XlsBYTE buf[8];\r
+    struct  \r
+    {\r
+      XlsWORD rowFirst;\r
+      XlsWORD rowLast;\r
+      XlsWORD colFirst;\r
+      XlsWORD colLast;\r
+    };\r
+  };\r
+\r
+  //------------------- Excel data types -------------------\r
+  union BIFF8_NUMBER\r
+  {\r
+    XlsBYTE buf[18];\r
+    struct\r
+    {\r
+      BIFF8_RECORD  biffRecord;\r
+      XlsWORD       row;\r
+      XlsWORD       col;\r
+      XlsWORD       iXF;\r
+      double        num;\r
+    };\r
+  };\r
+\r
+  union BIFF8_BLANK\r
+  {\r
+    XlsBYTE buf[10];\r
+    struct\r
+    {\r
+      BIFF8_RECORD  biffRecord;\r
+      XlsWORD       row;\r
+      XlsWORD       col;\r
+      XlsWORD       iXF;\r
+    };\r
+  };\r
+\r
+  union BIFF8_LABELSST\r
+  {\r
+    XlsBYTE buf[14];\r
+    struct\r
+    {\r
+      BIFF8_RECORD  biffRecord;\r
+      XlsWORD       row;\r
+      XlsWORD       col;\r
+      XlsWORD       iXF;\r
+      XlsDWORD      iSST;\r
+    };\r
+  };\r
+  //-------------- end of Excel data types -----------------\r
+\r
+  enum TypeOfData { WorkbookGlobals = 0x5, VB = 0x6,\r
+                    Sheet = 0x10, Chart = 0x20,\r
+                    MacroSheet = 0x40,\r
+                    Workspace = 0x100 };\r
+\r
+  enum TypeOfXF { Cell = 0, Style };\r
+\r
+  enum ReadingOrder { Context = 0, LeftToRight, RightToLeft }; \r
+\r
+  enum OtherFormatConstants { NoTransKeys = 0, DefaultParentStyle = 0, NoParentStyle = 0xFFF };\r
+\r
+  enum SheetHiddenState { Visible = 0, Hidden, VeryHidden };\r
+  \r
+  enum SheetType { WorksheetType = 0, MacroType, ChartType, VBType = 6};\r
+\r
+  enum BuiltInSyles { Normal = 0, RowLevel_n, ColLevel_n, Comma,\r
+                      Currency, Percent, Comma_0, Currency_0 };\r
+\r
+  enum Constants { MinFontNum = 5, MinXFNum = 15 };\r
+\r
+  enum StringFlags { Compressed = 0, Uncompressed };\r
+\r
+  enum FormatNumbers { _BOF   = 0x0809,\r
+                       _EOF   = 0x000A,\r
+                       WINDOW1  = 0x003d,\r
+                       DATE1904 = 0x0022,\r
+                       FONT = 0x0031,\r
+                       BOUNDSHEET = 0x0085,\r
+                       NUMBER = 0x0203,\r
+                       BLANK  = 0x0201,\r
+                       LABELSST = 0x00FD,\r
+                       XF     = 0x00E0,\r
+                       SST    = 0x00FC,\r
+                       ROW    = 0x0208,\r
+                       MERGECELLS = 0x00E5,\r
+                       COLINFO = 0x007D,\r
+                       STYLE  = 0x0293,\r
+                       BIFF_ver = 0x0600 };\r
+  //-------------- end of BIFF structure types -----------------\r
+public:\r
+  enum Align { AlignGeneral = 0, AlignLeft, AlignCenter, AlignRight,\r
+               AlignFill, AlignJustify, AlignCenterAcrossSelection };\r
+\r
+  enum VAlign { VAlignTop = 0, VAlignCenter, VAlignBottom, VAlignJustify };\r
+\r
+  enum LineStyles { None = 0, Thin, Medium, Dashed,\r
+                    Dotted, Thick, Double, Hair,\r
+                    MediumDashed, DashDot, MediumDashDot,\r
+                    DashDotDot, MediumDashDotDot,\r
+                    SlantedDashDot,\r
+                    DiagDown = 1, DiagUp = 2, DiagBoth = 3};\r
+\r
+  enum FontStyle { Italic = 0x2, Strikeout = 0x8, Outline = 0x10,\r
+                   Shadow = 0x20, Superscript = 1, Subscript = 2 };\r
+\r
+  enum FontWeight { NormalText = 0x190, BoldText = 0x2BC };\r
+\r
+  enum FontUnderlineType { SingleUnderline = 1, DoubleUnderline, \r
+                           SingleAccountingUnderline = 0x21, DoubleAccountingUnderline = 0x22 };\r
+\r
+  enum InternalFormat { General = 0, Integer }; //0x31 total - see XF reference\r
+\r
+  enum DefaultGroundColors { DefaultForegroundColor = 0x40, DefaultBackgroundColor };\r
+\r
+  enum DefaultFontColor { Black = 0x7FFF };\r
+\r
+  enum Font { DefaultFont = 0 };\r
+  \r
+  enum Style { DefaultStyle = 15 };\r
+\r
+  enum CharSet { ANSI_Latin = 0, SystemDefault, Symbol };\r
+\r
+  struct Border\r
+  {\r
+    LineStyles leftBorderStyle;\r
+    LineStyles rightBorderStyle;\r
+    LineStyles topBorderStyle;\r
+    LineStyles bottomBorderStyle;\r
+\r
+    LineStyles diagonalType;\r
+    LineStyles diagonalBorderStyle;\r
+\r
+    XlsBYTE    leftBorderColor;\r
+    XlsBYTE    rightBorderColor;\r
+    XlsBYTE    topBorderColor;\r
+    XlsBYTE    bottomBorderColor;\r
+    XlsBYTE    diagonalColor;\r
+  };\r
+\r
+public:\r
+  QtxXlsBiff();\r
+\r
+public:\r
+  QByteArray getBiffData();\r
+  void clear();\r
+\r
+  static void cleanBorderStruct( Border& theBorder );\r
+\r
+  void SetSheetName( const QString& theName );\r
+\r
+  void setColWidth( const XlsWORD theWidth, const XlsWORD theFrom,\r
+                    const XlsWORD theTo,const XlsWORD theStyleID );\r
+\r
+  void getFontParams( const XlsWORD theStyleID, QString& theFontName,\r
+                      int& theFontSize, bool& theIsBold );\r
+\r
+  void addData(  const double  theNumber,\r
+                 const XlsWORD theRow,\r
+                 const XlsWORD theCol,\r
+                 const XlsWORD theStyleID = 0 );\r
+\r
+  void addData(  const QString& theString,\r
+                 const XlsWORD  theRow,\r
+                 const XlsWORD  theCol,\r
+                 const XlsWORD  theStyleID = 0 );\r
+\r
+  int addFont(   const QString& theFontName,\r
+                 const XlsWORD theFontSize,\r
+                 const bool theIsBold = false,\r
+                 const XlsWORD theFontColor = Black,\r
+                 const XlsWORD theFontStyle = None,\r
+                 const XlsWORD theSuperSubscriptType = None,\r
+                 const XlsWORD theUnderlineType = None );\r
+\r
+  int addCellStyle( const XlsWORD theFontID,\r
+                    const XlsWORD theFormatID,\r
+                    const XlsWORD theAlign,\r
+                    const XlsWORD theVAlign,\r
+                    const Border* theBorders = 0,\r
+                    const bool    theIsWrapped = false,\r
+                    const bool    theIsMerged = false,\r
+                    const XlsWORD theRotation = None,\r
+                    const XlsBYTE theForegrountColorID = DefaultForegroundColor,\r
+                    const XlsBYTE theBackgrountColorID = DefaultBackgroundColor );\r
+\r
+  void mergeCells( const XlsWORD theFirstRow, const XlsWORD theLastRow,\r
+                   const XlsWORD theFirstCol, const XlsWORD theLastCol );\r
+\r
+private:\r
+  bool canBePacked( const QString& theStr );\r
+  QByteArray unicodeToByteArray( const QString& theStr );\r
+  void cleanBuffers();\r
+  void addDefaultFonts();\r
+  void addDefaultStyles();\r
+\r
+  void createBOF();\r
+  void createWindow1();\r
+  void createDate1904();\r
+  void createFontTable();\r
+  void createFormatTable();\r
+  void createStyleInfoTable();\r
+  void createBoundsheet( const int theSSTLength );\r
+  void createSSTTable( const QByteArray& theStringTable );\r
+  void createMergeCellsRecord();\r
+\r
+  BIFF8_FONT formatFontRecord( const QString& theFontName,\r
+                               const XlsWORD theFontSize,\r
+                               const bool theIsBold = false,\r
+                               const XlsWORD theFontColor = Black,\r
+                               const XlsWORD theFontStyle = None,\r
+                               const XlsWORD theSuperSubscriptType = None,\r
+                               const XlsWORD theUnderlineType = None );\r
+private:\r
+  QString                 myDefaultFontName;\r
+  int                     myDefaultFontSize;\r
+\r
+  QString                 mySheetName;\r
+\r
+  QByteArray              myWbDataBuf;\r
+  QByteArray              myShDataBuf;\r
+\r
+  QVector<BIFF8_FONT>     myFontTable;\r
+  QStringList             myFontNames;\r
+\r
+  QVector<BIFF8_XF>       myStyleTable;\r
+  QVector<BIFF8_REF>      myMergedCells;\r
+\r
+  QStringList             mySSTTable;\r
+  XlsDWORD                myLabelsNum;\r
+\r
+  QVector<BIFF8_BLANK>    myBlankCells;\r
+};\r
+\r
+#pragma pack(pop)\r
+#endif\r
diff --git a/src/Qtx/QtxXlsBorderTool.cxx b/src/Qtx/QtxXlsBorderTool.cxx
new file mode 100755 (executable)
index 0000000..16b9b62
--- /dev/null
@@ -0,0 +1,669 @@
+// Name   : QtxXlsBorderTool.cpp\r
+// Purpose: Implementation of QtxXlsBorderTool class.\r
+//\r
+// History:\r
+// 20/10/11 - Oleg Agashin - Creation of the file\r
+\r
+#include <QtxXlsBorderTool.h>\r
+#include <QtxXlsWriter.h>\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftTopThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                    const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                    const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.leftBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor = theColor;\r
+  aBorder.topBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightTopThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                     const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                     const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.rightBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor = theColor;\r
+  aBorder.topBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor   = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftBottomThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                       const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                       const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.leftBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor    = theColor;\r
+  aBorder.bottomBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightBottomThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                        const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                        const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.rightBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor    = theColor;\r
+  aBorder.bottomBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor   = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftTopThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.leftBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor = theColor;\r
+  aBorder.topBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightTopThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                    const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                    const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.rightBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor = theColor;\r
+  aBorder.topBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor   = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                      const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                      const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.leftBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor    = theColor;\r
+  aBorder.bottomBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                       const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                       const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.rightBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor    = theColor;\r
+  aBorder.bottomBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor   = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                 const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                 const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.leftBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                  const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                  const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.rightBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::TopThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::BottomThick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.bottomBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor   = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.leftBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                 const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                 const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.rightBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::TopThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                               const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                               const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::BottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                  const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                  const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.bottomBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor   = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::Thick( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                             const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                             const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::Thin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                            const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                            const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftTopThickRightBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightTopThickLeftBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftBottomThickRightTopThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightBottomThickLeftTopThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftTopRightThickBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftBottomRightThickTopThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftRightThickTopBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::TopThickLeftBottomRightThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftThickTopBottomRightThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::BottomThickTopLeftRightThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightThickTopLeftBottomThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thin;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thin;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::LeftTopBottomThickRightThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thick;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::RightTopBottomThickLeftThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thick;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+int QtxXlsBorderTool::TopBottomThickLeftRightThin( QtxXlsWriter& theWriter, const XlsWORD theFontID,\r
+                                                   const XlsBYTE theColor, const XlsWORD theFormatID,\r
+                                                   const XlsWORD theAlign, const XlsWORD theVAlign )\r
+{\r
+  QtxXlsBiff::Border aBorder;\r
+  QtxXlsBiff::cleanBorderStruct( aBorder );\r
+\r
+  aBorder.topBorderStyle    = QtxXlsBiff::Thick;\r
+  aBorder.topBorderColor    = theColor;\r
+  aBorder.leftBorderStyle   = QtxXlsBiff::Thin;\r
+  aBorder.leftBorderColor   = theColor;\r
+  aBorder.bottomBorderStyle = QtxXlsBiff::Thick;\r
+  aBorder.bottomBorderColor = theColor;\r
+  aBorder.rightBorderStyle  = QtxXlsBiff::Thin;\r
+  aBorder.rightBorderColor  = theColor;\r
+\r
+  return theWriter.addCellStyle( theFontID, theFormatID,\r
+                              theAlign, theVAlign, &aBorder );\r
+}\r
diff --git a/src/Qtx/QtxXlsBorderTool.h b/src/Qtx/QtxXlsBorderTool.h
new file mode 100755 (executable)
index 0000000..6afeaa0
--- /dev/null
@@ -0,0 +1,253 @@
+// Name   : QtxXlsBorderTool.h\r
+// Purpose: QtxXlsBorderTool is a class for easy creation of cell border styles.\r
+//\r
+// History:\r
+// 20/10/11 - Oleg Agashin - Creation of the file\r
+\r
+#ifndef QTXXLSBORDERTOOL_H_\r
+#define QTXXLSBORDERTOOL_H_\r
+\r
+#include <QtxXlsBiff.h>\r
+\r
+class QtxXlsWriter;\r
+\r
+class QtxXlsBorderTool\r
+{\r
+public:\r
+// Corner styles\r
+  //Thick\r
+  static int LeftTopThick( QtxXlsWriter& theWriter,\r
+                           const XlsWORD theFontID,\r
+                           const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                           const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                           const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                           const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightTopThick( QtxXlsWriter& theWriter,\r
+                            const XlsWORD theFontID,\r
+                            const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                            const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                            const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                            const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftBottomThick( QtxXlsWriter& theWriter,\r
+                              const XlsWORD theFontID,\r
+                              const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                              const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                              const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                              const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightBottomThick( QtxXlsWriter& theWriter,\r
+                               const XlsWORD theFontID,\r
+                               const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                               const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                               const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                               const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  // Thin\r
+  static int LeftTopThin( QtxXlsWriter& theWriter,\r
+                          const XlsWORD theFontID,\r
+                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightTopThin( QtxXlsWriter& theWriter,\r
+                           const XlsWORD theFontID,\r
+                           const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                           const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                           const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                           const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftBottomThin( QtxXlsWriter& theWriter,\r
+                             const XlsWORD theFontID,\r
+                             const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                             const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                             const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                             const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightBottomThin( QtxXlsWriter& theWriter,\r
+                              const XlsWORD theFontID,\r
+                              const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                              const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                              const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                              const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+\r
+// Side styles\r
+  //Thick\r
+  static int LeftThick( QtxXlsWriter& theWriter,\r
+                        const XlsWORD theFontID,\r
+                        const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                        const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                        const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                        const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightThick( QtxXlsWriter& theWriter,\r
+                         const XlsWORD theFontID,\r
+                         const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                         const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                         const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                         const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int TopThick( QtxXlsWriter& theWriter,\r
+                       const XlsWORD theFontID,\r
+                       const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                       const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                       const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                       const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int BottomThick( QtxXlsWriter& theWriter,\r
+                          const XlsWORD theFontID,\r
+                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  //For whole cell border\r
+  static int Thick( QtxXlsWriter& theWriter,\r
+                    const XlsWORD theFontID,\r
+                    const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                    const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                    const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                    const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+\r
+  //Thin\r
+  static int LeftThin( QtxXlsWriter& theWriter,\r
+                       const XlsWORD theFontID,\r
+                       const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                       const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                       const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                       const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightThin( QtxXlsWriter& theWriter,\r
+                        const XlsWORD theFontID,\r
+                        const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                        const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                        const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                        const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int TopThin( QtxXlsWriter& theWriter,\r
+                      const XlsWORD theFontID,\r
+                      const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                      const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                      const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                      const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int BottomThin( QtxXlsWriter& theWriter,\r
+                         const XlsWORD theFontID,\r
+                         const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                         const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                         const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                         const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  //For whole cell border\r
+  static int Thin( QtxXlsWriter& theWriter,\r
+                   const XlsWORD theFontID,\r
+                   const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                   const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                   const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                   const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+// Combine styles\r
+  static int LeftTopThickRightBottomThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightTopThickLeftBottomThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftBottomThickRightTopThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightBottomThickLeftTopThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftTopRightThickBottomThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftBottomRightThickTopThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftRightThickTopBottomThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int TopThickLeftBottomRightThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftThickTopBottomRightThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int BottomThickTopLeftRightThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightThickTopLeftBottomThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int LeftTopBottomThickRightThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int RightTopBottomThickLeftThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+\r
+  static int TopBottomThickLeftRightThin( QtxXlsWriter& theWriter,\r
+                                          const XlsWORD theFontID,\r
+                                          const XlsBYTE theColor = QtxXlsBiff::DefaultForegroundColor,\r
+                                          const XlsWORD theFormatID = QtxXlsBiff::General,\r
+                                          const XlsWORD theAlign = QtxXlsBiff::AlignGeneral,\r
+                                          const XlsWORD theVAlign = QtxXlsBiff::VAlignCenter );\r
+};\r
+\r
+#endif /* QTXXLSBORDERTOOL_H_ */\r
diff --git a/src/Qtx/QtxXlsWriter.cxx b/src/Qtx/QtxXlsWriter.cxx
new file mode 100755 (executable)
index 0000000..34aebf5
--- /dev/null
@@ -0,0 +1,485 @@
+// Name   : QtxXlsWriter.cpp\r
+// Purpose: Implementation of QtxXlsWriter class.\r
+//\r
+// History:\r
+// 11/10/11 - Oleg Agashin - Creation of the file\r
+\r
+#include <QtxXlsWriter.h>\r
+\r
+#include <QFile>\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+QtxXlsWriter::QtxXlsWriter( const QString& theFileName )\r
+: myFileName(theFileName), myWorkbookName("Workbook"),\r
+  myDataSecNum(Dummy), myMSATSecNum(Dummy),\r
+  mySATSecNum(Dummy), myFreeSector(Dummy)\r
+{\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+QtxXlsWriter::~QtxXlsWriter()\r
+{\r
+}\r
+\r
+/**\r
+ * Clear all structures\r
+ */\r
+void QtxXlsWriter::clear()\r
+{\r
+  myData.clear();\r
+  myDataSecNum = Dummy;\r
+  myMSATSecNum = Dummy;\r
+  mySATSecNum  = Dummy;\r
+  myFreeSector = Dummy;\r
+}\r
+\r
+/**\r
+ * Forms header of xls file\r
+ */\r
+QByteArray QtxXlsWriter::formatHeader( const QByteArray& theDataBuffer )\r
+{\r
+  //Data aligned to SectorSize boundary\r
+  XlsDWORD aDataLen = theDataBuffer.length();\r
+\r
+  mySATSecNum  = Dummy;\r
+  XlsDWORD aTotalSSATSecNum = Dummy;\r
+  myMSATSecNum = Dummy;\r
+\r
+  //Are there some data in buffer?\r
+  //if ( aDataLen ) \r
+  //\r
+  //rem: BOF & EOF data are always there and aDataLen >= SectorSize,\r
+  //     nothing to check\r
+\r
+  myDataSecNum = aDataLen / SectorSize; //Total data sectors\r
+\r
+  //If data length below a lower boundary\r
+  if ( aDataLen < MinStreamSize )\r
+  {\r
+    //format SSAT\r
+    aTotalSSATSecNum = 1;\r
+  }\r
+  else\r
+  {\r
+    //format SAT\r
+    mySATSecNum = getSectorsNum( myDataSecNum, totalSecIDinSATSector);\r
+\r
+    //check to add additional MSAT\r
+    if ( mySATSecNum > MinSATSecInMSAT )\r
+    {\r
+      //format MSAT\r
+      myMSATSecNum = getSectorsNum( mySATSecNum - MinSATSecInMSAT, totalSecIDinMSATSector );\r
+    }\r
+  }\r
+\r
+\r
+  XlsHeader aHeader = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1};\r
+\r
+  for( XlsWORD i = 8; i < 76; i++ )\r
+    aHeader.buf[i] = Dummy;\r
+\r
+  aHeader.formatRev = 0x003E;\r
+  aHeader.formatVer = 0x0003;\r
+  aHeader.byteOrder = 0xFFFE;\r
+\r
+  aHeader.sectorSize      = 9;\r
+  aHeader.shortSectorSize = 6;\r
+\r
+  aHeader.minStreamSize   = MinStreamSize;\r
+\r
+  aHeader.totalSATSecs    = mySATSecNum;\r
+  aHeader.totalSSATSecs   = aTotalSSATSecNum;\r
+  aHeader.totalMSATSecs   = myMSATSecNum;\r
+\r
+  myFreeSector = myDataSecNum;\r
+\r
+  fillFirstSectorID( myMSATSecNum,     aHeader.firstMSATSecID, myFreeSector );\r
+  fillFirstSectorID( aTotalSSATSecNum, aHeader.firstSSATSecID, myFreeSector );\r
+  aHeader.firstDirSecID = myFreeSector++;\r
+\r
+  XlsWORD anIndex = 76;\r
+\r
+  XlsWORD aBound = mySATSecNum;\r
+  if ( myMSATSecNum )\r
+  {\r
+    aBound = MinSATSecInMSAT;\r
+  }\r
+\r
+  for( XlsWORD i = 0; i < aBound; i++)\r
+  {\r
+    *(reinterpret_cast<XlsDWORD*>(&aHeader.buf[anIndex])) = myFreeSector++;\r
+\r
+    anIndex += SizeOfDWORD;\r
+  }\r
+  \r
+  //If we have a reminder\r
+  for(; anIndex < SectorSize; anIndex++)\r
+    aHeader.buf[anIndex] = Free_SecID;\r
+\r
+  return BYTE_ARRAY( aHeader.buf, SectorSize );\r
+}\r
+\r
+/**\r
+ * Calculates first sector ID for some structure block\r
+ */\r
+void QtxXlsWriter::fillFirstSectorID( const XlsDWORD theTotalSecNum,\r
+                                      XlsDWORD& theFirstSectorID,\r
+                                      XlsDWORD& theFreeSector )\r
+{\r
+  if ( theTotalSecNum )\r
+  {\r
+    theFirstSectorID = theFreeSector;\r
+    theFreeSector += theTotalSecNum;\r
+  }\r
+  else\r
+    theFirstSectorID = EndOfChain_SecID;\r
+}\r
+\r
+/**\r
+ * Update directory structure by default values\r
+ */\r
+void QtxXlsWriter::clearDirStructure( DirEntityStructure& theStruct )\r
+{\r
+  for( XlsWORD i = 0; i < DirEntrySize; i++ )\r
+    theStruct.buf[i] = Dummy;\r
+\r
+  theStruct.leftChildDirID  = Free_SecID;\r
+  theStruct.rightChildDirID = Free_SecID;\r
+  theStruct.rootDirID       = Free_SecID;\r
+}\r
+\r
+/**\r
+ * Adds user-defined font \r
+ */\r
+int QtxXlsWriter::addFont( const QString& theFontName,\r
+                           const XlsWORD theFontSize,\r
+                           const bool theIsBold,\r
+                           const XlsWORD theFontColor,\r
+                           const XlsWORD theFontStyle,\r
+                           const XlsWORD theSuperSubscriptType,\r
+                           const XlsWORD theUnderlineType )\r
+{\r
+  return myData.addFont( theFontName, theFontSize, theIsBold,\r
+                         theFontColor, theFontStyle,\r
+                         theSuperSubscriptType,\r
+                         theUnderlineType );\r
+}\r
+\r
+/**\r
+ * Adds user-defined format \r
+ */\r
+int QtxXlsWriter::addCellStyle( const XlsWORD theFontID,\r
+                                const XlsWORD theFormatID,\r
+                                const XlsWORD theAlign,\r
+                                const XlsWORD theVAlign,\r
+                                const QtxXlsBiff::Border* theBorders,\r
+                                const bool    theIsWrapped,\r
+                                const bool    theIsMerged,\r
+                                const XlsWORD theRotation,\r
+                                const XlsBYTE theForegrountColorID,\r
+                                const XlsBYTE theBackgrountColorID/*,\r
+                                const XlsWORD theParentStyleID*/ )\r
+{\r
+  return myData.addCellStyle( theFontID, theFormatID, theAlign,\r
+                           theVAlign, theBorders, theIsWrapped, theIsMerged,\r
+                           theRotation, theForegrountColorID, theBackgrountColorID );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsWriter::SetWorkbookName( const QString& theName )\r
+{\r
+  if( !theName.isEmpty() )\r
+    myWorkbookName = theName;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsWriter::SetSheetName( const QString& theName )\r
+{\r
+  myData.SetSheetName( theName );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsWriter::SetFileName( const QString& theName )\r
+{\r
+  if( !theName.isEmpty() )\r
+    myFileName = theName;\r
+}\r
+\r
+/**\r
+ * Stores the file\r
+ */\r
+bool QtxXlsWriter::upload()\r
+{\r
+  QFile aFile( myFileName );\r
+  if ( !aFile.open( QFile::WriteOnly ) )\r
+    return false;\r
+\r
+  QByteArray aDataBuffer( myData.getBiffData() );\r
+  fillData( aDataBuffer );\r
+\r
+  //counting data sectors\r
+\r
+  QByteArray aByteArray = formatHeader( aDataBuffer );\r
+  aFile.write( aByteArray );\r
+\r
+  aFile.write( aDataBuffer );\r
+  \r
+  aByteArray = formatMSAT();\r
+  aFile.write( aByteArray );\r
+\r
+  aByteArray = formatDirectoryEntry( aDataBuffer.length() );\r
+  aFile.write( aByteArray );\r
+\r
+  aByteArray = formatSAT();\r
+  aFile.write( aByteArray );\r
+\r
+  aFile.close();\r
+\r
+  return true;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsWriter::fillData( QByteArray& theDataBuffer )\r
+{\r
+  alignData( theDataBuffer, Dummy );\r
+\r
+  //Workaround of short-stream containers\r
+  while( theDataBuffer.length() < MinStreamSize )\r
+    theDataBuffer.append( Dummy );\r
+}\r
+\r
+/**\r
+ * Aligns data to SectorSize boundary\r
+ * by inserting Dummy data\r
+ */\r
+void QtxXlsWriter::alignData( QByteArray& theBuffer,\r
+                              XlsDWORD theFiller,\r
+                              QtxXlsWriter::AlignType theAlignType )\r
+{\r
+  int aPackLen = SectorSize - (theBuffer.length() % SectorSize);\r
+  if ( aPackLen != SectorSize )\r
+  {\r
+    for( int i = 0; i < aPackLen; )\r
+    {\r
+      switch ( theAlignType )\r
+      {\r
+      case Byte:\r
+        theBuffer.append( theFiller );\r
+        i++;\r
+        break;\r
+      \r
+      case Dword:\r
+        xlsDWORDExcange anExchanger;\r
+\r
+        anExchanger.value = theFiller;\r
+        theBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+        i += SizeOfDWORD;\r
+        break;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+ * Returns exact number of sectors that can storing all data\r
+ */\r
+XlsDWORD QtxXlsWriter::getSectorsNum( const XlsDWORD theDividend, const XlsDWORD theDivisor )\r
+{\r
+  XlsDWORD aSecNum = theDividend / theDivisor;\r
+  if ( theDividend % theDivisor )\r
+    ++aSecNum;\r
+  return aSecNum;\r
+}\r
+\r
+/**\r
+ * Fills the SAT sectors by reference data sectors IDs\r
+ */\r
+QByteArray QtxXlsWriter::formatSAT()\r
+{\r
+  QByteArray aBuffer;\r
+  xlsDWORDExcange anExchanger;\r
+  XlsDWORD aPenultimate = myDataSecNum - 1;\r
+\r
+  //Fill data chain\r
+  for( XlsDWORD anIndex = 0; anIndex < myDataSecNum; anIndex++)\r
+  {\r
+    if ( anIndex == aPenultimate )\r
+      anExchanger.value = EndOfChain_SecID;\r
+    else\r
+      anExchanger.value = anIndex + 1;\r
+\r
+    aBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+  }\r
+\r
+  //Fill MSAT used sectors\r
+  for( XlsDWORD anIndex = 0; anIndex < myMSATSecNum; anIndex++)\r
+  {\r
+    anExchanger.value = MSAT_SecID;\r
+    aBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+  }\r
+\r
+  //Fill SSAT\r
+\r
+  //Fill Dir - only one sector\r
+  anExchanger.value = EndOfChain_SecID;\r
+  aBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+\r
+  //Fill SAT used sectors\r
+  for( XlsDWORD anIndex = 0; anIndex < mySATSecNum; anIndex++)\r
+  {\r
+    anExchanger.value = SAT_SecID;\r
+    aBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+  }\r
+\r
+  alignData( aBuffer, Free_SecID, Dword );\r
+\r
+  return aBuffer;\r
+}\r
+\r
+/**\r
+ * Fills the MSAT sectors by reference SAT sectors IDs\r
+ */\r
+QByteArray QtxXlsWriter::formatMSAT()\r
+{\r
+  QByteArray aBuffer;\r
+\r
+  if ( !myMSATSecNum )\r
+  {\r
+    return aBuffer;\r
+  }\r
+\r
+  xlsDWORDExcange anExchanger;\r
+  XlsDWORD aRemSATSectors = mySATSecNum - MinSATSecInMSAT;\r
+  XlsDWORD aNextMSATSec   = myDataSecNum + 1;\r
+\r
+  for( XlsDWORD anIndex = 1; anIndex <= aRemSATSectors; anIndex++)\r
+  {\r
+    if ( !( anIndex % totalSecIDinSATSector ) )\r
+    {\r
+      anExchanger.value = aNextMSATSec++;\r
+      aBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+    }\r
+\r
+    anExchanger.value = myFreeSector++;\r
+    aBuffer.append( DWORD_BYTE_ARRAY(anExchanger.buf) );\r
+  }\r
+\r
+  alignData( aBuffer, Free_SecID, Dword );\r
+\r
+  return aBuffer;\r
+}\r
+\r
+/**\r
+ * Fills entry point for workbook\r
+ */\r
+QByteArray QtxXlsWriter::formatDirectoryEntry( const XlsDWORD theDataLen )\r
+{\r
+  QString aName;\r
+  QByteArray aBuffer;\r
+  DirEntityStructure anEntity;\r
+\r
+  clearDirStructure( anEntity );\r
+\r
+  aName = "Root Entry";\r
+  \r
+  XlsDWORD aStrLen = aName.length();\r
+  for ( XlsDWORD i = 0; i < aStrLen ; i++ )\r
+    anEntity.entryNameUnicode[i] = aName[i].unicode();\r
+\r
+  anEntity.nameLenInBytes  = (aStrLen + 1) << 1;\r
+  anEntity.entityType      = Root;\r
+  anEntity.nodeColour      = Black; //Red;\r
+  anEntity.rootDirID       = 1; //only one stream, this points to next dir entry\r
+  anEntity.firstSecID      = EndOfChain_SecID;\r
+  anEntity.totalStreamSize = Dummy;\r
+\r
+  anEntity.UID[0] = 0x00020820;\r
+  anEntity.UID[1] = 0x00000000;\r
+  anEntity.UID[2] = 0x000000C0;\r
+  anEntity.UID[3] = 0x46000000;\r
+\r
+  //Add root entry to buffer\r
+  aBuffer.append( BYTE_ARRAY(anEntity.buf, DirEntrySize) );\r
+\r
+\r
+  clearDirStructure( anEntity );\r
+  \r
+  aStrLen = myWorkbookName.length();\r
+  if ( aStrLen > MaxDirNameLen )\r
+  {\r
+    myWorkbookName.truncate( MaxDirNameLen );\r
+    aStrLen = MaxDirNameLen;\r
+  }\r
+\r
+  for ( XlsDWORD i = 0; i < aStrLen ; i++ )\r
+    anEntity.entryNameUnicode[i] = myWorkbookName[i].unicode();\r
+\r
+  anEntity.nameLenInBytes  = (aStrLen + 1) << 1;\r
+  anEntity.entityType      = UserStream;\r
+  anEntity.nodeColour      = Black;\r
+  anEntity.firstSecID      = 0;\r
+  anEntity.totalStreamSize = theDataLen;\r
+\r
+  //Add root entry to buffer\r
+  aBuffer.append( BYTE_ARRAY(anEntity.buf, DirEntrySize) );\r
+\r
+  alignData( aBuffer, Dummy );\r
+\r
+  return aBuffer;\r
+}\r
+\r
+/**\r
+ * Adds string value\r
+ */\r
+void QtxXlsWriter::addData( const QString& theData, const XlsWORD theRow,\r
+                            const XlsWORD theCol, const XlsWORD theStyleID )\r
+{\r
+       bool aIsDouble = false;\r
+       double aDouble = theData.toDouble( &aIsDouble );\r
+       if ( aIsDouble )\r
+               myData.addData( aDouble, theRow, theCol, theStyleID );\r
+       else\r
+               myData.addData( theData, theRow, theCol, theStyleID );\r
+\r
+}\r
+\r
+/**\r
+ * Adds double value\r
+ */\r
+void QtxXlsWriter::addData( const double theData, const XlsWORD theRow,\r
+                            const XlsWORD theCol, const XlsWORD theStyleID )\r
+{\r
+  myData.addData( theData, theRow, theCol, theStyleID );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsWriter::setColWidth( const XlsWORD theMaxLen, const XlsWORD theFromCol,\r
+                                const XlsWORD theToCol, const XlsWORD theStyleID )\r
+{\r
+  myData.setColWidth( theMaxLen + 1, theFromCol,\r
+                      theToCol, theStyleID );\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void QtxXlsWriter::mergeCells( const XlsWORD theFirstRow, const XlsWORD theLastRow,\r
+                               const XlsWORD theFirstCol, const XlsWORD theLastCol )\r
+{\r
+  myData.mergeCells( theFirstRow, theLastRow, theFirstCol, theLastCol );\r
+}\r
diff --git a/src/Qtx/QtxXlsWriter.h b/src/Qtx/QtxXlsWriter.h
new file mode 100755 (executable)
index 0000000..6f63875
--- /dev/null
@@ -0,0 +1,188 @@
+// Name   : QtxXlsWriter.h\r
+// Purpose: QtxXlsWriter is a class for storing data to *.XLS file.\r
+//          General behaviour - creating a low-level storage format\r
+//          for *.XLS file.\r
+//\r
+// History:\r
+// 11/10/11 - Oleg Agashin - Creation of the file\r
+\r
+#ifndef QTXXLSWRITER_HEADER\r
+#define QTXXLSWRITER_HEADER\r
+\r
+#include <QtxXlsBiff.h>\r
+\r
+#include <QString>\r
+#include <QByteArray>\r
+\r
+\r
+#pragma pack(push,1)\r
+/*\r
+ * Class for exporting data to *.XLS file\r
+ * Uses only one data stream\r
+ *\r
+ * *.XLS file structure:\r
+ * +------------------------+\r
+ * |        Header          |\r
+ * +------------------------+\r
+ * |         DATA           |\r
+ * +------------------------+\r
+ * | MSAT or Nothing if     |\r
+ * | number of SAT sectors  |\r
+ * | lower than 109         |\r
+ * +------------------------+\r
+ * | SSAT or Nothing if     |\r
+ * | length of data stream  |\r
+ * | greater than minimum   |\r
+ * | value                  |\r
+ * +------------------------+\r
+ * |    Directory Entry     |\r
+ * |       Structure        |\r
+ * +------------------------+\r
+ * | SAT or Nothing if      |\r
+ * | length of data stream  |\r
+ * | lower than minimum     |\r
+ * | value                  |\r
+ * +------------------------+\r
+ */\r
+class QtxXlsWriter\r
+{\r
+  //-------------- File structure types ------------------------\r
+  enum SectorType { Free_SecID = -1, EndOfChain_SecID = -2,\r
+                    SAT_SecID  = -3, MSAT_SecID       = -4,\r
+                    Dummy      =  0};\r
+\r
+  enum EntryType { Empty = 0, UserStorage, UserStream,\r
+                   LockBytes, Property,    Root};\r
+\r
+  enum NodeColour { Red = 0, Black };\r
+\r
+  enum Constants { SectorSize = 512, MinStreamSize = 4096,\r
+                   DirEntrySize = 128, MinSATSecInMSAT = 109,\r
+                   MaxDirNameLen = 32,\r
+                   SizeOfDWORD = sizeof(XlsDWORD),\r
+                   totalSecIDinSATSector  = SectorSize/SizeOfDWORD,\r
+                   totalSecIDinMSATSector = totalSecIDinSATSector-1 };\r
+\r
+  enum AlignType { Byte, Dword };\r
+\r
+  //Xls header structure\r
+  union XlsHeader\r
+  {\r
+    XlsBYTE buf[SectorSize];\r
+    struct\r
+    {\r
+      XlsBYTE  fileID[8];\r
+      XlsBYTE  UID[16];\r
+      XlsWORD  formatRev;\r
+      XlsWORD  formatVer;\r
+      XlsWORD  byteOrder;\r
+      XlsWORD  sectorSize;\r
+      XlsWORD  shortSectorSize;\r
+      XlsBYTE  notUsed10[10];\r
+      XlsDWORD totalSATSecs;\r
+      XlsDWORD firstDirSecID;\r
+      XlsDWORD notUsed;\r
+      XlsDWORD minStreamSize;\r
+      XlsDWORD firstSSATSecID;\r
+      XlsDWORD totalSSATSecs;\r
+      XlsDWORD firstMSATSecID;\r
+      XlsDWORD totalMSATSecs;\r
+      XlsBYTE  MSAT[436];\r
+    };\r
+  };\r
+\r
+  //Directiry entity structure\r
+  union DirEntityStructure\r
+  {\r
+    XlsBYTE buf[DirEntrySize];\r
+    struct\r
+    {\r
+      XlsWORD  entryNameUnicode[32];\r
+      XlsWORD  nameLenInBytes;\r
+      XlsBYTE  entityType;\r
+      XlsBYTE  nodeColour;\r
+      XlsDWORD leftChildDirID;\r
+      XlsDWORD rightChildDirID;\r
+      XlsDWORD rootDirID;\r
+      XlsDWORD UID[4];\r
+      XlsDWORD userFlags;\r
+      XlsDWORD timeStampCreation[2];\r
+      XlsDWORD timeStampModification[2];\r
+      XlsDWORD firstSecID;\r
+      XlsDWORD totalStreamSize;\r
+      XlsDWORD notUsed;\r
+    };\r
+  };\r
+  //-------------- end of File structure types -----------------\r
+\r
+public:\r
+  QtxXlsWriter( const QString& );\r
+  virtual ~QtxXlsWriter();\r
+\r
+public:\r
+  void addData( const QString& theData, const XlsWORD theRow,\r
+                const XlsWORD theCol, const XlsWORD theStyleID );\r
+  void addData( const double theData, const XlsWORD theRow,\r
+                const XlsWORD theCol, const XlsWORD theStyleID );\r
+\r
+  bool upload();\r
+  void clear();\r
+\r
+  void SetWorkbookName( const QString& theName );\r
+  void SetSheetName( const QString& theName );\r
+  void SetFileName( const QString& theName );\r
+\r
+  void setColWidth( const XlsWORD theMaxLen, const XlsWORD theFromCol,\r
+                    const XlsWORD theToCol, const XlsWORD theStyleID );\r
+\r
+  void mergeCells( const XlsWORD theFirstRow, const XlsWORD theLastRow,\r
+                   const XlsWORD theFirstCol, const XlsWORD theLastCol );\r
+\r
+  int addFont(   const QString& theFontName,\r
+                 const XlsWORD theFontSize,\r
+                 const bool theIsBold = false,\r
+                 const XlsWORD theFontColor = QtxXlsBiff::Black,\r
+                 const XlsWORD theFontStyle = QtxXlsBiff::None,\r
+                 const XlsWORD theSuperSubscriptType = QtxXlsBiff::None,\r
+                 const XlsWORD theUnderlineType = QtxXlsBiff::None );\r
+\r
+  int addCellStyle( const XlsWORD theFontID,\r
+                    const XlsWORD theFormatID,\r
+                    const XlsWORD theAlign,\r
+                    const XlsWORD theVAlign,\r
+                    const QtxXlsBiff::Border* theBorders = 0,\r
+                    const bool    theIsWrapped = false,\r
+                    const bool    theIsMerged = false,\r
+                    const XlsWORD theRotation = QtxXlsBiff::None,\r
+                    const XlsBYTE theForegrountColorID = QtxXlsBiff::DefaultForegroundColor,\r
+                    const XlsBYTE theBackgrountColorID = QtxXlsBiff::DefaultBackgroundColor );\r
+\r
+private:\r
+  QByteArray formatHeader( const QByteArray& theDataBuffer );\r
+  QByteArray formatSAT();\r
+  QByteArray formatMSAT();\r
+  QByteArray formatDirectoryEntry( const XlsDWORD theDataLen );\r
+\r
+  void clearDirStructure( DirEntityStructure& theStruct );\r
+  void alignData( QByteArray& theBuffer, XlsDWORD theFiller, AlignType theAlignType = Byte);\r
+  void fillData( QByteArray& );\r
+  XlsDWORD getSectorsNum( const XlsDWORD theDividend, const XlsDWORD theDivisor );\r
+  void fillFirstSectorID( const XlsDWORD theTotalSecNum,\r
+                          XlsDWORD& theFirstSectorID,\r
+                          XlsDWORD& theFreeSector );\r
+\r
+private:\r
+  QString    myFileName;\r
+  QString    myWorkbookName;\r
+\r
+  QtxXlsBiff myData;\r
+\r
+  XlsDWORD   myDataSecNum;\r
+  XlsDWORD   myMSATSecNum;\r
+  XlsDWORD   mySATSecNum;\r
+\r
+  XlsDWORD   myFreeSector;\r
+};\r
+\r
+#pragma pack(pop)\r
+#endif\r