Browse Source

execl 谱峰图导出

CXS 3 years ago
parent
commit
37aee811a6
1 changed files with 61 additions and 25 deletions
  1. 61 25
      OTSIncAReportApp/1-UI/Control_Grids/ParticlesGridDevidePage.cs

+ 61 - 25
OTSIncAReportApp/1-UI/Control_Grids/ParticlesGridDevidePage.cs

@@ -1822,6 +1822,8 @@ namespace OTSIncAReportGrids
                 fs.Close();
 
                 sheet = workbook.CreateSheet("Particles");//创建工作表
+                ISheet sheet3;
+                sheet3 = workbook.CreateSheet("Peak spectrum");
 
                 //创建表格边框样式风格
                 ICellStyle cellStyle = workbook.CreateCellStyle();
@@ -1893,6 +1895,13 @@ 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
                         {
                             //非图像列
@@ -1956,8 +1965,7 @@ namespace OTSIncAReportGrids
                     }
                 }
 
-                ISheet sheet3;
-                sheet3 = workbook.CreateSheet("Peak spectrum");//创建工作表
+                
                 sheet3.SetColumnWidth(1, 200 * 256);//图像列宽
                 //插入表头
                 row = sheet3.CreateRow(1);
@@ -1969,29 +1977,51 @@ namespace OTSIncAReportGrids
                 cell = row.CreateCell(1);
                 cell.CellStyle = cellStyle;
                 cell.SetCellValue("PeakSpectrum");
-                //for (int j = 0; j < 1; j++)//particles.Rows.Count
-                //{
-                //    row = sheet3.CreateRow(j+2);
-                //    row.Height = 120 * 20;
-                //    cell = row.CreateCell(0);
-                //    cell.CellStyle = cellStyle;
-                //    cell.SetCellValue(j+1);
-                //    cell = row.CreateCell(1);
-                //    IDrawing drawing = sheet3.CreateDrawingPatriarch();
-                //    //锚点
-                //    IClientAnchor anchor3 = drawing.CreateAnchor(0, 0, 0, 0, j+2, 1, j+2, 1);//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);
-                IDrawing drawing = sheet3.CreateDrawingPatriarch();
-                //锚点
-                IClientAnchor anchor3 = drawing.CreateAnchor(0, 0, 0, 0, 0, 0, 1, 1);//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);
+
+                IDrawing drawing;
+                IClientAnchor anchor3;
+                for (int j = 0; j < particles.Rows.Count; j++)
+                {
+                    row = sheet3.CreateRow(j + 2);
+                    row.Height = 120 * 20;
+                    cell = row.CreateCell(0);
+                    cell.CellStyle = cellStyle;
+                    cell.SetCellValue(j + 1);
+                    cell = row.CreateCell(1);
+                    cell = row.CreateCell(2);
+                    cell = row.CreateCell(3);
+                    drawing = sheet3.CreateDrawingPatriarch();
+                    //锚点
+                    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进行保存
                 FileStream file = new FileStream(sfd.FileName, FileMode.Create);
@@ -2007,6 +2037,12 @@ 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;
+
+
 
             }
         }