各位在winform中怎么实现报表的打印预览和打印功能?? 我是把数据导入到EXCEL文件中,用EXCEL打印的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 具体程序代码如下://连接数据库,准备循环取得每行记录的内容 string Strconnection; SqlCommand mySqlcommand; SqlConnection sqlconn; SqlDataAdapter Dbread; Dbread= new SqlDataAdapter(); Strconnection="data Source=localhost;initial catalog=Plan;persist security info=False;User id=sa;workstation id=localhost;packet size=4096"; sqlconn= new SqlConnection(Strconnection); try { sqlconn.Open(); } catch(Exception a) { MessageBox.Show(a.ToString()); } mySqlcommand=new SqlCommand("select * from TJGL ",sqlconn); DataSet DS=new DataSet(); Dbread.SelectCommand=mySqlcommand; Dbread.SelectCommand.ExecuteNonQuery(); Dbread.Fill(DS,"TJGL"); //建立EXCEL对象,对EXCEL进行操作 Excel.Application oXL; Excel._Workbook oWB; Excel._Worksheet oSheet; Excel.Range oRng; try { //开始设置Excel对象 oXL= new Excel.ApplicationClass(); oXL.Visible=true; //Get a new workbook oWB= (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value)); oSheet=(Excel._Worksheet)oWB.ActiveSheet; //填写表头 oSheet.Cells[1,1]="工作项目"; oSheet.Cells[1,2]="技术要求"; oSheet.Cells[1,3]="时间"; oSheet.Cells[1,4]="劳动标准(天/人)"; oSheet.Cells[1,5]="次数"; oSheet.Cells[1,6]="金额(元/亩)"; oSheet.Cells[1,7]="其他"; //格式化表格内容 oSheet.get_Range("A1","G1").Font.Bold=true; oSheet.get_Range("A1","G1").VerticalAlignment=Excel.XlVAlign.xlVAlignCenter; oRng= oSheet.get_Range("A1","G1"); oRng.EntireColumn.AutoFit(); //填写数据库中的内容到相应的字段下 for( int i=2;i<DS.Tables["TJGL"].Rows.Count+1; i++) { string[,] saNames= new string[1,7]; oSheet.Cells[i,1]=DS.Tables["TJGL"].Rows[i].ItemArray[1].ToString(); oSheet.Cells[i,2]=DS.Tables["TJGL"].Rows[i].ItemArray[3].ToString(); oSheet.Cells[i,3]=DS.Tables["TJGL"].Rows[i].ItemArray[4].ToString(); oSheet.Cells[i,4]=DS.Tables["TJGL"].Rows[i].ItemArray[5].ToString(); oSheet.Cells[i,5]=DS.Tables["TJGL"].Rows[i].ItemArray[6].ToString(); oSheet.Cells[i,6]=DS.Tables["TJGL"].Rows[i].ItemArray[7].ToString(); oSheet.Cells[i,7]=DS.Tables["TJGL"].Rows[i].ItemArray[8].ToString(); //oRng= oSheet.get_Range("C2","C6"); 使用EXCEL里面得运算格式 //oRng.Formula="=A2&\"\"& B2"; oRng=oSheet.get_Range("F2","F"+DS.Tables["TJGL"].Rows.Count); oRng.NumberFormat="¥0.00";oXL.Visible=true; oXL.UserControl=true; } } catch (Exception theException) { String errorMessage; errorMessage="Error:"; errorMessage=String.Concat(errorMessage,theException.Message); errorMessage=String.Concat(errorMessage,"Line:"); errorMessage=String.Concat(errorMessage,theException.Source); MessageBox.Show(errorMessage,"Error"); } 我确定得crystal report会比EXECL好,使用起来都简单. laser0126(风铃草) ,谢谢你,有没有办法把公司的标志之类的图片插入?另外,这种方法不能实现预览功能,还要客户自己再处理一遍,你有没有做过直接输出到打印机的那种??henryfan1(henry) ,使用crystal report,我没有用过,刚才我简单看了一下,好象和vf中自定义报表差不多,我听说这个组件要注册,我如果现在写好给客户,会不会出现过期之类的问题?你有没有具体应用的例子介绍介绍?? FTP 上传如何判断指定地址的FTP服务器有没有连接上? session 丢失 进入后台点几下就退出来了! grideview去某列的值 同一个treeview中节点的拖放? 奇怪的问题 大家来看看 来帮忙 《.NET企业服务框架》第15章的例子报错,请思归、速马和正在看此书的朋友解答一下吧。ps:提供书中的配套代码,有朋友说书中的网站不能下 在C#如何调用存储过程中返回多个值. 如何将html格式的数据直接保存成word文件 怎么对在程序运行时才生成的新控件进行操作(拖放 ,移动)? .net北京工作机会 关于stream reader的简单问题 小弟的第一本书,请大家批评
//连接数据库,准备循环取得每行记录的内容
string Strconnection;
SqlCommand mySqlcommand;
SqlConnection sqlconn;
SqlDataAdapter Dbread; Dbread= new SqlDataAdapter();
Strconnection="data Source=localhost;initial catalog=Plan;persist security info=False;User id=sa;workstation id=localhost;packet size=4096";
sqlconn= new SqlConnection(Strconnection);
try
{
sqlconn.Open();
}
catch(Exception a)
{
MessageBox.Show(a.ToString());
}
mySqlcommand=new SqlCommand("select * from TJGL ",sqlconn);
DataSet DS=new DataSet();
Dbread.SelectCommand=mySqlcommand;
Dbread.SelectCommand.ExecuteNonQuery();
Dbread.Fill(DS,"TJGL");
//建立EXCEL对象,对EXCEL进行操作
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;
try
{
//开始设置Excel对象
oXL= new Excel.ApplicationClass();
oXL.Visible=true;
//Get a new workbook
oWB= (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet=(Excel._Worksheet)oWB.ActiveSheet; //填写表头
oSheet.Cells[1,1]="工作项目";
oSheet.Cells[1,2]="技术要求";
oSheet.Cells[1,3]="时间";
oSheet.Cells[1,4]="劳动标准(天/人)";
oSheet.Cells[1,5]="次数";
oSheet.Cells[1,6]="金额(元/亩)";
oSheet.Cells[1,7]="其他"; //格式化表格内容
oSheet.get_Range("A1","G1").Font.Bold=true;
oSheet.get_Range("A1","G1").VerticalAlignment=Excel.XlVAlign.xlVAlignCenter;
oRng= oSheet.get_Range("A1","G1");
oRng.EntireColumn.AutoFit(); //填写数据库中的内容到相应的字段下
for( int i=2;i<DS.Tables["TJGL"].Rows.Count+1; i++)
{
string[,] saNames= new string[1,7];
oSheet.Cells[i,1]=DS.Tables["TJGL"].Rows[i].ItemArray[1].ToString();
oSheet.Cells[i,2]=DS.Tables["TJGL"].Rows[i].ItemArray[3].ToString();
oSheet.Cells[i,3]=DS.Tables["TJGL"].Rows[i].ItemArray[4].ToString();
oSheet.Cells[i,4]=DS.Tables["TJGL"].Rows[i].ItemArray[5].ToString();
oSheet.Cells[i,5]=DS.Tables["TJGL"].Rows[i].ItemArray[6].ToString();
oSheet.Cells[i,6]=DS.Tables["TJGL"].Rows[i].ItemArray[7].ToString();
oSheet.Cells[i,7]=DS.Tables["TJGL"].Rows[i].ItemArray[8].ToString();
//oRng= oSheet.get_Range("C2","C6"); 使用EXCEL里面得运算格式
//oRng.Formula="=A2&\"\"& B2";
oRng=oSheet.get_Range("F2","F"+DS.Tables["TJGL"].Rows.Count);
oRng.NumberFormat="¥0.00";
oXL.Visible=true;
oXL.UserControl=true;
}
}
catch (Exception theException)
{
String errorMessage;
errorMessage="Error:";
errorMessage=String.Concat(errorMessage,theException.Message);
errorMessage=String.Concat(errorMessage,"Line:");
errorMessage=String.Concat(errorMessage,theException.Source); MessageBox.Show(errorMessage,"Error");
}