1)打印,拖入一個 gridEXPrintDocument1控件
設置它的gridex屬性:gridex=GridExProduct; PageHeaderCenter = "物料明細表";
private void btnPrint_Click(object sender, EventArgs e)
{
FrmPrint frm = new FrmPrint(this);//frmprint,顯示打印的窗口,有個printPreviewControl1就可以了
frm.printPreviewControl1.Document = gridEXPrintDocument1;
frm.WindowState = FormWindowState.Maximized;
frm.ShowDialog();
}
//要打印,只要在 FrmPrint 裏調用ofrm.gridEXPrintDocument1.Print();//ofrm:btnPrint_Click所在的頁面
2. 輸出到execl 拖入一個 gridEXExporter1控件
private void btnExecl_Click(object sender, EventArgs e)
{
string saveFileName = "";
// bool fileSaved=false;
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "xls";
saveDialog.Filter = "Excel文件|*.xls";
saveDialog.FileName = "Sheet1";
saveDialog.ShowDialog();
saveFileName = saveDialog.FileName;
if (saveFileName.IndexOf(":") < 0) return;
gridEXExporter1.SheetName = gridEXPrintDocument1.PageHeaderCenter.ToString();
FileStream fs = new FileStream(saveFileName, FileMode.CreateNew);
gridEXExporter1.Export(fs);
}
這樣就可以簡單方便的實現打印和輸出到 excel的功能了。。