0
私はphlsexcelを使ってxlsxからmysqlデータベースにデータを入力しています。 私は例えばのために、ファイルが式を用いて算出した値を持っているエクセル:phpexcelを使用してmysqlデータベースにエクセル式を変換
= SUM(J21:J24)
マイphpexcelスクリプトは、細かいExcelファイルショーで式を用いしかし、データを実行しています " 0 'にします。
次のように私のPHPスクリプトは次のとおりです。上記のコードで
<?php
$connect = mysqli_connect("localhost", "root", "", "unhrd_fund_balance");
include ("PHPExcel/IOFactory.php");
$html="<table border='1'>";
$objPHPExcel = PHPExcel_IOFactory::load('sample2.xlsx');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row=2; $row<=$highestRow; $row++)
{
$html.="<tr>";
$ini = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(0, $row)->getValue());
$progkey = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(1, $row)->getValue());
$grantkey = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(2, $row)->getValue());
$tod = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(3, $row)->getValue());
$tdd = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(4, $row)->getValue());
$fund = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(5, $row)->getValue());
$orderkey = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(6, $row)->getValue());
$budgetalloc = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(7, $row)->getValue());
$precommit = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(8, $row)->getValue());
$commit = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(9, $row)->getValue());
$actuals = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(10, $row)->getValue());
$totalcommit = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(11, $row)->getValue());
$availablebudget = mysqli_real_escape_string($connect,$worksheet->getCellByColumnAndRow(12, $row)->getValue());
$query = "insert into fund_balances(INITIATIVE, FUNDED_PROG_KEY, GRANT_KEY, TOD, TDD, FUND, ORDER_KEY, BUDGET_ALLOC, PRE_COMMIT, COMMIT, ACTUALS, TOTAL_COMMIT,AVAILABLE_BUDGET) values('".$ini."','".$progkey."','".$grantkey."','".$tod."','".$tdd."','".$fund."','".$orderkey."','".$budgetalloc."','".$precommit."','".$commit."','".$actuals."','".$totalcommit."','".$availablebudget."')";
mysqli_query($connect, $query);
$html.= '<td>'.$ini.'</td>';
$html .= '<td>'.$progkey.'</td>';
$html .= '<td>'.$grantkey.'</td>';
$html .= '<td>'.$tod.'</td>';
$html .= '<td>'.$tdd.'</td>';
$html .= '<td>'.$fund.'</td>';
$html .= '<td>'.$orderkey.'</td>';
$html .= '<td>'.$budgetalloc.'</td>';
$html .= '<td>'.$precommit.'</td>';
$html .= '<td>'.$commit.'</td>';
$html .= '<td>'.$actuals.'</td>';
$html .= '<td>'.$totalcommit.'</td>';
$html .= '<td>'.$availablebudget.'</td>';
$html .= "</tr>";
}
}
$html .= '</table>';
echo $html;
echo '<br />Data Inserted';
?>
、「$実績は、」Excelの数式を使用して、データベース内のNULLです。
で説明されているように、
getCalculatedValue()
メソッドを使用します。値を指定してHTMLテーブルを作成しています。 '''です。$ actuals。' ''$ actuals'にも0が表示されますか?または、他の何か?例えば何ですか?また、あなたのMySQLテーブルの 'ACTUALS'フィールドはどんな種類のフィールドデータ型ですか? –表には、ゼロではなく数式が表示されます。 – compcrk
ACTUALSは、値を計算するExcelシートの式です – compcrk