当前位置: 动力学知识库 > 问答 > 编程问答 >

writing and appending into xls file php

问题描述:

Here I am putting some array content into xls file. I want to append some other message to. how it could be done?

currently it writes only array result into file.

I want to write

echo $category;

Inside for:

echo "<br/><br/><strong> $i star word count </strong>";

full code

 $file = fopen("words.xls","w+");

echo $category;

for($i = 5; $i > 0 ; $i--)

{

$select_words = mysqli_query($con,"SELECT * from review_details where rate = $i and category = '".$category."' and isApi = 0");

while ($row1 = @mysqli_fetch_array($select_words))

{

//echo $row1[review]."<br>";

// echo $row1[rate]."<br>";

$word.=$row1[adjective].",";

}

//echo "Words are : $word";

echo "<br/><br/><strong> $i star word count </strong>";

$word_count = array_count_values(str_word_count($word,1));

arsort($word_count);

echo "<br>";

echo "<br>";

//var_dump($word_count);

$word_count2 = array_slice($word_count,0,20);

print_r($word_count2);

unset($word);

unset($word_count);

unset($select_words);

file_put_contents('words.xls', print_r($word_count2, true), FILE_APPEND | LOCK_EX);

}

网友答案:

I wouldn't recommend directly opening xls file in php and write values to it, as it will create comparability issues.

If you want to manipulate xls files you can use a free and open source library like PHPExcel.

URL for PHPExcel

The code will look like this:

$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load("05featuredemo.xlsx");    
$objPHPExcel->getActiveSheet()->setCellValue('B8', 'Some value');
分享给朋友:
您可能感兴趣的文章:
随机阅读: