gpt4 book ai didi

javascript - 如何合并具有相同值的单元格表

转载 作者:行者123 更新时间:2023-11-28 02:19:08 25 4
gpt4 key购买 nike

我正在尝试创建一个表。如果单元格的属性值与另一个属性值(如“可用”或“不可用”)相同,我想合并表格单元格。我想不出如何用 jQuery、JavaScript 或任何其他语言来做到这一点。


我有以下代码:

<html>
<table>
<thead>
<tr>
<th>NO </th>
<th> name </th>
<th> 2018-1-1 </th>
<th> 2018-1-2 </th>
<th> 2018-1-3 </th>
<th> 2018-1-4 </th>
<th> 2018-1-5 </th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> Mark Tony </td>
<td>Available </td>
<td>Available </td>
<td>Available </td>
<td>Not </td>
<td>Not </td>
</tr>
<tr>
<td> 2 </td>
<td> Susan Tom </td>
<td>Not </td>
<td>Available </td>
<td>Available </td>
<td>Not </td>
<td>Not </td>
</tr>
</tbody>
</table>
</html>

最佳答案

子 MergeSameCell()

Dim Rng As Range, xCell As Range
Dim xRows As Integer, xRows1 As Integer
Dim LastRowTE As Long

LastRowTE = Worksheets("Test_Execution").Cells(Worksheets("Test_Execution").Rows.Count, "A").End(xlUp).Row
Set WorkRng = Range("A2:A" & LastRowTE)
Set WorkRng1 = Range("B2:B" & LastRowTE)

Application.ScreenUpdating = False
Application.DisplayAlerts = False

xRows = WorkRng.Rows.Count
xRows1 = WorkRng1.Rows.Count

For Each Rng In WorkRng.Columns
For i = 1 To xRows - 1
For j = i + 1 To xRows
If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then
Exit For
End If
Next
WorkRng.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge
i = j - 1
Next
Next

For Each Rng In WorkRng1.Columns
For i = 1 To xRows1 - 1
For j = i + 1 To xRows1
If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then
Exit For
End If
Next
WorkRng1.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge
i = j - 1
Next
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True

Range("A1:O" & LastRowTE).WrapText = True

结束子

关于javascript - 如何合并具有相同值的单元格表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48318092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com