NPOI画线踩坑
作者:互联网
应报表需要,图标需要用线链接,在连线时,发现线条的坐标比较坑,其中 CreateAnchor中的col1,row1参数本以为是起始单元格的位置,踩坑过程中发现col1仅仅代表一个列的的位置,并不和row1一起,且必须 col1小于col2,row1小于row2 否则生成的excel打开时会报错!!!!!
图形类型:ShapeTypes.Line 为下划线 ShapeTypes.LineInv 为上划线
/// <summary> /// 画线 /// </summary> /// <param name="sheet"></param> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="x2"></param> /// <param name="y2"></param> /// <param name="c1"></param> /// <param name="r1"></param> /// <param name="c2"></param> /// <param name="r2"></param> private static void DrawWire(ISheet sheet, int c1 = 4, int r1 = 8, int c2 = 5, int r2 = 9, ShapeTypes shapeType = ShapeTypes.Line) { XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFClientAnchor anchor = (XSSFClientAnchor)drawing.CreateAnchor(480000, 455000, 320000, 340000, c1, r1, c2, r2); XSSFSimpleShape wire = drawing.CreateSimpleShape(anchor); ////设置边框颜色 wire.ShapeType = (int)shapeType; wire.SetLineStyleColor(0, 0, 0); } /// <summary> /// 画图形 /// </summary> /// <param name="sheet"></param> /// <param name="i"></param> /// <param name="type"></param> private static void DrawGraph(ISheet sheet, int i, int col, int type) { XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFClientAnchor anchor = (XSSFClientAnchor)drawing.CreateAnchor( 323850, 269875,542290, 498475, col, 8 + i,col,8 + i); XSSFSimpleShape xss = drawing.CreateSimpleShape(anchor); xss.ShapeType = type; ////设置边框颜色 xss.SetLineStyleColor(0, 0, 0); }
标签:sheet,int,画线,NPOI,XSSFDrawing,XSSFClientAnchor,ShapeTypes,drawing 来源: https://www.cnblogs.com/MrJohnson/p/16301169.html