Changeset 4874c09 in tol
- Timestamp:
- Jan 21, 2010, 11:24:57 AM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- c6f2e5f
- Parents:
- b07437b
- File:
-
- 1 edited
-
tol/contrib/excel/tolExcel.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/contrib/excel/tolExcel.cpp
rb07437b r4874c09 29 29 #endif 30 30 31 #include <tol/tol_tree.h> 32 #include <tol/tol_blanguag.h> 31 33 #include <tol/tol_bdatgra.h> 32 34 #include <tol/tol_btxtgra.h> 35 #include <tol/tol_bspfun.h> 33 36 34 37 … … 51 54 { 52 55 m_ptrActiveWS = xls_getWorkSheet( m_ptrWB, num ); 56 if ( m_ptrActiveWS ) { 57 xls_parseWorkSheet( m_ptrActiveWS ); 58 } 53 59 return m_ptrActiveWS != NULL; 54 60 } … … 184 190 tal que podamos verificar si la direccion es valida antes de 185 191 hacer delete */ 186 delete aux; 187 contens_ = BDat( 1.0 ); 192 if ( aux ) { 193 delete aux; 194 contens_ = BDat( 1.0 ); 195 } else { 196 Error( BText( "Excel.Close: " ) + 197 I2("invalid excel handler", 198 "identificador de objeto excel invalido") ); 199 contens_ = BDat( 0.0 ); 200 } 188 201 } 189 202 … … 203 216 BText &name = Text( Arg( 2 ) ); 204 217 tol_excel_t *xls = tol_excel_t::decode_addr( addr ); 205 contens_ = BDat( xls->activateWS( name.Buffer() ) ); 218 if ( xls ) { 219 contens_ = BDat( xls->activateWS( name.Buffer() ) ); 220 } else { 221 Error( BText( "Excel.Close: " ) + 222 I2("invalid excel handler", 223 "identificador de objeto excel invalido") ); 224 contens_ = BDat( 0.0 ); 225 } 206 226 } 207 227 … … 223 243 if ( idx >= 0 ) { 224 244 tol_excel_t *xls = tol_excel_t::decode_addr( addr ); 225 contens_ = BDat( xls->activateWS( idx ) ); 245 if ( xls ) { 246 contens_ = BDat( xls->activateWS( idx ) ); 247 } else { 248 Error( BText( "Excel.ActivateWS: " ) + 249 I2("invalid excel handler", 250 "identificador de objeto excel invalido") ); 251 contens_ = BDat( 0.0 ); 252 } 226 253 } else { 227 Error( I2("Excel.ActivateWS : invalid Work Sheet index, must be >= 0", 228 "Excel.ActivateWS : indice de hoja invalido, debe ser >= 0") ); 254 Error( BText( "Excel.ActivateWS: " ) + 255 I2( "invalid work sheet index, must be >= 0", 256 "indice de hoja invalido, debe ser >= 0") ); 229 257 contens_ = BDat( 0.0 ); 230 258 } … … 235 263 } 236 264 } 265 266 //-------------------------------------------------------------------- 267 static BSyntaxObject* 268 EvExcelReadCell( BGrammar* gra, const List* tre, BBool left ) 269 /*! Evaluate Copy expressions 270 */ 271 //-------------------------------------------------------------------- 272 { 273 static BText _name_ = "Excel.ReadCell"; 274 BSyntaxObject* result = NIL; 275 BInt nb = BSpecialFunction::NumBranches(tre); 276 if( BSpecialFunction::TestNumArg( _name_, 3, nb, 3 ) ) { 277 BSyntaxObject *addr = GraReal()->EvaluateTree( Branch( tre, 1 ) ); 278 if ( !Dat( addr ).IsKnown( ) ) { 279 Error( _name_ + ": " + 280 I2( "invalid excel object address, must be known", 281 "direccion de objeto excel invalida, debe ser conocida" ) ); 282 return NULL; 283 } 284 BSyntaxObject *row = GraReal()->EvaluateTree( Branch( tre, 2 ) ); 285 BSyntaxObject *col = GraReal()->EvaluateTree( Branch( tre, 3 ) ); 286 if ( row && col ) { 287 BDat &dat_row = Dat( row ); 288 BDat &dat_col = Dat( col ); 289 if ( !dat_row.IsKnown() || dat_row.Value() < 0 || 290 !dat_col.IsKnown() || dat_col.Value() < 0 ) { 291 Error( _name_ + ": " + 292 I2("invalid cell coordinates, must be ", 293 "coordenadas de celda invalidas, deben ser ") + 294 "(row,col)>=(0,0)" ); 295 return NULL; 296 } 297 WORD i_row = DWORD( dat_row.Value() ); 298 WORD i_col = DWORD( dat_col.Value() ); 299 tol_excel_t *xls = tol_excel_t::decode_addr( Dat( addr ).Value() ); 300 if ( !xls ) { 301 Error( _name_ + ": " + 302 I2("invalid excel object address", 303 "direccion de objecto excel invalido") ); 304 return NULL; 305 } 306 307 if ( !xls->validWS( ) ) { 308 Error( _name_ + ": " + 309 I2("there is no active work sheet", 310 "no hay hoja de trabajo activa") ); 311 return NULL; 312 } 313 xlsCell *cell = xls->GetCell( i_row, i_col ); 314 if ( !cell || cell->ishiden ) { 315 Warning( _name_ + ": " + 316 I2("the cell does not exists or is hiden", 317 "la celda no existe o esta oculta") ); 318 result = new BContensText( "" ); 319 } else { 320 if ( cell->id == 0x27e || cell->id == 0x0BD || 321 cell->id == 0x203 ) { 322 result = new BContensDat( cell->d ); 323 } else if ( cell->id == 0x06 ) { 324 // formula 325 if ( cell->l == 0 ) { 326 // its a number 327 result = new BContensDat( cell->d ); 328 } else { 329 if ( !strcmp( cell->str, "bool" ) ) { 330 // its boolean, and test cell->d 331 result = new BContensDat( cell->d ); 332 } else if ( !strcmp( cell->str, "error" ) ) { 333 // formula is in error 334 result = new BContensText( "*error*" ); 335 } else { 336 // ... cell->str is valid as the result of a string formula. 337 result = new BContensText( cell->str ); 338 } 339 } 340 } else if (cell->str != NULL) { 341 result = new BContensText( cell->str ); 342 } else { 343 result = new BContensText( "" ); 344 } 345 } 346 } 347 } 348 result = BSpecialFunction::TestResult( _name_, result, tre, NIL, BTRUE ); 349 return(result); 350 } 351 352 static void* cloneInitExcelReadCell_() 353 { 354 BSpecialFunction::AddInstance( "Excel.ReadCell", 355 "(Real ExcelID, Real Row, Real Column)", 356 I2("Read the contents of a cell in the active work sheet", 357 "Lee el contenido de una celda en la hoja de trabajo activa"), 358 EvExcelReadCell ); 359 return new int(1); 360 }; 361 362 static int *_init_ExcelReadCell = 363 (int*)(__delay_init((void**)(&_init_ExcelReadCell), &cloneInitExcelReadCell_));
Note: See TracChangeset
for help on using the changeset viewer.
