问题描述
我正在使用带有c#的excel interop我希望使用c#代码合并包含特定值的所有相邻单元格。
如何合并包含所有单元格使用c#代码的值(合并单元格)。
我尝试过:
我正在尝试这个,
String startRange =C2;
String endRange =C7;
String repetitiveValue =Merged Cells;
Microsoft.Office.Interop.Excel.Range xlrange =(Microsoft.Office.Interop.Excel.Range)objexcelapp.Cells [startRange,endRange ];
xlrange.Value2 = repetitiveValue;
xlrange.Merge(System.Reflection.Missing.Value);
I am using excel interop with c# I want to merge all adjacent cells that contain a specific value using c# code.
How to merge all the cells that contains the value (Merged cells) using c# code.
What I have tried:
I am trying this,
String startRange = "C2";
String endRange = "C7";
String repetitiveValue = "Merged Cells";
Microsoft.Office.Interop.Excel.Range xlrange = (Microsoft.Office.Interop.Excel.Range)objexcelapp.Cells[startRange, endRange];
xlrange.Value2 = repetitiveValue;
xlrange.Merge(System.Reflection.Missing.Value);
推荐答案
using (ExcelPackage pck = new ExcelPackage(newFile))
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Accounts");
ws.Cells["A1"].LoadFromDataTable(dataTable, true);
pck.Save();
}
这篇关于如何使用C#基于单元格值合并excel单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!