Browse Source

修改导出execl添加默认文件名

cxs 3 years ago
parent
commit
179edd5832

+ 0 - 184
OTSIncAReportApp/1-UI/Control_Grids/ParticlesGridDevidePage.cs

@@ -1804,15 +1804,6 @@ namespace OTSIncAReportGrids
         {
             OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation sfd = new OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation();
             
-            ////将所有的数据导出到EXCEL中
-            //SaveFileDialog sfd = new SaveFileDialog();
-            //sfd.Filter = "Excel File(*.xlsx)|*.xlsx";
-            ////设置默认文件类型显示顺序
-            //sfd.FilterIndex = 1;
-
-            ////保存对话框是否记忆上次打开的目录
-            //sfd.RestoreDirectory = true;
-
             if (sfd.ShowDialog() == DialogResult.OK)
             {
                 //IWorkbook workbook = new HSSFWorkbook();   //用于创建.xls  office2003开始以前的
@@ -1896,13 +1887,6 @@ namespace OTSIncAReportGrids
 
                             //图像效果不好,自己另外导出吧,这里对该列宽进行了设置0
                         }
-                        //else if(i_cell==0)
-                        //{
-                        //    ICreationHelper createHelper = workbook.GetCreationHelper();
-                        //    XSSFHyperlink link = (XSSFHyperlink)createHelper.CreateHyperlink(HyperlinkType.Url);
-                        //    link.Address=;
-                        //    cell.Hyperlink.Address(link);
-                        //}
                         else
                         {
                             //非图像列
@@ -1999,33 +1983,6 @@ namespace OTSIncAReportGrids
                         anchor3 = drawing.CreateAnchor(0, 0, 0, 0, 1, j + 2, 2, j + 3);//XSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2);参数说明:dx1 dy1 起始单元格中的x,y坐标.dx2 dy2 结束单元格中的x,y坐标col1, row1 指定起始的单元格,下标从0开始col2, row2 指定结束的单元格,下标从0开始
                         CreateChart(drawing, sheet2, anchor3, j + 2);
                     }
-                    //row = sheet3.CreateRow(2);
-                    //row.Height = 120 * 20;
-                    //cell = row.CreateCell(0);
-                    //cell.CellStyle = cellStyle;
-                    //cell.SetCellValue(1);
-                    //cell = row.CreateCell(1);
-                    //cell = row.CreateCell(2);
-                    //cell = row.CreateCell(3);
-
-                    //drawing = sheet3.CreateDrawingPatriarch();
-                    ////锚点
-                    //anchor3 = drawing.CreateAnchor(0, 0, 0, 0, 1, 2, 2, 3);//XSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2);参数说明:dx1 dy1 起始单元格中的x,y坐标.dx2 dy2 结束单元格中的x,y坐标col1, row1 指定起始的单元格,下标从0开始col2, row2 指定结束的单元格,下标从0开始
-                    //CreateChart(drawing, sheet2, anchor3, 2);
-
-                    //row = sheet3.CreateRow(3);
-                    //row.Height = 120 * 20;
-                    //cell = row.CreateCell(0);
-                    //cell.CellStyle = cellStyle;
-                    //cell.SetCellValue(1);
-                    //cell = row.CreateCell(1);
-                    //cell = row.CreateCell(2);
-                    //cell = row.CreateCell(3);
-
-                    //drawing = sheet3.CreateDrawingPatriarch();
-                    ////锚点
-                    //anchor3 = drawing.CreateAnchor(0, 0, 0, 0, 1, 3, 2, 4);//XSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2);参数说明:dx1 dy1 起始单元格中的x,y坐标.dx2 dy2 结束单元格中的x,y坐标col1, row1 指定起始的单元格,下标从0开始col2, row2 指定结束的单元格,下标从0开始
-                    //CreateChart(drawing, sheet2, anchor3, 3);
                 }
 
                 //完成后,对Excel进行保存
@@ -2041,14 +1998,6 @@ namespace OTSIncAReportGrids
                     //打开刚才导出的文件
                     System.Diagnostics.Process.Start(sfd.FileName);
                 }
-
-                // 生成一个 单元格 对象 HSSFCell cellTableName = CreateCell(sheetTableIndex, t + 1, 0, strTableName, true); 
-                //创建一个超链接对象 HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT); 
-                // strTableName 这个参数为 sheet名字 A1 为单元格 其他是固定格式 link.Address = "#" + strTableName + "!A1"; 
-                //设置 cellTableName 单元格 的连接对象 cellTableName.Hyperlink = link;
-
-
-
             }
         }
 
