


效果如下
原表格:
col0 | col1 | col2 | col3 |
SuZhou | 11111 | 22222 | SuZhouCity |
SuZhou | 33333 | 44444 | SuZhouCity |
SuZhou | 55555 | 66666 | SuZhouCity |
ShangHai | 77777 | 88888 | ShangHaiCity |
ShangHai | uuuuu | hhhhh | ShangHaiCity |
ShangHai | ggggg | ccccc | ShangHaiCity |
GuangZhou | ttttt | eeeee | GuangZhouCity |
GuangZhou | ppppp | qqqqq | GuangZhouCity |
处理之后的样子:
col0 | col1 | col2 | col3 |
SuZhou | 11111 | 22222 | SuZhouCity |
33333 | 44444 | ||
55555 | 66666 | ||
ShangHai | 77777 | 88888 | ShangHaiCity |
uuuuu | hhhhh | ||
ggggg | ccccc | ||
GuangZhou | ttttt | eeeee | GuangZhouCity |
ppppp | qqqqq |
效果出来, 看上去比较简单, 下面先看下页面
col0 | col1 | col2 | col3 |
SuZhou | 11111 | 22222 | SuZhouCity |
SuZhou | 33333 | 44444 | SuZhouCity |
SuZhou | 55555 | 66666 | SuZhouCity |
ShangHai | 77777 | 88888 | ShangHaiCity |
ShangHai | uuuuu | hhhhh | ShangHaiCity |
ShangHai | ggggg | ccccc | ShangHaiCity |
GuangZhou | ttttt | eeeee | GuangZhouCity |
GuangZhou | ppppp | qqqqq | GuangZhouCity |
核心代码:
// 这里写成了一个jquery插件的形式
$('#process').mergeCell({
// 目前只有cols这么一个配置项, 用数组表示列的索引,从0开始
// 然后根据指定列来处理(合并)相同内容单元格
cols: [0, 3]
});
下面看看这个小插件的完整代码:
;(function($) {
// After looking at the jquery source code, you can find that $.fn is $.prototype, jQuery is only retained for compatibility with earlier versions of the plug-in
// The form of prototype
$.fn.mergeCell = function(options) {
return this.each(function() {
var cols = options.cols;
for ( var i = cols.length - 1; cols[i] != undefined; i--) {
// fixbug console debugging
// console.debug(cols[i]);
mergeCell($(this), cols [i]);
}
dispose($(this));
});
};
// If you have a clear understanding of the concepts of closure and scope in JavaScript, this is a plug-in Private methods used internally
// For details, please refer to the book introduced in my previous essay
function mergeCell($table, colIndex) {
$table.data('col-content', ''); // Store cell content
$table.data('col-rowspan', 1); // Store calculated rowspan value, which defaults to 1
$table.data('col-td' , $()); // Store the first td found that is different from the previous row (encapsulated by jQuery), defaulting to an "empty" jquery object
$table.data('trNum', $( 'tbody tr', $table).length); //The total number of rows of the table to be processed, used for judgment when the last row is subjected to special processing
//The key is to "scan" each row of data. It is to locate col-td, and its corresponding rowspan
$('tbody tr', $table).each(function(index) {
// colIndex in td:eq is the column index
var $td = $('td:eq(' colIndex ')', this);
// Get the current content of the cell
var currentContent = $td.html();
// First Take this branch the next time
if ($table.data('col-content') == '') {
$table.data('col-content', currentContent);
$table. data('col-td', $td);
} else {
// The previous row has the same content as the current row
if ($table.data('col-content') == currentContent) {
// If the content of the previous row is the same as the current row, col-rowspan is accumulated and the new value is saved
var rowspan = $table.data('col-rowspan') 1;
$table.data(' col-rowspan', rowspan);
// It is worth noting that if $td.remove() is used, it will affect the processing of other columns
$td.hide();
// The situation in the last line is a bit special
// For example, the contents of the td in the last two lines are the same, then the td saved in col-td at this time should be set to rowspan in the last line
if ( index = = $table.data('trNum'))
$table.data('col-td').attr('rowspan', $table.data('col-rowspan'));
} else { // The content of the previous row is different from the current row
// col-rowspan defaults to 1, if the calculated col-rowspan has not changed, it will not be processed
if ($table.data('col-rowspan') != 1) {
$table.data('col-td').attr('rowspan', $table.data('col-rowspan'));
}
// Save the first Once a td with different content appears, and its content, reset col-rowspan
$table.data('col-td', $td);
$table.data('col-content', $ td.html());
$table.data('col-rowspan', 1);
}
}
});
}
// also private Function to clean up memory
function dispose($table) {
$table.removeData();
}
})(jQuery);
Main instructions It should be all in the comments. The code is indeed relatively simple, but some areas still deserve improvement
•The table content to be processed is searched starting from tbody. If there is no tbody, a more general solution should be given
•for ( var i = cols.length - 1; cols[i] != undefined; i--)... If the amount of table data is large and there are many columns processed, failure to optimize here will cause browser problems For the risk of thread blocking, you can consider using setTimeout
• There are many other things worth improving, I think there should be a lot

使用错误检查工具使用Excel电子表格查找错误的最快方法之一是使用错误检查工具。如果该工具发现任何错误,您可以更正它们并再次尝试保存文件。但是,该工具可能无法找到所有类型的错误。如果错误检查工具没有发现任何错误或修复它们不能解决问题,那么您需要尝试以下其他修复之一。要在Excel中使用错误检查工具:选择公式 选项卡。单击错误检查 工具。在发现错误时,有关错误原因的信息将出现在工具中。如果不需要,请修复错误或删除导致问题的公式。在错误检查工具中,单击下一步以查看下一个错误并重复该过程。当没

如何在打印预览中设置GoogleSheets打印区域Google表格允许您使用三个不同的打印区域打印电子表格。您可以选择打印整个电子表格,包括您创建的每个单独的工作表。或者,您可以选择打印单个工作表。最后,您只能打印您选择的部分单元格。这是您可以创建的最小打印区域,因为理论上您可以选择单个单元格进行打印。最简单的设置方法是使用内置的Google表格打印预览菜单。您可以在PC、Mac或Chromebook上的网络浏览器中使用Google表格查看此内容。要设置Google

不同单元格格式太多复制不了的解决办法:1、打开EXCEL文档,然后在几个单元格中输入不同格式的内容;2、在Excel页面的左上角找到“格式刷”按钮,然后单击“格式刷”选项;3、点击鼠标左键,将格式统一设置成一致的即可。

如何在Windows上的Excel中查找合并的单元格在从数据中删除合并的单元格之前,您需要全部找到它们。使用Excel的查找和替换工具很容易做到这一点。在Excel中查找合并的单元格:突出显示要在其中查找合并单元格的单元格。要选择所有单元格,请单击电子表格左上角的空白区域或按Ctrl+A。单击主页选项卡。单击查找和选择图标。选择查找。单击选项按钮。在FindWhat设置的末尾,单击Format。在对齐选项卡下,单击合并单元格。它应该包含一个复选标记而不是一行。单击确定以确认格式

在数值上,在文本字符串上,在错误的地方使用逗号确实会变得烦人,即使对于最大的Excel极客来说也是如此。您甚至可能知道如何摆脱逗号,但您知道的方法可能对您来说很耗时。好吧,无论您的问题是什么,如果它与您的Excel工作表中的错误位置的逗号有关,我们可以告诉您一件事,您所有的问题今天都会得到解决,就在这里!深入研究这篇文章,了解如何通过尽可能简单的步骤轻松去除数字和文本值中的逗号。希望你喜欢阅读。哦,别忘了告诉我们哪种方法最吸引你的眼球!第1节:如何从数值中删除逗号当数值包含逗号时,可能有两种情

如何在Windows11上创建自定义电源计划自定义电源计划允许您确定Windows如何对不同情况作出反应。例如,如果您希望显示器在一段时间后关闭,但又不想让它进入睡眠状态,您可以创建一个自定义计划来执行此操作。在Windows11上创建自定义电源计划:打开开始菜单并键入控制面板。从搜索结果中选择控制面板。在控制面板中,将查看方式选项更改为大图标。接下来,选择电源选项。单击电源选项菜单中的创建电源计划选项。从提供的选项中选择您要使用的基本电源计划。在底部的计划名称字段中为其指定一个描述性名

如何使用 RANDBETWEEN 在 Excel 中生成随机数如果要生成特定范围内的随机数,RANDBETWEEN 函数是一种快速简便的方法。这允许您在您选择的任何两个值之间生成随机整数。使用 RANDBETWEEN 在 Excel 中生成随机数:单击您希望出现第一个随机数的单元格。键入=RANDBETWEEN(1,500)将“1”替换为您要生成的最低随机数,将“500”替换为

如果您的任务是处理包含大量日期的电子表格,那么计算多个日期之间的差异可能会非常令人沮丧。虽然最简单的选择是依靠在线日期计算器,但它可能不是最方便的,因为您可能必须将日期一一输入到在线工具中,然后手动将结果复制到电子表格中。 对于大量日期,您需要一个更方便地完成工作的工具。幸运的是,谷歌表格允许用户在本地计算电子表格中两个日期之间的差异。在这篇文章中,我们将使用一些内置函数帮助您计算Google表格上两个日期之间的天数。 如何计算Google表格上的日期之间的差异如果您希望Google


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),