删除线财产

时间:2013-06-25 10:50:16

标签: c# excel c#-4.0

如何使用c#删除excel表中的删除行?

我试过这个:

{
    Excel.Application app = new Excel.Application();
    Excel.Workbook workbook = app.Workbooks.Open("D:/Excel.xlsx", Type.Missing, Type.Missing, 
                                                  Type.Missing, Type.Missing, Type.Missing, 
                                                  Type.Missing, Type.Missing, Type.Missing, 
                                                  Type.Missing, Type.Missing, Type.Missing, 
                                                  Type.Missing, Type.Missing, Type.Missing);

    Excel.Worksheet ws = (Excel.Worksheet)app.Sheets["Production_2013"];
    Excel.Range range = ws.get_Range("A5", "T10");
    string clean_string = CleanStrikethroughChars(range);
}

string CleanStrikethroughChars(Excel.Range range) {
    string s = "";
    int char_index = 1;
    int length = range.Cells.Value2.ToString().Length;

    while (char_index < length) {
        if ((bool)range.Cells.get_Characters(char_index, 1).Font.Strikethrough) {
            s += range.Cells.get_Characters(char_index, 1).Text;
            char_index++;
        }
    }
    return s;

1 个答案:

答案 0 :(得分:0)

确定如何使用Excel interops执行操作的最佳方法之一是在Excel中创建预期操作的宏,然后查看生成的VBA代码。这可能会提示如何做所需的事情。