"Netoffice Excel" Excel merge Cells "original"

Source: Internet
Author: User

CSharp operation Excel uses open source native. NET assembly Netoffice, which is better in format compatibility.

Sometimes you need to merge cells when working with Excel

usingExceloffice =Netoffice.excelapi;usingOfficeapi =Netoffice.officeapi;//apply for a variable Privateexceloffice.application Excelapp;//in a method, define the followingExcelapp =Newexceloffice.application () {DisplayAlerts=false, EnableEvents=false            };//Add a new workbookExceloffice.workbook NewWorkbook =excelApp.Workbooks.Add ();//read the first sheetExceloffice.worksheet Newworksheet = newworkbook.worksheets[1] asExceloffice.worksheet; //merging A15 to E15Newworksheet.get_range ("A15","E15"). Merge (Newworksheet.get_range ("A15","E15").            MergeCells); newworksheet.cells[ the,1]. Value ="Hello World"; Exceloffice.range Excelrange= Newworksheet.get_range ("A15","E15");//set Text to center horizontallyExcelrange.horizontalalignment =ExcelOffice.Enums.XlHAlign.xlHAlignCenter;//Set Font sizeExcelRange.Font.Size = the;//Show ExcelExcelapp.visible =true;

Hope to be helpful to everyone

"Netoffice Excel" Excel merge Cells "original"

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.