http://support.microsoft.com/default.aspx?scid=kb;zh-cn;317719

解决方案 »

  1.   

    private void daochu_all()
    {
    int i = 0;
    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.get_Range(excel.Cells[j,1],excel.Cells[j,11]).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=6+7+8+9+10";
    excel.get_Range(excel.Cells[j,1],excel.Cells[j,11]).Borders.LineStyle = 1;
    j++;
    for (i=0;i<myds.Tables["A"].Rows.Count;i++)
    {
    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.get_Range(excel.Cells[j,1],excel.Cells[j,11]).Borders.LineStyle = 1;
    j++;
    }
     
    j++;
     
    j++;
     
    MessageBox.Show("数据导出完毕。");
    this.Close();
    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;
    }
    }