怎么增加,删除 excel中的某一行或某一列

解决方案 »

  1.   

    把Execl作为一个数据源来处理,就像操作表一样操作
      

  2.   

    我是想删除excel模板的某一行列,或插入某一行列.大侠能不能推荐一个简单的方法,
    具体点.有劳了
      

  3.   

    操作的方法是如果你想实现什么功能,就是EXCEL中自己建立一个宏,安你要求的操作,让宏记录下你的操作,把这段代码,再写进程序中,就可以了。
    private void daochu()
    {
    int i = mybind.Position;
    int j = 1;
    try
    {
    Excel.Application excel = new Excel.Application() ;
    excel.Application.Workbooks.Add(true);
    //excel.Visible = true;
    try
    {
    excel.Caption = "扣罚明细表";
    excel.Cells[j,2] = myds.Tables["A"].Rows[i]["会计期间"].ToString().Substring(0,4)+"年"+
    myds.Tables["A"].Rows[i]["会计期间"].ToString().Substring(4,2)+"月扣罚明细表";
    j++;
    //设置标题
    excel.Cells[j,1] = "会计期间";
    excel.Cells[j,2] = "部门编号";
    excel.Cells[j,3] = "部门名称";
    excel.Cells[j,4] = "人员编码";
    excel.Cells[j,5] = "人员姓名";
    excel.Cells[j,6] = "借款罚息";
    excel.Cells[j,7] = "压货罚息";
    excel.Cells[j,8] = "调整罚息";
    excel.Cells[j,9] = "处理呆死帐承担金额";
    excel.Cells[j,10] = "丢失药品承担金额";
    excel.Cells[j,11] = "发放赠品承担金额";
    excel.Cells[j,12] = "超半年未回款发票应扣税金";
    excel.Cells[j,13] = "发票税金返还";
    excel.Cells[j,14] = "其它扣罚";
    excel.Cells[j,15] = "当月通报罚款";
    excel.Cells[j,16] = "扣罚合计";
    excel.get_Range(excel.Cells[j,1],excel.Cells[j,16]).Borders.LineStyle = 1;

    j++; //写列号
    excel.Cells[j,1] = "1";
    excel.Cells[j,2] = "2";
    excel.Cells[j,3] = "3";
    excel.Cells[j,4] = "4";
    excel.Cells[j,5] = "5";
    excel.Cells[j,6] = "6";
    excel.Cells[j,7] = "7";
    excel.Cells[j,8] = "8";
    excel.Cells[j,9] = "9";
    excel.Cells[j,10] = "10";
    excel.Cells[j,11] = "11";
    excel.Cells[j,12] = "12";
    excel.Cells[j,13] = "13";
    excel.Cells[j,14] = "14";
    excel.Cells[j,15] = "15";
    excel.Cells[j,16] = "16=6+7+8+9+10+11+12-13+14+15";
    excel.get_Range(excel.Cells[j,1],excel.Cells[j,16]).Borders.LineStyle = 1;
     
    j++; excel.Cells[j,1] =  myds.Tables["A"].Rows[i]["会计期间"].ToString();
    excel.Cells[j,2] =  "'"+myds.Tables["A"].Rows[i]["部门编号"].ToString(); 
    excel.Cells[j,3] = myds.Tables["A"].Rows[i]["部门名称"].ToString();  
    excel.Cells[j,4] = "'"+myds.Tables["A"].Rows[i]["人员编号"].ToString(); 
    excel.Cells[j,5] =  myds.Tables["A"].Rows[i]["人员姓名"].ToString();;
    excel.Cells[j,6] =  myds.Tables["A"].Rows[i]["借款罚息"].ToString(); 
    excel.Cells[j,7] =  myds.Tables["A"].Rows[i]["压货罚息"].ToString(); 
    excel.Cells[j,8] =  myds.Tables["A"].Rows[i]["调整罚息"].ToString(); 
    excel.Cells[j,9] =  myds.Tables["A"].Rows[i]["处理呆死帐承担金额"].ToString(); 
    excel.Cells[j,10] = myds.Tables["A"].Rows[i]["丢失药品承担金额"].ToString();  
    excel.Cells[j,11] =  myds.Tables["A"].Rows[i]["发放赠品承担金额"].ToString(); 
    excel.Cells[j,12] =  myds.Tables["A"].Rows[i]["超半年未回款应扣税金"].ToString(); 
    excel.Cells[j,13] =  myds.Tables["A"].Rows[i]["发票税金返还"].ToString(); 
    excel.Cells[j,14] =  myds.Tables["A"].Rows[i]["其它扣罚"].ToString(); 
    excel.Cells[j,15] = myds.Tables["A"].Rows[i]["当月通报罚款"].ToString();  
    excel.Cells[j,16] = myds.Tables["A"].Rows[i]["扣罚合计"].ToString();  
    excel.get_Range(excel.Cells[j,1],excel.Cells[j,16]).Borders.LineStyle = 1;
    j++;
    j++;
    excel.Visible = true;
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    excel.Quit();
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("没有安装EXCEL。"+"\n"+ex.Message);
    }
    finally
    {
    this.dcbz = false;
    }

    }
      

  4.   

    怎么插入,删除 excel中的某一行或某一列
      

  5.   

    用excel中录制宏试试,看看删除的命令是什么
      

  6.   

    使用range的delete方法.
    Range r = (Range)xSheet.Columns[1, Type.Missing];
    r.Delete(0);
      

  7.   

    Columns("D:D").Delete   '删除列
        Columns("D:D").Insert   '增加列
        Rows("10:10").Delete   '删除行
        Rows("12:12").Insert   '增加行
      

  8.   

    楼上的Columns 和Rows没有Delete和Insert涵数
      

  9.   


    给SHEET页负值的,你参考下:
    public static void SetWorkSheetName (string fileName ,int sheetIndex,string sheetName)
    {
    Excel.Application objApp;
    Excel.Workbooks objBooks;
    Excel._Workbook objBook;
    Excel.Sheets objSheets;
    Excel._Worksheet objSheet;objApp = myApp;
    objApp.Visible = false;
    objBooks = objApp.Workbooks;try
    {
    objBook = objBooks.Open(fileName,Type.Missing ,Type.Missing ,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
    objSheets = objBook.Worksheets;if ((sheetIndex > objSheets.Count )|| (sheetIndex <= 0 ))
    {
    throw new Exception("工作表索引超出范围!");
    }objSheet = (Excel._Worksheet)objSheets.get_Item(sheetIndex);
    objSheet.Name = sheetName ;
    objBook.Save();}
    catch(Exception theException)
    {
    String errorMessage;
    errorMessage = "Error: ";
    errorMessage = String.Concat( errorMessage, theException.Message );
    errorMessage = String.Concat( errorMessage, " Line: " );
    errorMessage = String.Concat( errorMessage, theException.Source );
    }
    finally
    {
    objApp.UserControl = true ;
    objApp.Quit();
    }return ;
    }