private void FormatTableBorders(DevExpress.XtraRichEdit.API.Native.Table t) { t.Borders.Top.LineColor = Color.White; t.Borders.Bottom.LineColor = Color.White; t.Borders.Left.LineColor = Color.White; t.Borders.Right.LineColor = Color.White; t.Borders.InsideHorizontalBorder.LineStyle = TableBorderLineStyle.None; t.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None; }
private void btnCheckLayout_Click(object sender, EventArgs e) { #region #CheckLayout DevExpress.XtraRichEdit.API.Native.Table table = richEditControl1.Document.Tables.First; if (table != null) { // Obtain the layout element related to the table. LayoutTable ltable = richEditControl1.DocumentLayout.GetElement <LayoutTable>(table.Range.Start); // Obtain zero-based page index of the page containing the layout element. int pageIndex = this.richEditControl1.DocumentLayout.GetPageIndex(ltable); // Check whether the layout element is located at the second page. string s = "Layout verified."; if (pageIndex != 1) { s = "The first table is not on the page 2. Review pagination."; } MessageBox.Show(s, "Check Layout", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion #CheckLayout }
protected void Page_Init(object sender, EventArgs e) { if (!IsCallback && !IsPostBack) { HiddenInvoiceId.Value = Request.Params["OrderID"]; var arrayInvoice = new ArrayList(); using (SqlConnection con = new SqlConnection(conStr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = @"select i.InvoiceID, i.OrderID, i.InvoiceRtf from Invoices i where i.OrderID = " + HiddenInvoiceId.Value + " order by i.InvoiceID desc"; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { arrayInvoice.Add(reader["InvoiceID"]); arrayInvoice.Add(reader["OrderID"]); arrayInvoice.Add(reader["InvoiceRtf"]); } reader.Close(); con.Close(); } } if (arrayInvoice.Count > 0) { // Stream var MemoryStream updatedStream = new MemoryStream(); // Load stream from database MemoryStream stream = new MemoryStream((byte[])arrayInvoice[2]); // Load document from stream RichEditDocumentServer docServer = new RichEditDocumentServer(); docServer.LoadDocument(stream, DocumentFormat.Rtf); // Create document server Document document = docServer.Document; // If the document is not protected if (!document.IsDocumentProtected) { // Protect the document with a password document.Protect("123", DocumentProtectionType.ReadOnly); // Tables DevExpress.XtraRichEdit.API.Native.Table table1 = document.Tables[1]; DocumentRange rangeTable1 = table1.Rows[1].Range; DevExpress.XtraRichEdit.API.Native.Table table2 = document.Tables[2]; DocumentRange rangeTable2 = table2.Rows[1].Range; // Add table1 as range / Allow editing row 1 over table1 RangePermissionCollection coletionTable1 = document.BeginUpdateRangePermissions(); RangePermission permissionTable1 = coletionTable1.CreateRangePermission(rangeTable1); permissionTable1.Group = "Everyone"; coletionTable1.Add(permissionTable1); document.EndUpdateRangePermissions(coletionTable1); // Add table2 as range / Allow editing row 1 over table2 RangePermissionCollection coletionTable2 = document.BeginUpdateRangePermissions(); RangePermission permissionTable2 = coletionTable2.CreateRangePermission(rangeTable2); permissionTable2.Group = "Everyone"; coletionTable2.Add(permissionTable2); document.EndUpdateRangePermissions(coletionTable2); } // Update updatedStream var from stream var document.SaveDocument(updatedStream, DocumentFormat.Rtf); // Open document from updatedStream var ASPxRichEdit1.Open(Guid.NewGuid().ToString(), DocumentFormat.Rtf, () => { return(updatedStream.ToArray()); }); } } }
public void TablaDoc(ref RichEditDocumentServer wordDoc, int filas, string _poliza) { DocumentPosition pos = wordDoc.Document.CreatePosition(1075); System.Data.DataTable content = AccesoDatos.RegresaTablaSql("select asegurado as nombre, certificado, clase as descripcion from asegurado where poliza = '" + _poliza + "' order by asegurado, certificado"); DevExpress.XtraRichEdit.API.Native.Table table = wordDoc.Document.Tables.Add(pos, filas, 5); // Major adjustments table.TableLayout = TableLayoutType.Fixed; table.PreferredWidthType = WidthType.Fixed; table.PreferredWidth = Units.InchesToDocumentsF(8f); table.Rows[1].HeightType = HeightType.Exact; table.Rows[1].Height = Units.InchesToDocumentsF(0.25f); wordDoc.Document.InsertText(table[0, 0].Range.Start, "Nombre"); wordDoc.Document.InsertText(table[0, 2].Range.Start, "Cert."); wordDoc.Document.InsertText(table[0, 4].Range.Start, "Descripción"); //table[0, 0].Style.Bold = true; //table[0, 2].Style.Bold = true; //table[0, 4].Style.Bold = true; //table[0, 0].Style.FontSize = 12; //table[0, 2].Style.FontSize = 12; //table[0, 4].Style.FontSize = 12; table[0, 0].Borders.Bottom.LineColor = Color.White; table[0, 0].Borders.Top.LineColor = Color.White; table[0, 0].Borders.Left.LineColor = Color.White; table[0, 0].Borders.Right.LineColor = Color.White; table[0, 1].Borders.Bottom.LineColor = Color.White; table[0, 1].Borders.Top.LineColor = Color.White; table[0, 1].Borders.Left.LineColor = Color.White; table[0, 1].Borders.Right.LineColor = Color.White; table[0, 2].Borders.Bottom.LineColor = Color.White; table[0, 2].Borders.Top.LineColor = Color.White; table[0, 2].Borders.Left.LineColor = Color.White; table[0, 2].Borders.Right.LineColor = Color.White; table[0, 3].Borders.Bottom.LineColor = Color.White; table[0, 3].Borders.Top.LineColor = Color.White; table[0, 3].Borders.Left.LineColor = Color.White; table[0, 3].Borders.Right.LineColor = Color.White; table[0, 4].Borders.Bottom.LineColor = Color.White; table[0, 4].Borders.Top.LineColor = Color.White; table[0, 4].Borders.Left.LineColor = Color.White; table[0, 4].Borders.Right.LineColor = Color.White; // table[0, 0]..Right.LineColor = Color.White; int tupla = 1; // Additional adjustments //DocumentPosition pos = wordDoc.Document.CreatePosition(60); foreach (System.Data.DataRow rw in content.Rows) { try { table.Rows[tupla].Cells[0].BackgroundColor = Color.Yellow; table.Rows[tupla].Cells[2].BackgroundColor = Color.Yellow; table.Rows[tupla].Cells[4].BackgroundColor = Color.Yellow; table[tupla, 0].PreferredWidthType = WidthType.Fixed; table[tupla, 0].PreferredWidth = Units.InchesToDocumentsF(8f); table[tupla, 1].PreferredWidthType = WidthType.Fixed; table[tupla, 1].PreferredWidth = Units.InchesToDocumentsF(1f); table[tupla, 1].BackgroundColor = Color.White; table[tupla, 2].PreferredWidthType = WidthType.Fixed; table[tupla, 2].PreferredWidth = Units.InchesToDocumentsF(1f); table[tupla, 3].PreferredWidthType = WidthType.Fixed; table[tupla, 3].PreferredWidth = Units.InchesToDocumentsF(1f); table[tupla, 3].BackgroundColor = Color.White; table[tupla, 4].PreferredWidthType = WidthType.Fixed; table[tupla, 4].PreferredWidth = Units.InchesToDocumentsF(2f); wordDoc.Document.InsertText(table[tupla, 0].Range.Start, rw["nombre"].ToString().Trim()); wordDoc.Document.InsertText(table[tupla, 1].Range.Start, ""); wordDoc.Document.InsertText(table[tupla, 2].Range.Start, rw["certificado"].ToString().Trim()); wordDoc.Document.InsertText(table[tupla, 3].Range.Start, ""); wordDoc.Document.InsertText(table[tupla, 4].Range.Start, rw["descripcion"].ToString().Trim()); tupla += 1; } catch (Exception we) { Helper.RegistrarEvento("Cargando wordDoc : " + tupla.ToString() + " - " + we.Message); } } table[1, 1].LeftPadding = 0; }
//public static int GetDiagIndex(int r, int c, int n) //{ // //k = (n * (n - 1) / 2) - (n - r) * ((n - r) - 1) / 2 + c - r - 1 // int idx = (n * (n - 1) / 2) - (n - r) * ((n - r) - 1) / 2 + c - r - 1; // return idx; //} private void AppendDataTable(Document document, DataTable dataTable) { int dataTableRows = dataTable.Rows.Count; int dataTableColumns = dataTable.Columns.Count; List <string> columnsToDisplay = new List <string>(); for (int i = 0; i < dataTableColumns; i++) { string name = dataTable.Columns[i].ColumnName; // Skip PrimaryKey columns if (!name.ToUpper().EndsWith("ID")) { columnsToDisplay.Add(name); } } document.BeginUpdate(); DevExpress.XtraRichEdit.API.Native.Table table = document.Tables.Create(document.Range.End, dataTableRows + 1, columnsToDisplay.Count, AutoFitBehaviorType.AutoFitToContents); //table.Borders.InsideHorizontalBorder.LineColor = Color.DarkBlue; //table.Borders.InsideVerticalBorder.LineColor = Color.DarkBlue; //table.Borders.InsideHorizontalBorder.LineThickness = 0.5f; //table.Borders.InsideHorizontalBorder.LineStyle = TableBorderLineStyle.Single; //table.Borders.InsideVerticalBorder.LineThickness = 0.5f; //table.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.Single; //table.LeftPadding = Units.InchesToDocumentsF(0.01f); //table.FirstRow.Height = Units.InchesToDocumentsF(0.5f); //table.FirstRow.HeightType = HeightType.Exact; ParagraphProperties pp = document.BeginUpdateParagraphs(table.FirstRow.Range); pp.Alignment = ParagraphAlignment.Left; document.EndUpdateParagraphs(pp); CharacterProperties cp = document.BeginUpdateCharacters(table.FirstRow.Range); //cp.FontName = "Courier New"; cp.Bold = true; cp.ForeColor = Color.Gray; cp.FontSize = 9f; document.EndUpdateCharacters(cp); CharacterProperties cp2 = document.BeginUpdateCharacters(table.Range); //cp.FontName = "Courier New"; cp2.FontSize = 9f; document.EndUpdateCharacters(cp2); //for (int i = 0; i < table.FirstRow.Cells.Count; i++) //{ // table.FirstRow.Cells[i].HeightType = HeightType.Auto; // table.FirstRow.Cells[i].VerticalAlignment = TableCellVerticalAlignment.Top; //table.FirstRow.Cells[i].BackgroundColor = Color.DarkBlue; //table.FirstRow.Cells[i].VerticalAlignment = TableCellVerticalAlignment.Center; //} // Fill table header with column names for (int i = 0; i < columnsToDisplay.Count; i++) { document.InsertText(table[0, i].Range.Start, columnsToDisplay[i]); } // Fill table body with data table.ForEachCell(delegate(DevExpress.XtraRichEdit.API.Native.TableCell cell, int rowIndex, int cellIndex) { if (rowIndex > 0) { document.InsertText(cell.Range.Start, dataTable.Rows[rowIndex - 1][columnsToDisplay[cellIndex]].ToString()); } }); document.EndUpdate(); }
private void AppendCharts(DocumentPosition pos, DxChartBatch batch, Document doc, float scaleX, float scaleY) { bool addHeaderRow = true; if (batch.layout == DxLayout.Upper) { int numcols = LayoutOutput.NCols(batch.charts.Count); int numrows = (addHeaderRow) ? numcols + 1 : numcols; //int numrows = (addHeaderRow) ? batch.maxRow + 1 : batch.maxRow; doc.BeginUpdate(); DevExpress.XtraRichEdit.API.Native.Table t = doc.Tables.Create(doc.Range.End, numrows, numcols, AutoFitBehaviorType.AutoFitToContents); FormatTableBorders(t); if (addHeaderRow) { for (int h = 0; h < numcols; h++) { doc.InsertText(t[0, h].Range.Start, batch.vars[h]); doc.InsertText(t[h, 0].Range.Start, batch.vars[h - 1]); //if (h > 0 & h < batch.vars.Count) doc.InsertText(t[0, h].Range.Start, batch.vars[h]); //if (h > 0 & h < batch.vars.Count) doc.InsertText(t[h, 0].Range.Start, batch.vars[h - 1]); t.Cell(h, 0).VerticalAlignment = TableCellVerticalAlignment.Center; } } //t.Rows.Add(CreateHeaderRow(batch.vars, ncols)); int counter = 0; for (int r = 0; r < numrows; r++) { //for (int c = r; c < batch.maxCol; c++) for (int c = r; c < numcols; c++) { if (c > r) { int bumprow = (addHeaderRow) ? 1 : 0; int idx = LayoutOutput.GetDiagIndex(r, c, batch.maxRow); string chartfile = String.Format(@"{0}{1}.png", _temppath, batch.charts[counter].guid); counter++; DevExpress.XtraRichEdit.API.Native.TableCell cell = t.Cell(r + bumprow, c); doc.Images.Insert(cell.Range.Start, DocumentImageSource.FromFile(chartfile)); doc.Images[doc.Images.Count - 1].ScaleX = scaleX; doc.Images[doc.Images.Count - 1].ScaleY = scaleY; } } } doc.EndUpdate(); } else { foreach (DxChart chart in batch.charts) { string chartfile = String.Format(@"{0}{1}.png", _temppath, chart.guid); log(chartfile); //MemoryStream s = new MemoryStream(); //chart.chart.ExportToImage(s, System.Drawing.Imaging.ImageFormat.Png); doc.Images.Insert(pos, DocumentImageSource.FromFile(chartfile)); doc.Images[doc.Images.Count - 1].ScaleX = 0.5f; doc.Images[doc.Images.Count - 1].ScaleY = 0.5f; } } }