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

📄 main.cpp

📁 xls文件格式分析基础库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2004-2006 Yeico S. A. de C. V. * Copyright (C) 2007 David Hoerl * * $Source: /cvsroot/xlslib/xlslib/targets/test/main.cpp,v $ * $Revision: 1.1.1.1 $ * $Author: darioglz $ * $Date: 2004/08/27 16:32:05 $ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * File description: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */#include <config.h>#include "systype.h"//#include <stream>#include <sstream>#include <iostream>//#include <tostr.h>#include <string>#include <sstream>#include <iostream>#include <stdio.h>#include <workbook.h>#include <timespan.h>using namespace std;using namespace xlslib_core;#define __REPORT_TIME__#define OPT_HALIGN        0#define OPT_VALIGN        1#define OPT_ORIENTATION   2#define OPT_FILLFGCOLOR   3#define OPT_FILLBGCOLOR   4#define OPT_FILLSTYLE     5#define OPT_LOCKED        6#define OPT_HIDDEN        7#define OPT_WRAP          8#define OPT_BORDERSTYLE   9#define OPT_MAX           9#define OPT_FONTHEIGHT      0 #define OPT_FONTBOLD        1 #define OPT_FONTUNDERLINE   2 #define OPT_FONTSCRIPT      3 #define OPT_FONTCOLOR       4 #define OPT_FONTITALIC      5 #define OPT_FONTSTRIKEOUT   6 #define OPT_FONTOUTLINE     7 #define OPT_FONTSHADOW      8 #define OPT_FONTMAX         8// Macros#define TIMESPAN_START(id)                      \   CCpuClockTimespan span_##id;                 \   span_##id.StartClock();#define TIMESPAN_END(id,str)                                      \   span_##id.StopClock();                                         \   cout<<#str<<" "<<span_##id.GetUsedMilliseconds()<<" ms"<<endl;using namespace std;extern void StressTest(int a,int b,int c);extern void RandomTest(int a,int b,int c);extern void RandomCellAndFormatTest(int sheets_sz, int rows_sz, int cols_sz);extern void RandomFormat(cell_t* cell, bool profile = false);extern void RandomFontName(cell_t* cell, bool profile = false);extern void RandomFontOption(cell_t* cell, bool profile = false);extern void RandomFormatTest(int sheets_sz, int rows_sz, int cols_sz);extern void RandomCellAndFormatTestProf(int sheets_sz, int rows_sz, int cols_sz);extern void StandardTest(void);extern int GetRndNumber(int max);/******************************************************************* */static char tmp[256];int main(int argc, char *argv[]){/*   workbook wb;   wb.sheet("Sheet_01");   wb.Dump("blank.xls");*/	// comment and uncomment the below to try various tests	StandardTest();	//StressTest(3,100,100);	//StressTest(3,4,4);	//RandomTest(3,100,100);	//RandomCellAndFormatTest(1,15,10); //(1,15,10)	//RandomCellAndFormatTestProf(1,15,10);	//RandomFormatTest(1,15,10);	return 0;}void StandardTest(void){   // Get the workbook handler   workbook wb;   worksheet* sh = wb.sheet("sheet");// Title   sh->label(1,1,"test");   sh->rowheight(1,100);   sh->rowheight(2,150);   sh->label(2,1,"test");   wb.Dump("./test.xls");      }int GetRndNumber(int max){   int rndnum;   rndnum = ((int)(rand()*((double)(max+1)/RAND_MAX)));   return rndnum;}void RandomCellAndFormatTest(int sheets_sz, int rows_sz, int cols_sz){   workbook wb;   worksheet* sh;   srand(time(0));   TIMESPAN_START(1)   for(int shnum = 0; shnum < sheets_sz; shnum++)   {	  sprintf(tmp, "DUH_%d", shnum);	  string snamesheet(tmp);      sh = wb.sheet(snamesheet);      for(int row = 0; row<rows_sz; row++)      {         sh->rowheight(row,GetRndNumber(10)+15);         for(int col = 0; col<cols_sz; col++)         {            sh->colwidth(row,GetRndNumber(10)+15);            int rndcol = GetRndNumber(rows_sz);            int rndrow = GetRndNumber(cols_sz);			sprintf(tmp, "S%d:%d-%d", shnum, row+1, col+1);			string snamelabel(tmp);            cell_t* cell = sh->label(rndrow, rndcol, snamelabel);            int k, fmtries = GetRndNumber(OPT_MAX);            for(k = 0; k<fmtries; k++)               RandomFormat(cell);            fmtries = GetRndNumber(OPT_FONTMAX);            for(k = 0; k<fmtries; k++)               RandomFontOption(cell);            RandomFontName(cell);         }      }   }   wb.Dump("rndcellandformat.xls");   TIMESPAN_END(1,Random Cell and Format test:)      }void RandomCellAndFormatTestProf(int sheets_sz, int rows_sz, int cols_sz){   workbook wb;   worksheet* sh;   for(int shnum = 0; shnum < sheets_sz; shnum++)   {	  sprintf(tmp, "DUH_%d", shnum);	  string snamesheet(tmp);      sh = wb.sheet(snamesheet);      for(int row = 0; row<rows_sz; row++)      {         sh->rowheight(row,GetRndNumber(10)+15);         for(int col = 0; col<cols_sz; col++)         {            sh->colwidth(row,GetRndNumber(10)+15);            int rndcol = GetRndNumber(rows_sz);            int rndrow = GetRndNumber(cols_sz);			sprintf(tmp, "S%d:%d-%d", shnum, row+1, col+1);			string snamelabel(tmp);            cell_t* cell = sh->label(rndrow, rndcol, snamelabel);            cout<<"CELL ";            cout.fill('0');            cout.width(2);            cout<<rndrow<<",";            cout.fill('0');            cout.width(2);            cout<<rndcol<<": ";            int k, fmtries = GetRndNumber(OPT_MAX);            cout<<endl<<"**FORMAT** ";            for(k = 0; k<fmtries; k++)               RandomFormat(cell,true);            cout<<endl<<"**FONT**   ";            fmtries = GetRndNumber(OPT_FONTMAX);            for(k = 0; k<fmtries; k++)               RandomFontOption(cell,true);            RandomFontName(cell,true);            cout<<endl;         }      }   }   wb.Dump("rndcellandformat.xls");}void RandomFormatTest(int sheets_sz, int rows_sz, int cols_sz){   srand(time(0));   TIMESPAN_START(1)      workbook wb;   worksheet* sh;   for(int shnum = 0; shnum < sheets_sz; shnum++)   {	  sprintf(tmp, "DUH_%d", shnum);	  string snamesheet(tmp);      sh = wb.sheet(snamesheet);      for(int row = 0; row<rows_sz; row++)      {         sh->rowheight(row,GetRndNumber(10)+15);         for(int col = 0; col<cols_sz; col++)         {            sh->colwidth(row,GetRndNumber(10)+15);			sprintf(tmp, "S%d:%d-%d", shnum, row+1, col+1);			string snamelabel(tmp);            cell_t* cell = sh->label(row, col, snamelabel);            int k, fmtries = GetRndNumber(OPT_MAX);            for(k = 0; k<fmtries; k++)               RandomFormat(cell);            fmtries = GetRndNumber(OPT_FONTMAX);            for(k = 0; k<fmtries; k++)               RandomFontOption(cell);            RandomFontName(cell);         }      }   }   wb.Dump("rndformat.xls");   TIMESPAN_END(1,Random Format test:)      }#define OPT_FNTNAME_ARIAL             0#define OPT_FNTNAME_TIMES             1#define OPT_FNTNAME_TAHOMA            2#define OPT_FNTNAME_ARIALBLACK        3#define OPT_FNTNAME_CENTURYGOTHIC     4#define OPT_FNTNAME_COMICSANSMS       5#define OPT_FNTNAME_COURIER           6#define OPT_FNTNAME_COURIERNEW        7#define OPT_FNTNAME_FIXEDSYS          8#define OPT_FNTNAME_GARAMOND          9#define OPT_FNTNAME_IMPACT            10#define OPT_FNTNAME_LUCIDACONSOLE     11#define OPT_FNTNAME_MONOTYPECORSIVA   12#define OPT_FNTNAME_SYMBOL            13#define OPT_FNTNAME_WEBDINGS          14#define OPT_FNTNAME_WINGDINGS         15#define OPT_FNTNAME_MAX               15void RandomFontName(cell_t* cell, bool profile){   switch(GetRndNumber(OPT_FNTNAME_MAX))   {      case OPT_FNTNAME_ARIAL:         cell->fontname("Arial");         if(profile) cout<<"Arial Font, ";         break;      case OPT_FNTNAME_TIMES:         cell->fontname("Times New Roman");         if(profile) cout<<"Times New Roman Font, ";         break;      case OPT_FNTNAME_TAHOMA:         cell->fontname("Tahoma");         if(profile) cout<<"Tahoma Font, ";         break;      case OPT_FNTNAME_ARIALBLACK:         cell->fontname("Arial Black");         if(profile) cout<<"Arial Black Font, ";         break;      case OPT_FNTNAME_CENTURYGOTHIC:         cell->fontname("Century Gothic");         if(profile) cout<<"Century Gothic Font, ";         break;      case OPT_FNTNAME_COMICSANSMS:         cell->fontname("Comic Sans MS");         if(profile) cout<<"Comic Sans MS Font, ";         break;      case OPT_FNTNAME_COURIER:         cell->fontname("Courier");         if(profile) cout<<"Courier Font, ";         break;      case OPT_FNTNAME_COURIERNEW:         cell->fontname("Courier New");         if(profile) cout<<"Courier New Font, ";         break;      case OPT_FNTNAME_FIXEDSYS:         cell->fontname("Fixedsys");         if(profile) cout<<"Fixedsys Font, ";         break;      case OPT_FNTNAME_GARAMOND:         cell->fontname("Garamond");         if(profile) cout<<"Garamond Font, ";         break;      case OPT_FNTNAME_IMPACT:         cell->fontname("Impact");         if(profile) cout<<"Impact Font, ";         break;      case OPT_FNTNAME_LUCIDACONSOLE:         cell->fontname("Lucida Console");         if(profile) cout<<"Lucida Console Font, ";         break;      case OPT_FNTNAME_MONOTYPECORSIVA:         cell->fontname("Monotype Corsiva");         if(profile) cout<<"Monotype Corsiva Font, ";         break;      case OPT_FNTNAME_SYMBOL:         cell->fontname("Symbol");         if(profile) cout<<"Symbol Font, ";         break;      case OPT_FNTNAME_WEBDINGS:         cell->fontname("Webdings");         if(profile) cout<<"Webdings Font, ";         break;      case OPT_FNTNAME_WINGDINGS:         cell->fontname("Wingdings");         if(profile) cout<<"Wingdings Font, ";         break;   }}string BOLD[] = {   "BOLD",   "HALF ",   "NORMAL",   "DOUBLE"};string SCRIPT[] = {   "NONE",   "SUPER ",   "SUB"};string UNDERLINE[] = {   "NONE",   "SINGLE ",   "DOUBLE",   "SINGLEACC",   "DOUBLEACC"};string COLOR[] = {   "BLACK",   "DARK_RED",   "RED",   "FUCSIA",   "COMBINED01",   "COMBINED02",   "COMBINED03",   "COMBINED04",   "COMBINED05",   "COMBINED06",   "OLIVE",   "DARK_YELLOW",   "COMBINED07",   "YELLOW",   "LIGHT_YELLOW",   "DARK_GREEN",   "GREEN",   "COMBINED08",   "LIVING_GREEN",   "LIGHT_GREEN",   "COMBINED09",   "BLUE_GREEN",   "AQUAMARINA",   "TURQOISE",   "COMBINED10",   "DARK_BLUE",   "BLUE",   "LIGHT_BLUE",   "SKY_BLUE",   "COMBINED11",   "INDIGO",   "BLUE_GRAY",   "VIOLET",   "PLUM",   "LAVANDER",   "COMBINED12",   "GRAY50",   "GRAY40",   "GRAY25",   "WHITE"};void RandomFontOption(cell_t* cell, bool profile){   switch(GetRndNumber(OPT_FONTMAX))   {      case OPT_FONTHEIGHT:      {         unsigned16_t height = (unsigned16_t)GetRndNumber(20*40);         cell->fontheight(height);         if(profile) cout<<"Height "<<height<<", ";         break;      }      case OPT_FONTBOLD:      {         int bold = GetRndNumber((int)BOLDNESS_DOUBLE);         cell->fontbold((boldness_option_t)bold);         if(profile) cout<<"Bold "<<BOLD[bold]<<", ";                  break;

⌨️ 快捷键说明

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