문제

I am trying to use VSTO to clear the contents of a merged cell. I get an error of 'Can Not Change Merged Cell'. Is there a way to clear the contents of a merged cell in VSTO? This is the code I am using

wbExcel = oXL.ActiveWorkbook;
Worksheet ws = (Worksheet)wbExcel.ActiveSheet;
sheetExcel.Range["A4, A43, C10, F4"].Clear();
도움이 되었습니까?

해결책

If cells aren't part of a merged area, you can use the Range object like you did, otherwise clear the areas one-by-one:

sheetExcel.Range["A4"].MergeArea.Clear();
sheetExcel.Range["A43"].MergeArea.Clear();
sheetExcel.Range["C10"].MergeArea.Clear();
sheetExcel.Range["F4"].MergeArea.Clear();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top