Home > Article > Backend Development > Use for loop to merge multiple columns of data into one cell in Excel
Today at work, my boss gave me a task to merge multiple columns of data in the excel table into one column.
The data is as follows:
Note: The data ranges from 16601 to 20000, which means there are two thousand URLs.
Here are a few methods for you:
The first one: use the wps built-in function
1. In the publicity tab Find the insert function
#2. Search for CONCATENATE
function
3. Will need to splice Fill in the parameters in the cells
4 and confirm
Disadvantages: This method is suitable for small amounts of data, but in You may encounter a large amount of data at work, so I will introduce the second method to you.
Second: Use for() loop
Since we need to complete the data from 16601 to 20000, and the URL prefix and suffix are the same, we need to use the for() loop.
demo:
<?php $url = 'https://www.cctv.com/wenda/'; $html = '.html'; for($i = 16602; $i <= 2000; $i++) { echo $url.$i.$html.'<br>'; } ?>
The result is as shown in the figure:
Third method: Use the PHP built-in function implode() function
<?php //定义不变内容组成的数组 $arr = array('https://www.cctv.com/wenda','.html'); //利用循环和implode函数拼接字符串 for($i = 16601; $i <= 20000; $i++) { $string = implode($i,$arr); echo $string.'<br>'; } ?>
The results are as shown below:
If there are any errors in the above content, please correct me! Greatful.
For more related questions, please visit the PHP Chinese website: PHP Video Tutorial
The above is the detailed content of Use for loop to merge multiple columns of data into one cell in Excel. For more information, please follow other related articles on the PHP Chinese website!