Jump to content

shadow-walker

New Members
  • Posts

    4
  • Joined

  • Last visited

shadow-walker's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. how would it explode on the fields of an Excel file for import into a mysql table, because the next step of my dìsarebbe this function code: $ Uploaddir = getenv ( 'XLSX_STORE'). Basename ($ file); switch ($ filetype) { "WALL" houses: rename ($ file, $ uploaddir); echo "Upload succesfully!" file; try { $ InputFileType = PHPExcel_IOFactory :: identify ($ filetype); $ 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> <? Php break; default: echo "Files do not readable"; } } $ Query =? that is, once it was recognized that the file is called wall_ and was then imported into XLSX_STORE, the excel sheet data are organized into an array of arrays hash which then generates a table html, now I want to import this data to 'interior of a mysql table but that is unpacked http://i.stack.imgur.com/9yrC1.jpg This is the excel as you can see the first field is to be imported as you see it in one piece, but then the second and the third are unpacked ie data / model / type shall be divided and power is also divided into two, how would you? thank you, the connection to the db is already made so I just need the query, even infinite thanks
  2. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.