0

I'm using phpexcel , I created a script that so far it takes me an Excel spreadsheet and I put the field values ​​in an array of associative arrays , I found a way then print these values ​​in a table html , to see if the recreated excel files exactly as imported and I did , here is my function :

// DB Connection Init
//
$db_address="127.0.0.1";
$db_user="b2bmomo_b2b";
$db_password="Tyed_^8f_.Hr";
$db_name="b2bmomo_b2b";
$db = new mysqli($db_address, $db_user, $db_password, $db_name);
if ($db->connect_errno) {
    die("Failed to connect to MySQL: (".$db->connect_errno.") ".$db->connect_error);
}
    $excelfilepath='/home/b2bmomo/test/b2b.xlsx';
    $Extension = strtolower(pathinfo($excelfilepath, PATHINFO_EXTENSION));
    if ($Extension != 'xlsx'){
        throw new Exception('File Extension must be xlsx');
    }
    if (!is_readable($excelfilepath)){
                throw new Exception('File ('.$excelfilepath.') not readable');
    }

    try {
        $inputFileType = PHPExcel_IOFactory::identify($excelfilepath);
        $objReader = PHPExcel_IOFactory::createReader($inputFileType);
        $phpExcel = $objReader->load($excelfilepath);
        $sheet = $phpExcel->getSheet(0);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
  $highestrow = $sheet->getHighestRow();
  $highestcolumn = $sheet->getHighestColumn();
  $columncount = PHPExcel_Cell::columnIndexFromString($highestcolumn);
  $titles = $sheet->rangeToArray('A1:' . $highestcolumn . "1");
  $body = $sheet->rangeToArray('A2:' . $highestcolumn . $highestrow);
  $table = array();
  for ($row = 0; $row <= $highestrow - 2; $row++) {
    $a = array();
    for ($column = 0; $column <= $columncount - 1; $column++) {
      $a[$titles[0][$column]] = $body[$row][$column];
    }
    $table[$row] = $a;
  }?> <table class="table table-bordered"> <?php
$sheet = $phpExcel->getSheet(0);
 $highestColumn = $sheet->getHighestColumn();
 $highestRow = $sheet->getHighestRow();
for ($row = 1; $row <= $highestRow; $row++):
        $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
        ?> <tr> <?php foreach ($rowData[0] as $col): ?> <td><?php echo $col; ?></td> <?php endforeach; ?> </tr> <?php endfor; ?> </table>
$query=?

now I want to make sure that the data instead of my excel sheet, they were imported within a table in a mysql database , but unpacked , in the sense that having my excel sheet like this :

http://i.stack.imgur.com/9yrC1.jpg

the name of excel sheet is wall

the first field is One figure, then Amount As it stands, however The Second Course I would just import it by unzipping the field in 4 different data taking the first Excel's value as an example, I would take 2001 and inserting it into a field of a table machines call, the second in 2009 value and import it into another field in the table, the third value 147 in another field in the table and the last value 937, maybe doing a explode? I would do the same thing then in power taking more and as the first line I would like to put in a field the first value of the table and in another field in the second value, I used the phpdotenv class to store variables in the directory names in which they will the excel, now I should use this procedure:

Create a file in it includes config.app that laws init.php with https://github.com/vlucas/phpdotenv (phpdotenv is already loaded is configured)
2) In config.app files are the following variables, which will read:
XLSX_FILES = / home / b2bmomo / www / import /
XLSX_STORE = / home / b2bmomo / www / store /
3) At this point, $ ENV [ "XSLX_FILES"] will contain "/ home / b2bmomo / www / import /" and $ ENV [ "XSLX_STORE"] will contain "/ home / b2bmomo / www / store /", and are global
4) Are you looking for if there is a file with extension XLSX $ _ENV [ "XSLX_FILES"]
5) For each file that you find
a) I take the name of the file, which will be called by convection all <something> <something else> .xslsx
b) Depending on the value of <something> (hint: use switches)
- If <something> == "WALL"
Importing a file WALL
- default
error: unrecognized file type
IMPORT WALL
// Archive file
I move WALL
<something else> .xslsx in $ _ENV [ "XSLX_STORE"]. <something else> .xslsx
// Amount of data in memory
I read $ _ENV [ "XSLX_STORE"]. <Something else> .xslsx in a table (array of arrays hash)
// I prepare the cars table
for each array element
recovery from the "MANUFACTURER" fields, "DATA / MODEL / TYPE" and "POWER" the data for the table
check if there is already a record with this data
If there is not
I insert it

Edited by Federico_1

2
Contributors
4
Replies
15
Views
1 Year
Discussion Span
Last Post by rproffitt
1

Let's check a basic thing. You claim the file name is "wall" but later on write "WALL". In almost every OS today those are not the same file.

0

i know this, i write this in this mode because i write fast, but you can help me with my problem?

2

Sorry but if you post incorrect details, folk may give incorrect answers. Next time copy and paste to avoid this issue. I offered what I saw, but it appears that you were in a hurry.

Votes + Comments
He he. "He knows this". +1 for keeping it civil :)
0

Just in case you are stuck. A few things.

  1. I call such work "parsing." If I have a string that I need to parse into substrings, I parse that. Unzipping to most folk is something else altogether.

  2. If you are unsure of what's going on, and you don't have an IDE with debugging, old fashioned print statements and pauses do wonders.

  3. When I need to try something new in php, I use phpfiddle (see the web.) Your choice on that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.