Re: Import of data by users

Hello,
Using SC 9.4

I want to give the users, of my developed app using scriptcase, the facility to import data from an excel or csv files. I need your help in making this possibility

  1. First the user should have a facility to import a excel / csv file to the server.
  2. Then we need to read the file, show the contents in a table. So that any wrong data could be identified.
  3. Then user will select the rows that he needs to update
  4. Read the selected rows, check and insert the data into the database. If the data is already available, it need not update
  5. Need to display in another table, the rows that were not added.
  6. Allow to export the not added rows into excel

Any idea to accomplish this task is highly appreciated.

Happiness Always
BKR Sivaprakash

2 Likes

Scriptcase? I need this too. It is the Second Year that I am rethinking my renewal with them…

Hi, I hope this can help you

  1. In a blank app:
    sc_include_lib (“excel”);
    $objPHPExcel=PHPExcel_IOFactory::load($rutaXLS);
    foreach ($objPHPExcel->getWorksheetIterator() as $worksheet){
    $worksheet = $objPHPExcel->getActiveSheet();
    $worksheetTitle = $worksheet->getTitle();
    $highestRow = $worksheet->getHighestRow();
    $highestColumn = $worksheet->getHighestColumn();
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $nrColumns = ord($highestColumn) - 64;

    for ($row=2;$row<= $highestRow; ++ $row)
    {
    $cell = $worksheet -> getCellByColumnAndRow (0, $row);
    $field1= $cell ->getValue();
    $cell = $worksheet -> getCellByColumnAndRow (1, $row);
    $field2= $cell ->getValue();
    …the same with all fields you need to insert into a temp table.
    now do the insert SQL into the temp table

}

}

2/3/4. Now, you have data in a SQL table, when the import ends redirects to a grid to show the data and select the rows you are interested in through run button and process them saving into a table.
Delete each selected rows in the temp table

  1. The temp table only have now the rows not processed
  2. Use the export utility of a grid to export the data to an excel file

regards.

4 Likes

Can any one share the full code.

Can you share the full code

you ever find the code?