Merge the same content columns in Table + merge the same content columns in Excel.

Source: Internet
Author: User

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 =                                               }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.