如何使用smartsheet C#SDK删除具有条件格式规则的列?

如何使用smartsheet C#SDK删除具有条件格式规则的列?,c#,smartsheet-api,C#,Smartsheet Api,如何使用smartsheet C#SDK删除具有条件格式规则的列 我们得到了一个错误- 指定的列用于条件格式规则,因此 无法删除列,也无法更改其类型。“ .您应该先删除列的条件格式,然后删除列。 意思是:错误的原因将消失 myRange是列的条件格式 提示1:您需要删除所有条件,这样就不需要if语句 foreach (Microsoft.Office.Interop.Excel.FormatCondition fc in myRange.FormatConditions) { if (fc.

如何使用smartsheet C#SDK删除具有条件格式规则的列

我们得到了一个错误-

指定的列用于条件格式规则,因此 无法删除列,也无法更改其类型。“


.

您应该先删除列的条件格式,然后删除列。 意思是:错误的原因将消失

myRange
是列的条件格式

提示1:您需要删除所有条件,这样就不需要
if
语句

foreach (Microsoft.Office.Interop.Excel.FormatCondition fc in myRange.FormatConditions)
{
  if (fc.Formula1 == whatever) // You don't need this if statement. bcz you want to delete all of them
  {
    fc.Delete();
  }
}
看看这个样品

@西德哈特路酒店


我希望这对您有所帮助。

@Mohamed_Shahrestani正确地认为,在删除列之前,必须删除应用于该列的任何条件格式规则。不幸的是,Smartsheet API目前似乎不支持管理条件格式规则,因此目前无法通过API实现这一点。删除应用了条件格式规则的列的唯一方法是首先手动(通过Smartsheet UI)从列中删除所有条件格式规则。

我认为您应该先删除条件格式,然后删除列。@MohamadShahrestani,如何使用smartsheet C#SDK删除列中的条件格式?我的问题是关于smartsheet的。但是讨论了excel条件格式。@BuddhadevKarmakar啊,好的,所以我不知道如何删除它;)
private void btnSearch_Click(object sender, EventArgs e)
{
    Microsoft.Office.Interop.Excel.Application xlexcel;
    Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
    Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

    xlexcel = new Excel.Application();
    xlexcel.Visible = true;

    //~~> Add a File
    xlWorkBook = xlexcel.Workbooks.Add();
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

    //~~> Create 2 Conditions
    xlWorkSheet.Cells[1, 1].FormatConditions.Add( 1,5,"=5");
    xlWorkSheet.Cells[1, 1].FormatConditions.Add(1, 5, "=10");

    MessageBox.Show("Wait");
    //~~> Now if you check the Excel file, Cell A1 has two conditional formats.
    //~~> See Snapshot 1

    //~~> Delete the first condition
    xlWorkSheet.Cells[1, 1].formatconditions(1).delete();

    MessageBox.Show("Wait");
    //~~> Now if you check the Excel file, Cell A1 has only 1 conditional format.
    //~~> See Snapshot 2
}