//protected void MakeDocx(DataTable dt_plotfiles, DataTable dt_output) //, string path, string projtitle, string datafile) //{ // log(" ====== MakeDocx (DataTable dt_plotfiles, DataTable dt_tables) ======"); // using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = new DevExpress.XtraRichEdit.RichEditDocumentServer()) // { // DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document; // doc.Unit = DevExpress.Office.DocumentUnit.Inch; // doc.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.Letter; // doc.Sections[0].Margins.Left = 0.5f; // doc.Sections[0].Margins.Right = 0.5f; // doc.Sections[0].Margins.Top = 0.5f; // doc.Sections[0].Margins.Bottom = 0.5f; // DocxHeader(doc, _projtitle, _datafile); // DocumentPosition pos = doc.Range.Start; // //New Section // doc.Paragraphs.Append(); // doc.AppendHtmlText("<h3>Plots</h3>"); // doc.Paragraphs.Append(); // foreach (DataRow row in dt_plotfiles.Rows) // { // doc.AppendSingleLineText(String.Format("#{0}",row["index"].ToString())); // doc.Paragraphs.Append(); // AppendChart(doc, _temppath, row["filename"].ToString()); // doc.Paragraphs.Append(); // } // if (dt_output.HasRows()) // { // doc.AppendHtmlText("<br/><br/><h3>Tables</h3>"); // doc.Paragraphs.Append(); // foreach (DataRow row in dt_output.Rows) // { // doc.AppendSingleLineText(String.Format("#{0}", row["index"].ToString())); // doc.Paragraphs.Append(); // doc.AppendHtmlText(row["contents"].ToString()); // doc.Paragraphs.Append(); // } // } // doc.InsertSection(doc.Range.End); // try // { // srv.SaveDocument(_filename, DevExpress.XtraRichEdit.DocumentFormat.OpenXml); // } // catch(Exception ex) // { // } // } //} //protected void MakeDocx(DataTable dt_plotfiles, List<string> htmltables) //, string path, string projtitle, string datafile) //{ // log(" ====== MakeDocx (DataTable dt_plotfiles, List<string> htmltables) ======"); // using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = new DevExpress.XtraRichEdit.RichEditDocumentServer()) // { // DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document; // doc.Unit = DevExpress.Office.DocumentUnit.Inch; // doc.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.Letter; // doc.Sections[0].Margins.Left = 0.5f; // doc.Sections[0].Margins.Right = 0.5f; // doc.Sections[0].Margins.Top = 0.5f; // doc.Sections[0].Margins.Bottom = 0.5f; // DocxHeader(doc, _projtitle, _datafile); // DocumentPosition pos = doc.Range.Start; // //New Section // doc.Paragraphs.Append(); // doc.AppendSingleLineText("The start of it all!"); // doc.Paragraphs.Append(); // foreach (DataRow row in dt_plotfiles.Rows) // { // doc.AppendSingleLineText(String.Format("#{0}", row["index"].ToString())); // doc.Paragraphs.Append(); // AppendChart(doc, _temppath, row["filename"].ToString()); // doc.Paragraphs.Append(); // } // doc.AppendHtmlText("<br/><br/><h3>Tables</h3>"); // foreach (string t in htmltables) // { // doc.AppendHtmlText(t); // doc.Paragraphs.Append(); // } // doc.InsertSection(doc.Range.End); // try // { // srv.SaveDocument(_filename, DevExpress.XtraRichEdit.DocumentFormat.OpenXml); // } // catch (Exception ex) // { // } // } //} //protected void MakeDocx(List<DxChartOrder> ordersC) //, string path, string projtitle, string datafile) //{ // log(" ====== MakeDocx (DxChartFactory factory) ======"); // //const float imageLocationX = 40; // //const float imageLocationY = 40; // //int counter = 0; // //string path = @"C:\_temp\factory\"; // string fileName = String.Format(@"{0}{1}", _temppath, _filename); // using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = new DevExpress.XtraRichEdit.RichEditDocumentServer()) // { // DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document; // doc.Unit = DevExpress.Office.DocumentUnit.Inch; // doc.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.Letter; // doc.Sections[0].Margins.Left = 0.5f; // doc.Sections[0].Margins.Right = 0.5f; // doc.Sections[0].Margins.Top = 0.5f; // doc.Sections[0].Margins.Bottom = 0.5f; // DocxHeader(doc, _projtitle, _datafile); // DocumentPosition pos = doc.Range.Start; // //New Section // foreach (DxChartOrder order in ordersC) // { // doc.Paragraphs.Append(); // if(order.dt_selectedvars != null) // { // AppendDataTable(doc, order.dt_selectedvars); // doc.Paragraphs.Append(); // } // doc.AppendSingleLineText(order.InvoiceToString()); // doc.Paragraphs.Append(); // foreach (DxChartBatch batch in order.batches) // { // if (batch.charts.Count > 0) // { // doc.AppendSingleLineText(batch.batchtitle); // doc.Paragraphs.Append(); // AppendCharts(pos, batch, doc); // doc.Paragraphs.Append(); // } // } // doc.InsertSection(doc.Range.End); // } // srv.SaveDocument(fileName, DevExpress.XtraRichEdit.DocumentFormat.OpenXml); // } //} #endregion private void AppendCharts(DocumentPosition pos, DxChartBatch batch, Document doc) { float scaleX = 0.5f - (batch.maxCol * .03f); AppendCharts(pos, batch, doc, scaleX, scaleX); }
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; } } }
protected void MakeDocx(DxReport rpt) //, string path, string projtitle, string datafile) { log(" ====== MakeDocx (DxChartFactory factory) ======"); //const float imageLocationX = 40; //const float imageLocationY = 40; //int counter = 0; //string path = @"C:\_temp\factory\"; //string fileName_with_savepath = String.Format(@"{0}{1}", _savepath, _filename); using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = new DevExpress.XtraRichEdit.RichEditDocumentServer()) { DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document; doc.Unit = DevExpress.Office.DocumentUnit.Inch; doc.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.Letter; doc.Sections[0].Margins.Left = 0.5f; doc.Sections[0].Margins.Right = 0.5f; doc.Sections[0].Margins.Top = 0.5f; doc.Sections[0].Margins.Bottom = 0.5f; string subtitle = String.Format("Data Proj: {0}{1}Data file: {2}", _projtitle, Environment.NewLine, _datafile); DocxHeader(doc, rpt.rpttitle, subtitle); DocumentPosition pos = doc.Range.Start; //New Section if (rpt.rptdesc.Length > 2) { doc.AppendText("Report Description:"); doc.Paragraphs.Append(); doc.AppendText(rpt.rptdesc); doc.Paragraphs.Append(); } //foreach (DxChartOrder order in rpt.orders.chartorders) for (int c = 0; c < rpt.orders.chartorders.Count; c++) { DxChartOrder order = rpt.orders.chartorders[c]; doc.Paragraphs.Append(); bool hassameasPrev = rpt.orders.HasSameWkshtFilterVars(c, "chart", -1); bool hassameasNext = rpt.orders.HasSameWkshtFilterVars(c, "chart", 1); if (order.dt_selectedvars != null & hassameasPrev == false) { AppendDataTable(doc, order.dt_selectedvars); doc.Paragraphs.Append(); } Debug.WriteLine(order.InvoiceToString()); doc.AppendSingleLineText(order.InvoiceToString()); doc.Paragraphs.Append(); for (int b = 0; b < order.batches.Count; b++) { DxChartBatch batch = order.batches[b]; if (batch.charts.Count > 0) { doc.AppendSingleLineText(batch.batchtitle); doc.Paragraphs.Append(); AppendCharts(pos, batch, doc); doc.Paragraphs.Append(); } } if (hassameasNext == false) { doc.InsertSection(doc.Range.End); } } srv.SaveDocument(String.Format(@"{0}{1}", _savepath, rpt.RptFilename()), DevExpress.XtraRichEdit.DocumentFormat.OpenXml); } }