@@ -2078,7 +2027,6 @@ namespace OTSIncAReportGrids
                 doubles[i] = i;
             }
             IChartDataSource<double> xs = DataSources.FromArray(doubles);
-            //IChartDataSource<double> ys = DataSources.FromArray(doubles);
 
             //数据系列
             var s1 = data.AddSeries(xs, ys);
@@ -2160,138 +2108,6 @@ namespace OTSIncAReportGrids
                 }
             }
         }
-
-
-        #region 将DataTable中的数据写到Excel的指定Sheet中
-        /// <summary>
-        /// 将DataTable中的数据写到Excel的指定Sheet中
-        /// </summary>
-        /// <param name="dt"></param>
-        /// <param name="m_Sheet"></param>
-        public void DataTableToSheet(string title, DataTable dt, Microsoft.Office.Interop.Excel._Worksheet m_Sheet,
-                                    Microsoft.Office.Interop.Excel._Workbook m_Book, int startrow)
-        {
-
-            //以下是填写EXCEL中数据
-            Microsoft.Office.Interop.Excel.Range range = m_Sheet.get_Range(m_Sheet.Cells[1, 1], m_Sheet.Cells[1, 2]);
-            range.MergeCells = true;  //合并单元格
-            range.Font.Bold = true;   //加粗单元格内字符
-            //写入题目
-            m_Sheet.Cells[startrow, startrow] = title;
-            int rownum = dt.Rows.Count;//行数
-            int columnnum = dt.Columns.Count;//列数
-            int num = rownum + 2;   //得到数据中的最大行数
-
-
-            //写入列标题
-            for (int j = 0; j < columnnum; j++)
-            {
-                int bt_startrow = startrow + 1;
-
-                //将字段名写入文档
-                m_Sheet.Cells[bt_startrow, 1 + j] = dt.Columns[j].ColumnName;
-
-                //单元格内背景色
-                m_Sheet.get_Range(m_Sheet.Cells[bt_startrow, 1 + j], m_Sheet.Cells[bt_startrow, 1 + j]).Interior.ColorIndex = 15;
-            }
-
-
-            //逐行写入数据
-            for (int i = 0; i < rownum; i++)
-            {
-                for (int j = 0; j < columnnum; j++)
-                {
-                    m_Sheet.Cells[startrow + 2 + i, 1 + j] = dt.Rows[i][j].ToString();
-                }
-            }
-            m_Sheet.Columns.AutoFit();
-
-
-
-            //在当前工作表中根据数据生成图表
-
-            CreateChart(m_Book, m_Sheet, num);
-        }
-        private void CreateChart(Microsoft.Office.Interop.Excel._Workbook m_Book, Microsoft.Office.Interop.Excel._Worksheet m_Sheet, int num)
-        {
-            Microsoft.Office.Interop.Excel.Range oResizeRange;
-            Microsoft.Office.Interop.Excel.Series oSeries;
-
-            m_Book.Charts.Add(Missing.Value, Missing.Value, 1, Missing.Value);
-            m_Book.ActiveChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;//设置图形
-
-            //设置数据取值范围
-            m_Book.ActiveChart.SetSourceData(m_Sheet.get_Range("A2", "C" + num.ToString()), Microsoft.Office.Interop.Excel.XlRowCol.xlColumns);
-            //m_Book.ActiveChart.Location(Microsoft.Office.Interop.Excel.XlChartLocation.xlLocationAutomatic, title);
-            //以下是给图表放在指定位置
-            m_Book.ActiveChart.Location(Microsoft.Office.Interop.Excel.XlChartLocation.xlLocationAsObject, m_Sheet.Name);
-            oResizeRange = (Microsoft.Office.Interop.Excel.Range)m_Sheet.Rows.get_Item(10, Missing.Value);
-            m_Sheet.Shapes.Item("Chart 1").Top = (float)(double)oResizeRange.Top;  //调图表的位置上边距
-            oResizeRange = (Microsoft.Office.Interop.Excel.Range)m_Sheet.Columns.get_Item(6, Missing.Value);  //调图表的位置左边距
-                                                                                                              // m_Sheet.Shapes.Item("Chart 1").Left = (float)(double)oResizeRange.Left;
-            m_Sheet.Shapes.Item("Chart 1").Width = 400;   //调图表的宽度
-            m_Sheet.Shapes.Item("Chart 1").Height = 250;  //调图表的高度
-
-            m_Book.ActiveChart.PlotArea.Interior.ColorIndex = 19;  //设置绘图区的背景色
-            m_Book.ActiveChart.PlotArea.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone;//设置绘图区边框线条
-            m_Book.ActiveChart.PlotArea.Width = 400;   //设置绘图区宽度
-            //m_Book.ActiveChart.ChartArea.Interior.ColorIndex = 10; //设置整个图表的背影颜色
-            //m_Book.ActiveChart.ChartArea.Border.ColorIndex = 8;// 设置整个图表的边框颜色
-            m_Book.ActiveChart.ChartArea.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone;//设置边框线条
-            m_Book.ActiveChart.HasDataTable = false;
-
-
-            //设置Legend图例的位置和格式
-            m_Book.ActiveChart.Legend.Top = 20.00; //具体设置图例的上边距
-            m_Book.ActiveChart.Legend.Left = 60.00;//具体设置图例的左边距
-            m_Book.ActiveChart.Legend.Interior.ColorIndex = Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexNone;
-            m_Book.ActiveChart.Legend.Width = 150;
-            m_Book.ActiveChart.Legend.Font.Size = 9.5;
-            //m_Book.ActiveChart.Legend.Font.Bold = true;
-            m_Book.ActiveChart.Legend.Font.Name = "宋体";
-            //m_Book.ActiveChart.Legend.Position = Microsoft.Office.Interop.Excel.XlLegendPosition.xlLegendPositionTop;//设置图例的位置
-            m_Book.ActiveChart.Legend.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone;//设置图例边框线条
-
-
-
-            //设置X轴的显示
-            Microsoft.Office.Interop.Excel.Axis xAxis = (Microsoft.Office.Interop.Excel.Axis)m_Book.ActiveChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
-            xAxis.MajorGridlines.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlDot;
-            xAxis.MajorGridlines.Border.ColorIndex = 1;//gridLine横向线条的颜色
-            xAxis.HasTitle = false;
-            xAxis.MinimumScale = 1500;
-            xAxis.MaximumScale = 6000;
-            xAxis.TickLabels.Font.Name = "宋体";
-            xAxis.TickLabels.Font.Size = 9;
-
-
-
-            //设置Y轴的显示
-            Microsoft.Office.Interop.Excel.Axis yAxis = (Microsoft.Office.Interop.Excel.Axis)m_Book.ActiveChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
-            yAxis.TickLabelSpacing = 30;
-            yAxis.TickLabels.NumberFormat = "M月D日";
-            yAxis.TickLabels.Orientation = Microsoft.Office.Interop.Excel.XlTickLabelOrientation.xlTickLabelOrientationHorizontal;//Y轴显示的方向,是水平还是垂直等
-            yAxis.TickLabels.Font.Size = 8;
-            yAxis.TickLabels.Font.Name = "宋体";
-
-            //m_Book.ActiveChart.Floor.Interior.ColorIndex = 8;
-            /***以下是设置标题*****
-            m_Book.ActiveChart.HasTitle=true;
-            m_Book.ActiveChart.ChartTitle.Text = "净值指数";
-            m_Book.ActiveChart.ChartTitle.Shadow = true;
-            m_Book.ActiveChart.ChartTitle.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
-            */
-
-            oSeries = (Microsoft.Office.Interop.Excel.Series)m_Book.ActiveChart.SeriesCollection(1);
-            oSeries.Border.ColorIndex = 45;
-            oSeries.Border.Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;
-            oSeries = (Microsoft.Office.Interop.Excel.Series)m_Book.ActiveChart.SeriesCollection(2);
-            oSeries.Border.ColorIndex = 9;
-            oSeries.Border.Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;
-
-        }
-
-        #endregion
     }
 
 

+ 1 - 0
OTSIncAReportApp/1-UI/Control_Grids/SpectrumExportConfirmation.cs

@@ -50,6 +50,7 @@ namespace OTSIncAReportApp._1_UI.Control_Grids
             sfd.Filter = "Excel File(*.xlsx)|*.xlsx";
             //设置默认文件类型显示顺序
             sfd.FilterIndex = 1;
+            sfd.FileName = "ParticlesInfo";
 
             //保存对话框是否记忆上次打开的目录
             sfd.RestoreDirectory = true;