我创建了一个应用程序,用于从Excel获取数据并从其数据中打印帐单。
我已成功打印,但我不知道如何计算Point(x,y)以将我的数据放入A6页面。
我将课程Express()
放入foreach loop
,但我想在1个A5页面中设置2个A6尺寸并继续foreach loop
。
喜欢这张图片:
这是我的代码:
private void Print(int id, PrintDialog dialogPop)
{
stt = id;
printDialog = dialogPop;
ExcelConnect excelLoad = new ExcelConnect(sFileName);
dtExcel = excelLoad.ExcelLoad("Sheet1");
foreach(DataRow dt in dtExcel.Rows)
{
stt = Int32.Parse(dt[0].ToString());
ten = dt[1].ToString();
Express();
}
}
private void Express()
{
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printDialog.PrinterSettings.PrinterName;
printDoc.PrinterSettings.Copies = printDialog.PrinterSettings.Copies;
printDoc.PrintPage += new PrintPageEventHandler(firstPage);
printDoc.Print();
}
private void firstPage(object sender, PrintPageEventArgs e)
{
// Logo
Image img = INGIAYGUIHANG.Properties.Resources.logo;
Bitmap logo = new Bitmap(img);
logo.SetResolution(198, 80);
// Header & Address
e.Graphics.DrawString("abc", new Font("Courier", 25), new SolidBrush(Color.Black), new Point(454, 25));
}