Home > Backend Development > PHP Tutorial > Use for loop to merge multiple columns of data into one cell in Excel

Use for loop to merge multiple columns of data into one cell in Excel

王林
Release: 2023-04-07 10:44:02
Original
5404 people have browsed it

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:

Use for loop to merge multiple columns of data into one cell in Excel

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

Use for loop to merge multiple columns of data into one cell in Excel

#2. Search for CONCATENATEfunction

Use for loop to merge multiple columns of data into one cell in Excel

3. Will need to splice Fill in the parameters in the cells

Use for loop to merge multiple columns of data into one cell in Excel4 and confirm

Use for loop to merge multiple columns of data into one cell in Excel

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 = &#39;https://www.cctv.com/wenda/&#39;;
$html = &#39;.html&#39;;
for($i = 16602; $i <= 2000; $i++) {
    echo $url.$i.$html.&#39;<br>&#39;;
}
?>
Copy after login

The result is as shown in the figure:

Use for loop to merge multiple columns of data into one cell in Excel

Third method: Use the PHP built-in function implode() function

<?php
//定义不变内容组成的数组
$arr = array(&#39;https://www.cctv.com/wenda&#39;,&#39;.html&#39;);
//利用循环和implode函数拼接字符串
for($i = 16601; $i <= 20000; $i++) {
    $string = implode($i,$arr);
    echo $string.&#39;<br>&#39;;
}
?>
Copy after login

The results are as shown below:

Use for loop to merge multiple columns of data into one cell in Excel

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template