Monday, 27 October 2014

Read Excel File Using Peoplecode


Local object &oWorkApp, &oWorkBook;
Local string &sFilePath ;
&sFilePath = "C:\Users\Administrator\Desktop\munib\Book1.xls";


&oWorkApp = CreateObject("COM", "Excel.Application");
&oWorkApp.DisplayAlerts = "False";
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks");


&oWorkBook.Open(&sFilePath);
&oWorkSheet = &oWorkApp.Worksheets("Sheet1");
&rowcount = &oWorkSheet.Usedrange.rows.count;
&cellcount = &oWorkSheet.Usedrange.cells.count;
&columncount = &oWorkSheet.Usedrange.columns.count;

For &i = 1 To &rowcount
         For &j = 1 To &columncount;
      &data = &oWorkSheet.Cells(&i, &j).Value;
      MessageBox(0, "", 0, 0, "data in" | &i | " row " | &j | " column :" | &data);
   
   End-For;
End-For;

&oWorkApp.ActiveWorkBook.Close();
&oWorkApp.DisplayAlerts = "True";
&oWorkApp.Quit();

No comments:

Post a Comment