how to detect merged cells in c# using MS interop excel -


i want detect merged cells either in row/entire sheet(preferable).here code

microsoft.office.interop.excel.application xl = new microsoft.office.interop.excel.application();  microsoft.office.interop.excel.workbook workbook = xl.workbooks.open(source); //microsoft.office.interop.excel.worksheet ws = (microsoft.office.interop.excel.worksheet)workbook.sheets[sheetnumber]; microsoft.office.interop.excel.worksheet ws = (microsoft.office.interop.excel.worksheet)workbook.worksheets[objinmemory._sheetname]; xl.screenupdating = false; ws.columns.clearformats(); ws.rows.clearformats(); int colcount = ws.usedrange.columns.count; int rowcount = ws.usedrange.rows.count; int strtrow = ws.usedrange.rows[1].row; int strtcol = ws.usedrange.columns[1].column;    microsoft.office.interop.excel.range objrange = null; 

neither piece of code

if (ws.cells.mergecells) {  } 

nor piece of code(only row1)

for (int j = strtcol; j < strtcol + colcount; j++) {     objrange = ws.cells[strtrow, j];      if (ws.cells[strtrow, j].mergecells)     {         message = "the sheet contains merged cells";         break;     }   } 

seem work..kindly let me know how check if sheet/specific range contains merged cells.

if want check if range contains merged cells, mergecells property you're after.

if range merged, return true. if range contains merged cells (i.e. merged, aren't), return dbnull.value.

so, should work entire sheet:

object mergecells = ws.usedrange.mergecells; var containsmergedcells = mergecells == dbnull.value || (bool)mergecells; 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -