to zhangzgl: thanks!the program haven't Excel powerful functions, such as visualization.
how to integrate the program and Excel? when the excel change something,the program also change automatically.
我的这个小工具是按照要求做的,所以并未实现强大的功能,Excel Com 还有很多功能,请看这两个帖子,看看对你的问题是否有帮助 http://dev.csdn.net/develop/article/9/9531.shtm http://dev.csdn.net/develop/article/9/9530.shtm
Excel怎么作为插件,在.net环境中?
no man has this experience? So should i can my method? i will go out for two days. I hope someone will give me a help during this time. thanks a lot!
http://www.codeproject.com/dotnet/ExportExcelData.asp
http://www.codeproject.com/csharp/csharp_excel.asp
Any help will be appreciated and paid back with point;-)
可否给我一份,拜托了
[email protected]
thanks!the program haven't Excel powerful functions, such as visualization.
when the excel change something,the program also change automatically.
http://dev.csdn.net/develop/article/9/9531.shtm
http://dev.csdn.net/develop/article/9/9530.shtm
i will go out for two days. I hope someone will give me a help during this time.
thanks a lot!
C:\Program Files\Microsoft Office\Office10\1033
{
Excel.Application excel = new Excel.Application() ;
excel.Application.Workbooks.Add(true);
//excel.Visible = true;
try
{
excel.Caption = "内部对帐单";
for (i=0;i<myds.Tables["mytable"].Rows.Count;i++)
{
this.progressBar1.Value = this.progressBar1.Value +1;
excel.Cells[j,2] = myds.Tables["mytable"].Rows[i]["kjqj"].ToString().Substring(0,4)+"年"+
myds.Tables["mytable"].Rows[i]["kjqj"].ToString().Substring(4,2)+"月营销员内部对帐单";
j++;
excel.Cells[j,1] = myds.Tables["mytable"].Rows[i]["dqmc"].ToString()+
myds.Tables["mytable"].Rows[i]["bmmc"].ToString()+
myds.Tables["mytable"].Rows[i]["ryxm"].ToString()+"业务员";
j++;
excel.Cells[j,1] = "现将你"+myds.Tables["mytable"].Rows[i]["kjqj"].ToString()+"月份帐目情况给你,请你核对无误后签字。";
j++;
excel.Cells[j,1] = "一、货款情况";
j++;
excel.Cells[j,1] = "本月发货";
excel.get_Range(excel.Cells[j,1],excel.Cells[j,1]).Borders.LineStyle = 1;
excel.Cells[j,2] = "本年发货";
excel.get_Range(excel.Cells[j,2],excel.Cells[j,2]).Borders.LineStyle = 1;
excel.Cells[j,3] = "本月回款";
excel.get_Range(excel.Cells[j,3],excel.Cells[j,3]).Borders.LineStyle = 1;
excel.Cells[j,4] = "本年回款";
excel.get_Range(excel.Cells[j,4],excel.Cells[j,4]).Borders.LineStyle = 1;
excel.Cells[j,5] = "上年末欠款";
excel.get_Range(excel.Cells[j,5],excel.Cells[j,5]).Borders.LineStyle = 1;
excel.Cells[j,6] = "本年欠款";
excel.get_Range(excel.Cells[j,6],excel.Cells[j,6]).Borders.LineStyle = 1;
excel.Cells[j,7] = "累计欠款";
excel.get_Range(excel.Cells[j,7],excel.Cells[j,7]).Borders.LineStyle = 1;
excel.Cells[j,8] = "本年回款率";
excel.get_Range(excel.Cells[j,8],excel.Cells[j,8]).Borders.LineStyle = 1;
excel.Cells[j,9] = "累计回款率";
excel.get_Range(excel.Cells[j,9],excel.Cells[j,9]).Borders.LineStyle = 1;
j++;
excel.Cells[j,1] = myds.Tables["mytable"].Rows[i]["byfh"].ToString();
excel.get_Range(excel.Cells[j,1],excel.Cells[j,1]).Borders.LineStyle = 1;
excel.Cells[j,2] = myds.Tables["mytable"].Rows[i]["bnfh"].ToString();
excel.get_Range(excel.Cells[j,2],excel.Cells[j,2]).Borders.LineStyle = 1;
excel.Cells[j,3] = myds.Tables["mytable"].Rows[i]["byhk"].ToString();
excel.get_Range(excel.Cells[j,3],excel.Cells[j,3]).Borders.LineStyle = 1;
excel.Cells[j,4] = myds.Tables["mytable"].Rows[i]["bnhk"].ToString();
excel.get_Range(excel.Cells[j,4],excel.Cells[j,4]).Borders.LineStyle = 1;
excel.Cells[j,5] = myds.Tables["mytable"].Rows[i]["snqk"].ToString();
excel.get_Range(excel.Cells[j,5],excel.Cells[j,5]).Borders.LineStyle = 1;
excel.Cells[j,6] = myds.Tables["mytable"].Rows[i]["bnqk"].ToString();
excel.get_Range(excel.Cells[j,6],excel.Cells[j,6]).Borders.LineStyle = 1;
excel.Cells[j,7] = myds.Tables["mytable"].Rows[i]["ljqk"].ToString();
excel.get_Range(excel.Cells[j,7],excel.Cells[j,7]).Borders.LineStyle = 1;
excel.Cells[j,8] = myds.Tables["mytable"].Rows[i]["bnhkl"].ToString();
excel.get_Range(excel.Cells[j,8],excel.Cells[j,8]).Borders.LineStyle = 1;
excel.Cells[j,9] = myds.Tables["mytable"].Rows[i]["ljhkl"].ToString();
excel.get_Range(excel.Cells[j,9],excel.Cells[j,9]).Borders.LineStyle = 1;
j++;
excel.Cells[j,1] = "二、借款情况";
j++;
excel.Cells[j,1] = "累计借款";
excel.get_Range(excel.Cells[j,1],excel.Cells[j,1]).Borders.LineStyle = 1;
excel.Cells[j,2] = "本月借款";
excel.get_Range(excel.Cells[j,2],excel.Cells[j,2]).Borders.LineStyle = 1;
excel.Cells[j,3] = "本月回款";
excel.get_Range(excel.Cells[j,3],excel.Cells[j,3]).Borders.LineStyle = 1;
excel.Cells[j,4] = "本月提成合计";
excel.get_Range(excel.Cells[j,4],excel.Cells[j,4]).Borders.LineStyle = 1;
excel.Cells[j,5] = "结转上月扣除后剩余提成为负";
excel.get_Range(excel.Cells[j,5],excel.Cells[j,5]).Borders.LineStyle = 1;
excel.Cells[j,6] = "本月扣罚合计";
excel.get_Range(excel.Cells[j,6],excel.Cells[j,6]).Borders.LineStyle = 1;
excel.Cells[j,7] = "本月扣除后剩余提成";
excel.get_Range(excel.Cells[j,7],excel.Cells[j,7]).Borders.LineStyle = 1;
excel.Cells[j,8] = "应贴票金额";
excel.get_Range(excel.Cells[j,8],excel.Cells[j,8]).Borders.LineStyle = 1;
excel.Cells[j,9] = "累计投入中途差旅费";
excel.get_Range(excel.Cells[j,9],excel.Cells[j,9]).Borders.LineStyle = 1;
excel.Cells[j,10] ="短途差旅费";
excel.get_Range(excel.Cells[j,10],excel.Cells[j,10]).Borders.LineStyle = 1;
excel.Cells[j,11] ="累计欠款";
excel.get_Range(excel.Cells[j,11],excel.Cells[j,11]).Borders.LineStyle = 1;
excel.Cells[j,12] ="个人所得税";
excel.get_Range(excel.Cells[j,12],excel.Cells[j,12]).Borders.LineStyle = 1;
j++;
excel.Cells[j,1] = myds.Tables["mytable"].Rows[i]["ljjkye"].ToString();
excel.get_Range(excel.Cells[j,1],excel.Cells[j,1]).Borders.LineStyle = 1;
excel.Cells[j,2] = myds.Tables["mytable"].Rows[i]["byjk"].ToString();
excel.get_Range(excel.Cells[j,2],excel.Cells[j,2]).Borders.LineStyle = 1;
excel.Cells[j,3] = myds.Tables["mytable"].Rows[i]["byhk"].ToString();
excel.get_Range(excel.Cells[j,3],excel.Cells[j,3]).Borders.LineStyle = 1;
excel.Cells[j,4] = myds.Tables["mytable"].Rows[i]["bytchj"].ToString();
excel.get_Range(excel.Cells[j,4],excel.Cells[j,4]).Borders.LineStyle = 1;
excel.Cells[j,5] = myds.Tables["mytable"].Rows[i]["jzsytc"].ToString();
excel.get_Range(excel.Cells[j,5],excel.Cells[j,5]).Borders.LineStyle = 1;
excel.Cells[j,6] = myds.Tables["mytable"].Rows[i]["bykfhj"].ToString();
excel.get_Range(excel.Cells[j,6],excel.Cells[j,6]).Borders.LineStyle = 1;
excel.Cells[j,7] = myds.Tables["mytable"].Rows[i]["bytcsy"].ToString();
excel.get_Range(excel.Cells[j,7],excel.Cells[j,7]).Borders.LineStyle = 1;
excel.Cells[j,8] = myds.Tables["mytable"].Rows[i]["ytpje"].ToString();
excel.get_Range(excel.Cells[j,8],excel.Cells[j,8]).Borders.LineStyle = 1;
excel.Cells[j,9] = myds.Tables["mytable"].Rows[i]["ljtyclf"].ToString();
excel.get_Range(excel.Cells[j,9],excel.Cells[j,9]).Borders.LineStyle = 1;
excel.Cells[j,10] =myds.Tables["mytable"].Rows[i]["dtclf"].ToString();
excel.get_Range(excel.Cells[j,10],excel.Cells[j,10]).Borders.LineStyle = 1;
excel.Cells[j,11] =myds.Tables["mytable"].Rows[i]["ljqk"].ToString();
excel.get_Range(excel.Cells[j,11],excel.Cells[j,11]).Borders.LineStyle = 1;
excel.Cells[j,12] =myds.Tables["mytable"].Rows[i]["grsds"].ToString();
excel.get_Range(excel.Cells[j,12],excel.Cells[j,12]).Borders.LineStyle = 1;
j++;
excel.Cells[j,1] = "要求:请在20日之前将内部对帐签字后返回公司,如有疑问,请填写查帐申请。";
j++;
excel.Cells[j,1] = "若不按时返回或不合格,将停止借款或发货。";
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);
}
http://community.csdn.net/Expert/TopicView.asp?id=3233333/////////////////////////////////////////////////////////
我用下列方法打开Excel(来自网上例子)
string strFileName = "a.xls";
Object refmissing = System.Reflection.Missing.Value;
axWebBrowser1.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing);axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing);
出错在最后一句,ExceWB的作用是显示操作excel的图标按钮,如果没有这句,可以正常打开Excel,但对Excel的可操作性有限!出错信息是:
未处理异常System.Runtime.InteropServices.COMException出现在axinterop.shdocvw.dll中
其他信息:试图吊销一个未注册的拖放目标
////////////////////////////////////////////////////////////////////////////
自己看。
具体实现方法:你可以用Excel建一个模板出来保存在系统目录或你自己的系统的目录下面,然后,使用你自己开发的界面来完成你要实现的功能。不是一样吗?
比如:可以把Excel里面的所有界面改为自己的。只是风格与传统Excel一致。这不是什么难点。
难点主要是在你要实现的功能如何在Excel里面表现出来而已。
我主要是想利用Excel强大的数据可视化功能,需保存回程序
就以Excel文件保存就可以了
xBk.SaveAs(fileName,Missing.Value,
Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Excel.XlSaveAsAccessMode.xlExclusive,Missing.Value,
Missing.Value,Missing.Value,
Missing.Value,Missing.Value);
这一句就是保存Excel的语句。
其中,你要添加引用:using System.Reflection;与:using Excel;
xBk是Excel._Workbook xBk;
可以完成你想要的功能。而fileName就是你要保存的文件名。
Type.Missing,Type.Missing,Type.Missing,
Excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
excel.Quit();
然后操作Application对象里的东西。别的没什么,但要记得先引用一下