现在用spread设定一个打印模板,因为打印纸张大小,这个sheet中共有11行表格,0-5是表头,6-11行是动态填充数据,一页纸只能打印11行数据,
但是从数据库中获取的数据大于11行,需自动分页打印,但每页都需表头。
PrintInfo pi = new PrintInfo();
fprint = new FpSpread();
FarPoint.Win.Spread.SheetViewCollection coll;
coll = fprint.Sheets;
pi.Orientation = PrintOrientation.Auto;
pi.PageOrder = PrintPageOrder.Auto;
pi.ShowPrintDialog = true;
pi.PrintNotes = PrintNotes.AtEnd;
pi.ShowColumnHeaders = false;
pi.ShowGrid = true;
pi.ShowPrintDialog = true;
pi.ShowRowHeaders = false;
pi.ShowShadows = true;
pi.UseSmartPrint = true;
pi.PrintNotes = PrintNotes.AtEnd;
int b = dt.Rows.Count;
int a = 6;
for (int i = 0; i < b; i++)
{
fpSpread1.ActiveSheet.Cells[a, 1].Text = (i + 1).ToString();
fpSpread1.ActiveSheet.Cells[a, 2].Text = dt.Rows[0].ToString();
fpSpread1.ActiveSheet.Cells[a, 3].Text = dt.Rows[1].ToString();
fpSpread1.ActiveSheet.Cells[a, 4].Text = dt.Rows[2].ToString();
fpSpread1.ActiveSheet.Cells[a, 5].Text = dt.Rows[4].ToString();
fpSpread1.ActiveSheet.Cells[a, 6].Text = dt.Rows[3].ToString();
this.fpSpread1.ActiveSheet.Rows[a].VerticalAlignment = CellVerticalAlignment.Top;
a = a + 1;
if ((i + 1) % 6 == 0)
{
coll.Add(CopySheet(fpSpread1.ActiveSheet, (i + 1).ToString()));
a = 6;
}
}
for (int k = 0; k < coll.Count; k++)
{
fprint.Sheets.Add(coll[k]);
}
for (int j = 0; j < this.fprint.Sheets.Count; j++)
{
fprint.Sheets[j].PrintInfo = pi;
fprint.PrintSheet(j);
}
fprint.Sheets.Add(coll[k]); 只保留最后一个的sheet数据,打印数据都是重复的 |
|