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"