Changeset 2048518 in tol
- Timestamp:
- Aug 18, 2010, 12:32:01 PM (16 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 7d960bd
- Parents:
- 7d97465
- Location:
- tol/contrib/excel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/contrib/excel/Jamfile
r7d97465 r2048518 5 5 exe test01 : test01.cpp ExcelFormat.cpp BasicExcel.cpp ; 6 6 7 explicit test01 ; 7 exe test02 : test02.cpp ; 8 9 explicit test01 test02 ; -
tol/contrib/excel/test.tol
r7d97465 r2048518 41 41 [[ cell_05_01, cell_05_02 ]] ]], "Std" ) 42 42 }; 43 44 WriteLn( "Lectura de rango ..." ); 45 Set { 46 Set range1 = Excel.ReadRange( id, "A1", "B5" ); 47 Set View( range1, "Std" ) 48 }; 43 49 44 50 Real status = Excel.Destroy( id ); -
tol/contrib/excel/tolExcel.cpp
r7d97465 r2048518 34 34 #include <tol/tol_btxtgra.h> 35 35 #include <tol/tol_bspfun.h> 36 #include <tol/tol_bsetgra.h> 36 37 37 38 class TolExcel { … … 202 203 return nHour / nHiD + nMinute / nMiD + nSecond / nSiD; 203 204 } 205 206 static size_t decodeColumn( char * cellName, size_t length ); 207 static bool decodeCoordinates( char * cellName, 208 size_t &row, size_t &column ); 209 static bool getCellCoordinates( const BText & name, 210 BSyntaxObject *cell, 211 size_t &row, size_t &column ); 204 212 205 213 protected: … … 243 251 BasicExcelWorksheet *m_ptrActiveWS; 244 252 }; 253 254 size_t TolExcel::decodeColumn( char * cellName, size_t length ) 255 { 256 if ( !length ) return 0; 257 char c = cellName[ --length ]; 258 if ( c < 'A' || c > 'Z') 259 return 0; 260 return (c - 'A' + 1) + TolExcel::decodeColumn( cellName, length ) * 26; 261 } 262 263 bool TolExcel::decodeCoordinates( char * cellName, size_t &row, size_t &column ) 264 { 265 size_t i = 0; 266 267 // decode column A-based 268 char ch = cellName[ i ]; 269 while ( ch >= 'A' && ch <= 'Z' ) { ch = cellName[ ++i ]; } 270 column = TolExcel::decodeColumn( cellName, i ); 271 if ( !column ) { 272 return false; 273 } 274 // decode row 1-based 275 row = 0; 276 while ( ch >= '1' && ch <= '9' ) { 277 row = row * 10 + ch - '0'; 278 ch = cellName[ ++i ]; 279 } 280 if ( !row ) { 281 return false; 282 } 283 // cell coordinates are 0-based internally 284 --row; 285 --column; 286 return true; 287 } 288 289 bool TolExcel::getCellCoordinates( const BText & name, BSyntaxObject *cell, 290 size_t &row, size_t &column ) 291 { 292 bool status; 293 294 if ( cell->Grammar() == GraText() ) { 295 BText & cellName = Text( cell ); 296 297 status = TolExcel::decodeCoordinates( cellName.Buffer(), 298 row, column ); 299 if ( !status ) { 300 Error( name + ": " + 301 I2( "invalid cell coordinates ", 302 "coordenadas de celda invalidas " ) + cellName ); 303 } 304 } else if ( cell->Grammar() == GraSet() ) { 305 BSet &_cell = Set( cell ); 306 if ( _cell.Card() != 2 ) { 307 Error( name + ": " + 308 I2( "invalid cell coordinates, must be a Set of two numbers ", 309 " coordenadas de celda invalidas, debe ser un conjunto de 2 " 310 "numeros" ) ); 311 status = false; 312 } else { 313 BDat &datRow = Dat( _cell[1] ); 314 BDat &datCol = Dat( _cell[2] ); 315 if ( !datRow.IsKnown() || datRow.Value() < 1 || 316 !datCol.IsKnown() || datCol.Value() < 1 ) { 317 char buffer[256]; 318 snprintf( buffer, 256, "(%f,%f)", datRow.Value(), datCol.Value() ); 319 Error( name + ": " + 320 I2( "invalid cell coordinates ", 321 "coordenadas de celda invalidas " ) + buffer ); 322 status = false; 323 } 324 // Cell coordinates are 0-based internally 325 row = size_t( datRow.Value( ) - 1 ); 326 column = size_t( datCol.Value( ) - 1 ); 327 status = true; 328 } 329 } else { 330 Error( name + ": " + 331 I2( "invalid cell type, must be Text or Set ", 332 "referencia de celda invalida debe ser de tipo Text o Set " )); 333 status = false; 334 } 335 return status; 336 } 245 337 246 338 TolExcel::TolExcel( ) … … 561 653 562 654 //--------------------------------------------------------------------------- 563 DeclareContensClass(BDat, BDatTemporary, BDatExcel GetReal);564 DefExtOpr(1, BDatExcel GetReal, "Excel.ReadReal", 3, 3, "Real Real Real",655 DeclareContensClass(BDat, BDatTemporary, BDatExcelReadReal); 656 DefExtOpr(1, BDatExcelReadReal, "Excel.ReadReal", 3, 3, "Real Real Real", 565 657 "(Real ExcelHandler, Real Row, Real Column)", 566 658 I2("Return the contents of the given cell as a Real. If the contents " … … 569 661 BOperClassify::System_); 570 662 //---------------------------------------------------------------------------- 571 void BDatExcel GetReal::CalcContens()663 void BDatExcelReadReal::CalcContens() 572 664 { 573 665 static BText _name_( "Excel.ReadReal" ); … … 593 685 594 686 //--------------------------------------------------------------------------- 595 DeclareContensClass(BText, BTxtTemporary, BTxtExcel GetText);596 DefExtOpr(1, BTxtExcel GetText, "Excel.ReadText", 3, 3, "Real Real Real",687 DeclareContensClass(BText, BTxtTemporary, BTxtExcelReadText); 688 DefExtOpr(1, BTxtExcelReadText, "Excel.ReadText", 3, 3, "Real Real Real", 597 689 "(Real ExcelHandler, Real Row, Real Column)", 598 690 I2("Return the contents of the given cell as a Text. If the contents " … … 601 693 BOperClassify::System_); 602 694 //---------------------------------------------------------------------------- 603 void BTxtExcel GetText::CalcContens()695 void BTxtExcelReadText::CalcContens() 604 696 { 605 697 static BText _name_( "Excel.ReadText" ); … … 625 717 626 718 //--------------------------------------------------------------------------- 627 DeclareContensClass(BDate, BDteTemporary, BDteExcel GetDate);628 DefExtOpr(1, BDteExcel GetDate, "Excel.ReadDate", 3, 3, "Real Real Real",719 DeclareContensClass(BDate, BDteTemporary, BDteExcelReadDate); 720 DefExtOpr(1, BDteExcelReadDate, "Excel.ReadDate", 3, 3, "Real Real Real", 629 721 "(Real ExcelHandler, Real Row, Real Column)", 630 722 I2("Return the contents of the given cell as a Date. If the contents " … … 633 725 BOperClassify::System_); 634 726 //---------------------------------------------------------------------------- 635 void BDteExcel GetDate::CalcContens()727 void BDteExcelReadDate::CalcContens() 636 728 { 637 729 static BText _name_( "Excel.ReadDate" ); … … 653 745 } else { 654 746 contens_ = BDate::Unknown( ); 747 } 748 } 749 750 //--------------------------------------------------------------------------- 751 DeclareContensClass(BSet, BSetTemporary, BSetExcelReadRange); 752 DefExtOpr(1, BSetExcelReadRange, "Excel.ReadRange", 3, 3, "Real Anything Anything", 753 "(Real ExcelHandler, Anything CornerLT, Anything CornerRB)", 754 I2("Return the contents of the cells contained given cell's range. " 755 "The cell corners delimiting the range can be given as Text or " 756 "Set. For instance you can use either \"A1\" or [[1,1]].", 757 "Retorna el contenido de las celdas contenidas en el rango de " 758 "celdas dado. Las esquinas del rango pueden especificarse como " 759 "Text o Set. Por ejemplo se puede usar indistintamente " 760 "\"A1\" o [[1,1]]."), 761 BOperClassify::System_); 762 //---------------------------------------------------------------------------- 763 void BSetExcelReadRange::CalcContens() 764 { 765 static BText _name_( "Excel.ReadRange" ); 766 double addr = Dat( Arg( 1 ) ).Value(); 767 BSyntaxObject *cornerLT = Arg(2); 768 BSyntaxObject *cornerBR = Arg(3); 769 size_t c0, r0, c1, r1; 770 771 TolExcel *xls = TolExcel::decode_addr( addr ); 772 if ( xls ) { 773 // bool status1 = ; 774 // bool status2 = ; 775 if ( TolExcel::getCellCoordinates( _name_, cornerLT, r0, c0 ) && 776 TolExcel::getCellCoordinates( _name_, cornerBR, r1, c1 ) ) { 777 BList* result = NIL; 778 BList* aux = NIL; 779 size_t r,c; 780 for( r = r0; r <= r1; r++ ) { 781 BList* lsta = NIL; 782 BList* auxa = NIL; 783 for( c = c0; c <= c1; c++ ) { 784 LstFastAppend( lsta, auxa, xls->GetCellAnything( _name_, r, c ) ); 785 } 786 LstFastAppend( result, aux, NewSet( "", "", lsta, NIL, BSet::Generic) ); 787 } 788 contens_.RobStruct( result, NIL, BSet::Table ); 789 } 790 } else { 791 Error( _name_ + 792 I2(": invalid excel handler", 793 ": identificador de objeto excel invalido") ); 655 794 } 656 795 }
Note: See TracChangeset
for help on using the changeset viewer.
