zoukankan      html  css  js  c++  java
  • 将GridControl和ChartControl导出到Excel的同个Sheet页中

    DevExpress 10 版本

    #region 导出 private void btnExport_Click(object sender, EventArgs e) { ExportToExcel(gc, chartControl1); } /// <summary> /// 创建打印Componet /// </summary> /// <param name="printable"></param> /// <returns></returns> PrintableComponentLink CreatePrintableLink(IPrintable printable) { ChartControl chart = printable as ChartControl; if (chart != null) chart.OptionsPrint.SizeMode = DevExpress.XtraCharts.Printing.PrintSizeMode.Stretch; PrintableComponentLink printableLink = new PrintableComponentLink() { Component = printable }; return printableLink; } /// <summary> /// 导出Excel,支持多个控件同时导出在同一个Sheet表 /// </summary> /// <param name="panels">控件集</param> public void ExportToExcel(params IPrintable[] panels) { string fileName = string.Empty; if (gv.RowCount > 0) { try { this.saveFileDialog.FileName = "XXX -- " + DateTime.Now.Date.ToString("yyyy-MM-dd"); // 默认文件名 this.saveFileDialog.Title = "Export Excel"; this.saveFileDialog.DefaultExt = "xlsx"; // 扩展名 this.saveFileDialog.Filter = "Excel file(*.xlsx)|*.xlsx|Excel file(*.xls)|*.xls"; this.saveFileDialog.OverwritePrompt = false; // 文件存在是是否提示覆盖 if (this.saveFileDialog.ShowDialog() == DialogResult.OK) { fileName = saveFileDialog.FileName; this.gv.RowStyle -= gv_RowStyle; //去除选中行样式 PrintingSystem ps = new PrintingSystem(); CompositeLink link = new CompositeLink(ps); ps.Links.Add(link); foreach (IPrintable panel in panels) { link.Links.Add(CreatePrintableLink(panel)); } link.Landscape = true;//横向 //判断是否有标题,有则设置 link.CreateDocument(); //建立文档 //ps.PreviewFormEx.Show();//进行预览 //ps.Print(); //打印 try { if (string.IsNullOrEmpty(fileName)) { return; } int count = 1; //在重复名称后加(序号) while (File.Exists(fileName)) { if (fileName.Contains(").")) { int start = fileName.LastIndexOf("("); int end = fileName.LastIndexOf(").") - fileName.LastIndexOf("(") + 2; fileName = fileName.Replace(fileName.Substring(start, end), string.Format("({0}).", count)); } else { int find = fileName.LastIndexOf("."); fileName = fileName.Insert(find, string.Format("({0})", count)); } count++; } if (fileName.LastIndexOf(".xlsx") >= fileName.Length - 5) { XlsxExportOptions options = new XlsxExportOptions(); options.SheetName = "XXX"; //修改sheet页命名 link.PrintingSystem.ExportToXlsx(fileName, options); } else { XlsExportOptions options = new XlsExportOptions(); options.SheetName = "XXX"; //修改sheet页命名 link.PrintingSystem.ExportToXls(fileName, options); } if (DevExpress.XtraEditors.XtraMessageBox.Show("保存成功,是否打开文件?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { System.Diagnostics.Process.Start(fileName);//打开指定路径下的文件 } } catch (Exception) { //提示... } this.gv.RowStyle += gv_RowStyle; } } catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message); } } else { //提示... return; } } #endregion

     相关链接:https://q.cnblogs.com/q/88667/#a_203370

  • 相关阅读:
    在chrome上隐藏video的option按钮
    使用POST请求实现页面的跳转
    Write Sling Servlet using a resource type and selector
    HTL里面使用sling model的时候传参问题
    使用querybuilder做忽略大小写查询的例子
    AEM上的一个图片转换工具
    Oracle的Rman差异增量备份
    HDFS
    使用ROBOCOPY定时增量备份文件
    SOAP详解
  • 原文地址:https://www.cnblogs.com/719468186-QAQ/p/6961279.html
Copyright © 2011-2022 走看看