private void btnReport_Click(object sender, EventArgs e) { try { RtfDocument doc = new RtfDocument(PaperSize.A4, PaperOrientation.Portrait, Lcid.Russian); RtfParagraph p = doc.addParagraph(); p.Alignment = Align.Center; p.DefaultCharFormat.FontSize = 14.0f; p.DefaultCharFormat.FontStyle.addStyle(FontStyleFlag.Bold); p.Text = "Статистика баллов ЕГЭ по регионам"; if (chbEntered.Checked) { p.Text += " среди зачисленных абитуриентов"; } doc.addParagraph().Text = ""; p = doc.addParagraph(); p.Alignment = Align.Left; if (FacultyId.HasValue) { p.Text = cbFaculty.Text; } else { p.Text = "По всему университету"; } if (LicenseProgramId.HasValue) { p = doc.addParagraph(); p.Alignment = Align.Left; p.Text = "Направление: " + cbLicenseProgram.Text; } if (ObrazProgramId.HasValue) { p = doc.addParagraph(); p.Alignment = Align.Left; p.Text = "Образовательная программа: " + cbObrazProgram.Text; } p = doc.addParagraph(); //p.LineSpacing = RtfConstants.MILLIMETERS_TO_POINTS if (StudyFormId.HasValue) { p.Text = "Форма обучения: " + cbStudyForm.Text; } else { p.Text = "Все формы обучения"; } p = doc.addParagraph(); //p.LineSpacing = RtfConstants.MILLIMETERS_TO_POINTS if (StudyFormId.HasValue) { p.Text = "Основа обучения: " + cbStudyBasis.Text; } else { p.Text = "Все основы обучения"; } p = doc.addParagraph(); //p.LineSpacing = RtfConstants.MILLIMETERS_TO_POINTS p.Text = "Предмет: " + cbEgeExamName.Text; doc.addParagraph().Text = ""; RtfTable table = doc.addTable(dgv.Rows.Count + 1, dgv.ColumnCount); table.setInnerBorder(RtfWriter.BorderStyle.Single, 0.25f); table.setOuterBorder(RtfWriter.BorderStyle.Single, 0.25f); //заголовки for (int i = 0; i < dgv.ColumnCount; i++) { table.cell(0, i).Alignment = Align.Center; table.cell(0, i).addParagraph().Text = dgv.Columns[i].Name; } table.setColWidth(0, (float)(60.0m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(1, (float)(25.0m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(2, (float)(20.0m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(3, (float)(20.0m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(4, (float)(20.0m * RtfConstants.MILLIMETERS_TO_POINTS)); DataView dv = new DataView((DataTable)dgv.DataSource); dv.Sort = "Кол-во абитуриентов DESC"; int rowId = 1; foreach (DataRow rw in dv.ToTable().Rows) { int colId = 0; foreach (DataColumn col in dv.ToTable().Columns) { var par = table.cell(rowId, colId).addParagraph(); par.Text = rw[col.ColumnName].ToString(); par.Alignment = Align.Center; colId++; } //запрет переноса строк table.setRowKeepInSamePage(rowId++, false); } doc.save(MainClass.saveTempFolder + "/Report.rtf"); System.Diagnostics.Process.Start(MainClass.saveTempFolder + "/Report.rtf"); } catch (Exception ex) { WinFormsServ.Error(ex.Message); } }
public void SetRowKeepInSamePageTest() { var rtfTable = new RtfTable(3, 3, 20, 20); Assert.DoesNotThrow(() => rtfTable.setRowKeepInSamePage(1, true)); }
public void ShouldThrowExceptionWhenRowKeepInSamePageIsNegative() { var rtfTable = new RtfTable(3, 3, 20, 20); Assert.Throws <Exception>(() => rtfTable.setRowKeepInSamePage(-1, false)); }
private void btnReport_Click(object sender, EventArgs e) { try { RtfDocument doc = new RtfDocument(PaperSize.A4, PaperOrientation.Landscape, Lcid.Russian); RtfParagraph p = doc.addParagraph(); p.Alignment = Align.Center; p.DefaultCharFormat.FontSize = 14.0f; p.DefaultCharFormat.FontStyle.addStyle(FontStyleFlag.Bold); p.Text = string.Format("Статистика по регионам по {0}абитуриентам", chbEntered.Checked ? "зачисленным " : ""); doc.addParagraph().Text = ""; p = doc.addParagraph(); p.Alignment = Align.Left; p.Text = "По региону: " + cbRegion.Text; p = doc.addParagraph(); //p.LineSpacing = RtfConstants.MILLIMETERS_TO_POINTS if (StudyFormId.HasValue) { p.Text = "Форма обучения: " + cbStudyForm.Text; } else { p.Text = "Все формы обучения"; } doc.addParagraph().Text = ""; RtfTable table = doc.addTable(dgv.Rows.Count + 1, dgv.ColumnCount); table.setInnerBorder(RtfWriter.BorderStyle.Single, 0.25f); table.setOuterBorder(RtfWriter.BorderStyle.Single, 0.25f); //заголовки for (int i = 0; i < dgv.ColumnCount; i++) { table.cell(0, i).Alignment = Align.Center; table.cell(0, i).addParagraph().Text = dgv.Columns[i].Name; } table.setColWidth(0, (float)(60.0m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(1, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(2, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(3, (float)(17.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(4, (float)(17.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(5, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(6, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(7, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(8, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(9, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(10, (float)(12.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(11, (float)(17.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(12, (float)(17.5m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(13, (float)(10.0m * RtfConstants.MILLIMETERS_TO_POINTS)); table.setColWidth(14, (float)(10.0m * RtfConstants.MILLIMETERS_TO_POINTS)); DataView dv = new DataView((DataTable)dgv.DataSource); dv.Sort = "Абитуриентов г/б DESC"; int rowId = 1; foreach (DataRow rw in dv.ToTable().Rows) { int colId = 0; foreach (DataColumn col in dv.ToTable().Columns) { var par = table.cell(rowId, colId).addParagraph(); par.Text = rw[col.ColumnName].ToString(); par.Alignment = Align.Center; colId++; } //запрет переноса строк table.setRowKeepInSamePage(rowId++, false); } doc.save(MainClass.saveTempFolder + "/RegionAbitStat_Rev_Report.rtf"); System.Diagnostics.Process.Start(MainClass.saveTempFolder + "/RegionAbitStat_Rev_Report.rtf"); } catch (Exception ex) { WinFormsServ.Error(ex.Message); } }