Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Quando o script le o sql o formato da data acaba não sendo aceito ('FriFri/NovNov/2010201020102010') conforme o retorno abaixo:
- FriFri/NovNov/2010201020102010 -
- Warning: pg_query() expects parameter 1 to be resource, boolean given in
- D:\xampp\htdocs\leitorxls2\example.php on line 99
- INSERT INTO pedidos_venda2 ( product_hierarchy, validade, material, material_description )
- VALUES ( 'BRTM', 'FriFri/NovNov/2010201020102010', 'P61BEB5FH',
- '09 25 15 5S 0,05B 0,05Cu 0,1Mn 0,1Zn' )
- ______________________________________________________________________
- <?php
- // Test CVS
- require_once 'Excel/reader.php';
- function conecta_logistica()
- {
- $BANCO = "host=localhost port=5432 dbname=teste user=postgres password=102030";
- return pg_connect ( $BANCO );
- }
- // ExcelFile($filename, $encoding);
- $data = new Spreadsheet_Excel_Reader();
- // Set output Encoding.
- $data->setOutputEncoding('CP1251');
- /***
- * if you want you can change 'iconv' to mb_convert_encoding:
- * $data->setUTFEncoder('mb');
- *
- **/
- /***
- * By default rows & cols indeces start with 1
- * For change initial index use:
- * $data->setRowColOffset(0);
- *
- Exibindo Uma Planilha
- Caso seu desejo seja apenas apresentar o conteúdo de um arquivo excel no navegador então faça o seguinte:
- $data = new Spreadsheet_Excel_Reader("test.xls");
- $data->dump();
- Convertendo uma Planilha em Array
- Não existe tal função na ferramenta, sendo assim eu fiz a implementação desta funcionalidade
- $data = new Spreadsheet_Excel_Reader("test.xls")
- $totalLinhas = $data->rowcount();
- $totalColunas= $data->colcount();
- for($i = 1; $i <= $totalLinhas; $i++){
- for($j = 1; $j <= $totalColunas; $j++){
- $a[$i][$j] = $data->val($i,$j);
- }
- }
- return $a;
- * Some function for formatting output.
- * $data->setDefaultFormat('%.2f');
- * setDefaultFormat - set format for columns with unknown formatting
- *
- * $data->setColumnFormat(4, '%.3f');
- * setColumnFormat - set format for column (apply only to number fields)
- *
- **/
- $data->read('fotosemana1.xls');
- /*
- $data->sheets[0]['numRows'] - count rows
- $data->sheets[0]['numCols'] - count columns
- $data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column
- $data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell
- $data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
- if 'type' == "unknown" - use 'raw' value, because cell contain value with format '0.00';
- $data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
- $data->sheets[0]['cellsInfo'][$i][$j]['colspan']
- $data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
- */
- error_reporting(E_ALL ^ E_NOTICE);
- $CON = conecta_logistica();
- pg_query( 'BEGIN' );
- for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
- {
- if($i != 1)
- {
- echo $teste = $data->sheets[0]['cells'][$i][16]." - ";
- if( $data->sheets[0]['cells'][$i][1] != '' )
- {
- $SQL = "
- INSERT INTO pedidos_venda2
- ( product_hierarchy, validade, material, material_description )
- VALUES
- ( '" . $data->sheets[0]['cells'][$i][1] . "', '" . $data->sheets[0]['cells'][$i][16] . "', '" . $data->sheets[0]['cells'][$i][3] . "', '" . $data->sheets[0]['cells'][$i][4] . "' )
- ";
- pg_query ( $CON, $SQL );
- echo $SQL;
- }
- }
- echo "<br><br>";
- }
- pg_query( 'COMMIT' );
- //print_r($data);
- //print_r($data->formatRecords);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement