It is easier to merge columns with the same content in a Table, and there are a lot of code on the Internet.
Plug-ins, calling is still quite useful.
This place has been slightly modified. Sometimes the content in td is the same, but the value in the database is different. For example, different companies have personnel departments, finance departments,
Company A's Finance Department and Company B's Finance Department cannot be merged, so I added A name attribute to td. Used to save the Department ID. The Department IDs of each company in the group are different.
Call Method
$ (Function (){
$ ("# Tbdianbao"). rowspan (1); // merge the 2nd columns,
$ ("# Tbdianbao"). rowspan (2); // merge the 3rd Columns
});
(Function ($) {$. fn. extend ({// the name used to call the plug-in. The input is the column index 0, 1, 2, "rowspan": function (co1_x) {var that; var rowspan; // traverse the rows in the table $ (this ). find ("tr "). each (function (row) {// obtain the set of the index column, and filter it with filter to Obtain visible columns, and then traverse them $ ('td: eq ('+ codecomx +') ', this ). filter (': visible '). each (function (col) {// the content of the upper and lower columns is the same if (that! = Null & $ {rowspan = $ (that ). attr ("rowSpan"); // if it is the first time to merge two columns if (rowspan = undefined) {$ (that ). attr ("rowSpan", 1); rowspan = $ (that ). attr ("rowSpan");} rowspan = Number (rowspan) + 1; $ (that ). attr ("rowSpan", rowspan); // hide this column $ (this ). hide () ;}else {// the object that saves the previous column that = this ;}}) ;}}}) ;}) (jQuery );
We may need to import the generated table to Excel and merge the same columns. We cannot afford to worry about VBA, so we can only judge the merged columns when generating an Excel file.
The columns with the same company ID in the two columns are merged from the excel 3rd row, and the columns with the same department ID in the three columns are merged.
This. margeCol (worksheet, 2, 2, dtExcel, "GongSiID ");
This. margeCol (worksheet, 2, 3, dtExcel, "BuMenId ");
margeCol(Microsoft.Office.Interop.Excel._Worksheet worksheet, rno, cno,DataTable dttemp, dcvalue = sron=rno; (DataRow dr (dcvalue != .Empty && dcvalue == rno = rno + ; dcvalue = (rno > rno = rno + sron = }