DataTable myTable = new DataTable("myTable"); PrintRowVersion(myTable, DataRowVersion.Current);
private void PrintRowVersion(DataTable dt, DataRowVersion ver){ // Print a new line and the version using the ReturnRowVersion function. Console.WriteLine("\n" + ver.ToString() + " Version:"); // Print the value of each column in each row. try{ foreach(DataRow row in dt.Rows ) { // Print the specified version of the row's value. Console.Write(row[0,ver] + ", "); Console.Write(row[1,ver] + "\n"); } } catch(Exception e) { // Process exception and return. System.Diagnostics.EventLog log = new System.Diagnostics.EventLog(); log.Source = "My Application"; log.WriteEntry(e.ToString()); Console.WriteLine("Exception of type {0} occurred.", e.GetType()); } }
PrintRowVersion(myTable, DataRowVersion.Current);
// Print a new line and the version using the ReturnRowVersion function.
Console.WriteLine("\n" + ver.ToString() + " Version:");
// Print the value of each column in each row.
try{
foreach(DataRow row in dt.Rows ) {
// Print the specified version of the row's value.
Console.Write(row[0,ver] + ", ");
Console.Write(row[1,ver] + "\n");
}
}
catch(Exception e) {
// Process exception and return.
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = "My Application";
log.WriteEntry(e.ToString());
Console.WriteLine("Exception of type {0} occurred.", e.GetType());
}
}
{
GoldPrinter.ExcelAccess excel = new GoldPrinter.ExcelAccess();
Print(excel);
excel.Print(); //
excel.Close();
} private void Print(GoldPrinter.ExcelAccess excel)
{
//制作步骤:
/* 1、用Excel作出与要打印的样式一样的电子表格存为模板;
* 技巧:最好把第一行与第一列作为空行,以利于调整边距(虽然Excel、打印机可调整页边距), 尽量的在需要调整的地方多空几行与几列,以利于调整套打对准
*
* 2、如同本程序一样,将Excel作为套打的模板,直接将要打印的数据写入;
*
* 3、打印,根据实际的效果调整Excel模板行高列宽及空出的行列, 直到能够准确的套上。*/
// GoldPrinter.ExcelAccess excel = new GoldPrinter.ExcelAccess();
string strFileName="";
string strExcelTemplateFile ="";
DateTime dtoday=System.DateTime.Now;
string strtoday=dtoday.ToShortDateString();
string stryear=dtoday.Year.ToString();
string strmonth=dtoday.Month.ToString();
string strday=dtoday.Day.ToString(); strFileName="Receipt-cw.xlt";
strExcelTemplateFile = this.getpath()+strFileName;
excel.Open(strExcelTemplateFile);
excel.FormCaption = "收费收据模板";
//在模板中写入要打印的数据
//第一联
excel.SetCellText(7,"D",X_MC.ToString());
excel.SetCellText(7,"G",XS_XH.ToString());
excel.SetCellText(8,"D",XS_XM.ToString());
excel.SetCellText(8,"G",strtoday);
excel.SetCellText(13,"C","补费");
excel.SetCellText(13,"F",totaljfje.ToString()); //第二联
excel.SetCellText(7,"L",X_MC.ToString());
excel.SetCellText(7,"O",XS_XH.ToString());
excel.SetCellText(8,"L",XS_XM.ToString());
excel.SetCellText(8,"O",strtoday);
excel.SetCellText(13,"C","补费");
excel.SetCellText(13,"F",totaljfje.ToString());
//第三联
excel.SetCellText(7,"T",X_MC.ToString());
excel.SetCellText(7,"W",XS_XH.ToString());
excel.SetCellText(8,"T",XS_XM.ToString());
excel.SetCellText(8,"W",strtoday);
excel.SetCellText(13,"C","补费");
excel.SetCellText(13,"F",totaljfje.ToString()); }