private void PrintSaleInvoice(System.Data.DataTable dt) { try { int PageSize = 25; int TotalPages = dt.Rows.Count / 25; int remainder = dt.Rows.Count % 25; if (remainder > 0) { TotalPages++; } //FillInvoiceHeader(TotalPages); int iStart = 14; int pos = 0; int row = 0; m_TotalDiscount = 0; for (int page = 0; page < TotalPages; page++) { if (page > 0) { iStart = 51; } OpenTemplate(); FillInvoiceHeader(page + 1, TotalPages); for (int index = 0; index < PageSize; index++) { if (row >= dt.Rows.Count) { break; } pos = iStart + index; FillCellsWithData(dt, pos, row); row++; } if (page == TotalPages - 1) //Last page { if (TotalPages == 1) { pos = 39; } else { pos = 76; } string TotDiscountValue = "F" + pos.ToString(); Excel.Range TotDiscountValueCell = (Excel.Range)excelWorksheet.get_Range(TotDiscountValue, TotDiscountValue); TotDiscountValueCell.Value2 = m_TotalDiscount.ToString(); pos++; string TotalValue = "G" + pos.ToString(); Excel.Range TotalValueCell = (Excel.Range)excelWorksheet.get_Range(TotalValue, TotalValue); TotalValueCell.Value2 = m_InvoiceTotal.ToString(); } //excelWorkbook.SaveCopyAs("C:\\DEV\\MICS\\TEMPLATES\\inv" + page + ".xls"); if (page == 0) { excelWorksheet.PrintOut(1, 1, m_Copies, false, "", false, false, ""); } else { excelWorksheet.PrintOut(2, 2, m_Copies, false, "", false, false, ""); } excelWorkbook.Close(false, m_TemplatePath, true); } } catch (Exception ex) { excelWorkbook.Close(false, m_TemplatePath, true); throw(ex); } }
/// <summary> /// 打印并退出 /// </summary> /// <param name="xlsSheet"></param> private void PrintXls(Excel.Worksheet xlsSheet) { ((Excel._Worksheet)xlsSheet).Activate(); xlsSheet.PrintOut(); }