English 中文(简体)
表 数据分类和在使用 php的单表中保存表格数据
原标题:Table data parsing and saving the table data in excel sheet using php

我有一份“进口.php”文件,其中在表格标栏下撰写了html数据。 现在,我想要将这一数据加以分类,并将这些数据列入一个表。 格式载于上文,第一版载有标题,然后是数据。

<html>
  <body>
  <table>
  <tr>
  <th>Name</th>
  <th>Email</th>
  <th>Addr</th>
  <th>City</th>
  </tr>

  <tr>
  <td>Jack</td>
  <td>[email protected]</td>
  <td>xyz Road</td>
  <td>LOS ANGELES</td>
  </tr>

  <tr>
  <td>Sam</td>
  <td>[email protected]</td>
  <td>pr Road</td>
  <td>TUSTIN</td>
  </tr>
    </table>
  </body>
  </html>
最佳回答

Maybe You ve better look at this: http://phpexcel.codeplex.com/

http://www.easyxls.com/“rel=“nofollow”http://www.easyxls.com/

另一trick是拯救您的数据,将其作为CSV文档:

最新资料:

无法将数据直接输入Excel文档,而是作为CSV保存。 颁布这一法典:

<?php 
$data = array( array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25), 
    array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18), 
    array("firstname" => "James", "lastname" => "Brown", "age" => 31), 
    array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7), 
    array("firstname" => "Michael", "lastname" => "Davis", "age" => 43), 
    array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24), 
    array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27) ); 

    # filename for download 
    $filename = "website_data_" . date( Ymd ) . ".xls"; 
    header("Content-Disposition: attachment; filename="$filename""); 
    header("Content-Type: application/vnd.ms-excel");
    $flag = false; 
    foreach($data as $row) 
    { 
        if(!$flag) 
        { # display field/column names as first row echo 
            implode("	", array_keys($row)) . "
"; $flag = true; 
        } 
        array_walk($row,  cleanData );
        print implode("	", array_values($row)) . "
"; 
    }


    function cleanData(&$str) 
    { 
        $str = preg_replace("/	/", "\t", $str); 
        $str = preg_replace("/
?
/", "\n", $str); 
        if(strstr($str,  " )) 
            $str =  "  . str_replace( " ,  "" , $str) .  " ;
    }
?>

关于从进口到岸价的排序问题,你可以读到贵国的html。 php,除掉所有不必要的标签,使每一方或对口单位都告终,然后将贵方的价值观纳入一个整体:

<?php 
$htmldata = "";
$htmldata .= "<html>";
$htmldata .= "<body>";
$htmldata .= "<tr>";
$htmldata .= "<th>header1</th>";
$htmldata .= "<th>header2</th>";
$htmldata .= "<th>header3</th>";
$htmldata .= "<th>header4</th>";
$htmldata .= "</tr>";
$htmldata .= "<tr>";
$htmldata .= "<td>data1</td>";
$htmldata .= "<td>data2</td>";
$htmldata .= "<td>data3</td>";
$htmldata .= "<td>data4</td>";
$htmldata .= "</tr>";
$htmldata .= "</body>";
$htmldata .= "</html>";

//Remove the unecessary tags like <html>, </html>, <body>, </body>, <th>, </th>, <td>, </td>
$searchfor = array("<html>", "</html>", "<body>", "</body>", "<tr>", "</tr>", "<th>", "</th>", "<td>", "</td>");
$replacewith = array("", "", "", "", "", "", "", "**SEPERATOR**", "", "**SEPERATOR**"); // Replace </th> & </td> with **SEPERATOR** text
$htmldata = str_replace($searchfor, $replacewith, $htmldata);

$values = explode("**SEPERATOR**", $htmldata); ;
print_r($values);

?>

阵列的头4项价值包含你的头盔价值。 希望有助于......

问题回答

暂无回答




相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签