|
@@ -1958,32 +1958,40 @@ namespace OTSIncAReportGrids
|
|
|
|
|
|
ISheet sheet3;
|
|
|
sheet3 = workbook.CreateSheet("Peak spectrum");//创建工作表
|
|
|
- sheet3.SetColumnWidth(0, 100 * 256);//图像列宽
|
|
|
- ////插入表头
|
|
|
- //row = sheet3.CreateRow(1);
|
|
|
- //row.Height = 30 * 20;
|
|
|
- //cell = row.CreateCell(0);
|
|
|
- //cell.CellStyle = cellStyle;
|
|
|
- //cell.SetCellValue("rowid");
|
|
|
-
|
|
|
- //cell = row.CreateCell(1);
|
|
|
- //cell.CellStyle = cellStyle;
|
|
|
- //cell.SetCellValue("PeakSpectrum");
|
|
|
- //for (int j = 0; j < particles.Rows.Count; j++)
|
|
|
+ sheet3.SetColumnWidth(1, 200 * 256);//图像列宽
|
|
|
+ //插入表头
|
|
|
+ row = sheet3.CreateRow(1);
|
|
|
+ row.Height = 30 * 20;
|
|
|
+ cell = row.CreateCell(0);
|
|
|
+ cell.CellStyle = cellStyle;
|
|
|
+ cell.SetCellValue("rowid");
|
|
|
+
|
|
|
+ cell = row.CreateCell(1);
|
|
|
+ cell.CellStyle = cellStyle;
|
|
|
+ cell.SetCellValue("PeakSpectrum");
|
|
|
+ //for (int j = 0; j < 1; j++)//particles.Rows.Count
|
|
|
//{
|
|
|
- row = sheet3.CreateRow(1);
|
|
|
- row.Height = 60 * 20;
|
|
|
- cell = row.CreateCell(0);
|
|
|
- cell.CellStyle = cellStyle;
|
|
|
- //cell.SetCellValue(1);
|
|
|
- cell = row.CreateCell(1);
|
|
|
- cell = row.CreateCell(2);
|
|
|
- IDrawing drawing = sheet3.CreateDrawingPatriarch();
|
|
|
- //锚点
|
|
|
- IClientAnchor anchor3 = drawing.CreateAnchor(0, 0, 0, 0, 0, 0, 2, 2);//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, "title1");
|
|
|
+ // 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);
|
|
|
|
|
|
//完成后,对Excel进行保存
|
|
|
FileStream file = new FileStream(sfd.FileName, FileMode.Create);
|
|
@@ -2003,23 +2011,25 @@ namespace OTSIncAReportGrids
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, string serie1)
|
|
|
+ void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, int rowid)
|
|
|
{
|
|
|
var chart = drawing.CreateChart(anchor) as XSSFChart;
|
|
|
// 创建图形注释的位置
|
|
|
//var legend = chart.GetOrCreateLegend();
|
|
|
//legend.Position = LegendPosition.Top;
|
|
|
-
|
|
|
|
|
|
- //图表
|
|
|
- var data = chart.GetChartDataFactory().CreateLineChartData<double, double>(); //折线图散点图
|
|
|
|
|
|
- IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateCategoryAxis(AxisPosition.Bottom);
|
|
|
- IValueAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Left);
|
|
|
- leftAxis.SetCrosses(AxisCrosses.AutoZero);
|
|
|
+ //图表
|
|
|
+ var data = chart.ChartDataFactory.CreateLineChartData<double, double>(); //折线图
|
|
|
|
|
|
+ IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
|
|
|
+
|
|
|
+ IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
|
|
|
+ leftAxis.Crosses=AxisCrosses.AutoZero;
|
|
|
+ leftAxis.IsVisible = true;
|
|
|
+ bottomAxis.IsVisible = true;
|
|
|
//数据源
|
|
|
- //IChartDataSource<double> xs = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 1, 2001));
|
|
|
+ IChartDataSource<double> ys = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(rowid, rowid, 1, 2001));
|
|
|
|
|
|
Double[] doubles = new Double[2000];
|
|
|
for (int i = 0; i < 2000; i++)
|
|
@@ -2027,11 +2037,10 @@ namespace OTSIncAReportGrids
|
|
|
doubles[i] = i;
|
|
|
}
|
|
|
IChartDataSource<double> xs = DataSources.FromArray(doubles);
|
|
|
- IChartDataSource<double> ys = DataSources.FromArray(doubles);
|
|
|
+ //IChartDataSource<double> ys = DataSources.FromArray(doubles);
|
|
|
|
|
|
//数据系列
|
|
|
- var s1 = data.AddSerie(xs, ys);
|
|
|
- s1.SetTitle(serie1);
|
|
|
+ var s1 = data.AddSeries(xs, ys);
|
|
|
|
|
|
// 开始绘制折线图
|
|
|
chart.Plot(data, bottomAxis, leftAxis);
|