Demo不会写诶……不好意思 还是把代码放上来请大神找找问题吧
private void ExportPages()
{
FarPoint.Win.Spread.FpSpread Spread = new FarPoint.Win.Spread.FpSpread();
FarPoint.Win.Spread.SheetViewCollection coll;
coll = fpSpread1.Sheets;
//Copy表头
fpSpread1.Sheets[0].ClipboardCopy(new CellRange(1, 1, 6, 12));
fpSpread1.Sheets[1].SetActiveCell(1, 1);
fpSpread1.Sheets[1].ClipboardPaste(ClipboardPasteOptions.All);
//Copy表尾
fpSpread1.Sheets[0].ClipboardCopy(new CellRange(30, 1, 1, 12));
fpSpread1.Sheets[1].SetActiveCell(12, 1);
fpSpread1.Sheets[1].ClipboardPaste(ClipboardPasteOptions.All);
//Copy数据区域
int numPages = 0;
if (_BillCount % 4 == 0) numPages = _BillCount / 4;
if (_BillCount % 4 != 0) numPages = _BillCount / 4 + 1;
for (int i = 0; i < _BillCount; i++)
{
if (i != 0 && i % 4 == 0)
{
string page = "第" + (i / 4).ToString() + "页 / 共" + numPages.ToString() + "页";
fpSpread1.Sheets[1].Cells.Get(18, 0).Text = page;
coll.Add(fpSpread1.Sheets[1]);
ClearDataField();
}
fpSpread1.Sheets[0].ClipboardCopy(new CellRange(i + 8, 1, 1, 12));
fpSpread1.Sheets[1].SetActiveCell(i % 4 + 8, 1);
fpSpread1.Sheets[1].ClipboardPaste(ClipboardPasteOptions.All);
if (i == _BillCount - 1)
{
string page = "第" + (i / 4 + 1).ToString() + "页 / 共" + numPages.ToString() + "页";
fpSpread1.Sheets[1].Cells.Get(18, 0).Text = page;
coll.Add(fpSpread1.Sheets[1]);
break;
}
}
for (int i = 0; i < coll.Count; i++)
{
Spread.Sheets.Add(coll);
}
this.Controls.Add(Spread);
for (int i = 0; i < coll.Count; i++)
{
Spread.Sheets.PrintInfo = _printInfo;
}
try
{
Spread.PrintSheet(-1); //打印控件的所有标签页
UIMessageUtil.ShowInformationMessage("导出PDF成功");
}
catch (Exception ex)
{
UIMessageUtil.ShowInformationMessage("导出PDF失败\n\n" + ex.Message);
}
return;
}
大致就是这个逻辑吧,我希望表头和表尾固定不变,只把中间的4行数据一次次地粘贴过来做成新的sheet
每做成一个sheet就收集起来,最后一起打印 |