错误:一个表不能与Interop.Excel c#中的另一个表重叠

时间:2019-07-08 12:29:59

标签: c# excel interop office-interop excel-interop

我遇到错误A table can't overlap another table

一旦写了几行,我就试图写和同一时间格式的表。表格式是for循环的一部分。

方法1:

Range range = (Range)sheet.Range[sheet.Cells[fromRow, fromCol], sheet.Cells[toRow, toCol]];
ListObject x = sheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, range, Missing.Value, XlYesNoGuess.xlYes, Missing.Value);
x.TableStyle = "TableStyleMedium9";

迭代1:通过

fromRow = 3, fromCol = 2, toRow = 187, toCol = 8 // Passed

迭代2:失败

fromRow = 189, fromCol = 2, toRow = 271, toCol = 8 // Failed

方法2:

string r = GetExcelRangeName(fromRow, fromCol, toRow, toCol);
Range range = (Range)sheet.get_Range(r);
ListObject x = sheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, range, Missing.Value, XlYesNoGuess.xlYes, Missing.Value);
x.TableStyle = "TableStyleMedium9";

迭代1:通过

r = "B3:H187" // Passed

迭代2:失败

r = "B189:H271" //Failed

这很难调试。请帮忙。

0 个答案:

没有答案