fork download
  1. void __fastcall TForm1::Btn_LoadClick(TObject *Sender)
  2. {
  3. AnsiString filepath;
  4.  
  5. if(OpenDialog1->Execute()) //若開啟檔案成功
  6. {
  7. filepath= OpenDialog1->FileName.c_str(); //把檔案路徑儲存 filepath
  8. }
  9.  
  10.  
  11. Edit1->Text= ""+filepath ; //印出路徑
  12.  
  13. //declaration of variables of type variant
  14. Variant XL,v0,v1,vcell;
  15.  
  16. //a string where you will temporarily put the content of a single Cell
  17. AnsiString tmp;
  18.  
  19. //create an object which is an excel application and store it to XL
  20. XL=Variant::CreateObject("excel.application");
  21.  
  22. //Set the Excel Application as invisible once you have opened it
  23. XL.PS("Visible",false);
  24.  
  25. //Get the workbooks while has a path stored in “file” variable and open it.
  26. XL.PG("Workbooks").PR("Open", filepath.c_str() );
  27.  
  28. //Get the Sheet which has a title “Sheet1〃
  29. v0=XL.PG("Sheets","Hover_Down_Result");
  30.  
  31. //Get the Cells of that particular Sheet.
  32. v1=v0.PG("Cells");
  33. for(int row=1; row<7; row++)
  34. {
  35. for(int col=1; col<3; col++)
  36. {
  37. //Get the content of the Cell located at row 2 and column 2
  38. vcell=v1.PG("Item",row,col); //決定要讀取的位置 at row 2 and column 2
  39.  
  40. //store that content to ansistring “tmp”
  41. tmp=vcell.PG("Value");
  42. //重複 上兩行決定要讀的數字
  43.  
  44. //印出
  45. Memo1->Lines->Add("xls[2][2]="+tmp );
  46. }
  47. }
  48.  
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: expected initializer before ‘TForm1’
stdout
Standard output is empty