如何打印出excel的内容?
DBControl.PathStr = Application.StartupPath.Trim();
try
{
DBControl.DestinationFileName = DBControl.PathStr + @"\Report.xls";
DBControl.SourceFileName = DBControl.PathStr + @"\wxREPORT.xls"; // GRJHM-BDG3W-9P6TY-FB4WX-DKF9Y
try
{
System.IO.File.Delete(DBControl.DestinationFileName);
File.Copy(DBControl.SourceFileName, DBControl.DestinationFileName);
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
return;
}
Excel.Application xlApp = new Excel.Application(); //注意一定要有New,这样才能有EXCEL进程的接口实例
Excel.Workbook xlBook = xlApp.Workbooks.Add(DBControl.DestinationFileName); //不要用new,这一句已经使xlBook指向了实例
Excel.Worksheet xlSheet = (Excel.Worksheet)xlBook.Worksheets["分货类吞吐量"];
xlSheet.Activate();
xlSheet.Application.Visible = true;
//填报单位
DBControl.fillDsCompany();
for (int i=0;i<=DBControl.dsCompany.Tables[0].Rows.Count -1;i++)
{
if (DBControl.dsCompany.Tables[0].Rows[i]["companycode"].ToString()==DBControl.companyCode)
{
xlSheet.Cells[3,2]=DBControl.dsCompany.Tables[0].Rows[i]["companyname"].ToString();
}
}
//统计日期
xlSheet.Cells[3,8]=this.dtStartDate.Value.Year.ToString()+'/'+this.dtStartDate.Value.Month.ToString()+'/'+this.dtStartDate.Value.Day.ToString();
xlSheet.Cells[3,10]=this.dtEndDate.Value.Year.ToString()+'/'+this.dtEndDate.Value.Month.ToString()+'/'+this.dtEndDate.Value.Day.ToString();
//打印表体
for (int i=0;i<=ds.Tables[0].Rows.Count -1;i++)
{
for (int j=1;j<this.c1dbg.Columns.Count -1;j++)
{
xlSheet.Cells[6+i,j]=ds.Tables[0].Rows[i][j];
}
}
//单位负责人
xlSheet.Cells[ds.Tables[0].Rows.Count +7,1]="单位负责人:";
xlSheet.Cells[ds.Tables[0].Rows.Count +7,3]=this.txtFuzeren.Text;
//填报人
xlSheet.Cells[ds.Tables[0].Rows.Count +7,4]="填报人:";
xlSheet.Cells[ds.Tables[0].Rows.Count +7,5]=DBControl.UserName;
//填报日期
xlSheet.Cells[ds.Tables[0].Rows.Count +7,7]="填报日期:";
xlSheet.Cells[ds.Tables[0].Rows.Count +7,8]=System.DateTime.Today ;
//--------------------
Excel.Range r2=xlSheet.get_Range(xlSheet.Cells[6,1],xlSheet.Cells[ds.Tables[0].Rows.Count+5,10]);
r2.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = 7;
r2.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = 7;
r2.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = 7;
r2.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = 7;
// r2.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = 7;
r2.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = 7;
r2.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = 7;
xlSheet.PrintPreview(xlSheet);//???
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
在问号的位置可以打印欲揽,可是我不知道PrintOut方法怎么用的啊?