//重绘单元格
        private void InvalidateCell(I3ReportCell cell)
        {
            if (cell == null)
            {
                this.Invalidate();
                return;
            }

            I3PrintArea area = null;

            foreach (I3PrintArea tmpArea in reportDatas.PrintAreas.Dic.Values)
            {
                if (new List <int>(tmpArea.AllRows).IndexOf(cell.Row) >= 0 && new List <int>(tmpArea.AllCols).IndexOf(cell.Col) >= 0)
                {
                    area = tmpArea;
                    break;
                }
            }
            if (area == null)
            {
                this.Invalidate();
                return;
            }

            RectangleF contentRect = GetAreaContentRect(area);
            RectangleF rectF       = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, contentRect, null);
            Rectangle  drawRect    = new Rectangle((int)Math.Ceiling(rectF.X), (int)Math.Ceiling(rectF.Y), (int)Math.Ceiling(rectF.Width), (int)Math.Ceiling(rectF.Height));

            this.Invalidate(drawRect, false);
        }
 public void Init(I3ReportDatas reportDatas)
 {
     this.reportDatas  = reportDatas;
     this.foucesedCell = null;
     this.mouseOnCell  = null;
     this.reportDatas.ReCalSizeAndPageInfo();
     this.ReCal();
 }
        public void OnCellItemDoubleClicked(I3ReportCell cell)
        {
            this.FoucesedCell = cell;

            if (!this.DesignMode && CellItemDoubleClicked != null)
            {
                CellItemDoubleClicked(this, new I3CellItemEventArgs(cell));
            }
        }
        /// <summary>
        /// 构造新的Renderer
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public static II3CellRenderer BuildRenderer(I3ReportCell cell)
        {
            if (cell == null)
            {
                return(null);
            }

            return(BuildRenderer(cell.GetType()));
        }
Example #5
0
        /// <summary>
        /// 计算输出区域   (以内容输出区域左上角为0,0开始计算)
        /// 如果是合并单元格,包含整个合并区域
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="reportData"></param>
        /// <param name="cell"></param>
        public static RectangleF CalCellDrawRect_Scale(I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, float scale, RectangleF dataRect, I3ReportCell mergedCell)
        {
            RectangleF rect = CalCellDrawRect_UnScale(reportDatas, cell, area, mergedCell);

            I3ReportCell destCell = mergedCell == null ? cell : mergedCell;  //移动位置时使用真实单元格

            rect = ScaleAndMoveCellRect(rect, reportDatas, destCell, area, scale, dataRect);
            return(rect);
        }
        public void OnCellItemMouseIn(I3ReportCell cell)
        {
            this.MouseOnCell = cell;

            if (!this.DesignMode && CellItemMouseIn != null)
            {
                CellItemMouseIn(this, new I3CellItemEventArgs(cell));
            }
        }
Example #7
0
        /// <summary>
        /// 获取或创建文本单元格
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        public I3ReportCell GetOrCreateCellItem(int row, int col)
        {
            I3ReportCell item = GetCellItem(row, col);

            if (item == null)
            {
                item           = new I3ReportCell(row, col);
                this[row][col] = item;
            }
            return(item);
        }
Example #8
0
        /// <summary>
        /// 拆分单个合并单元格
        /// </summary>
        /// <param name="m"></param>
        /// <param name="reportData"></param>
        /// <returns></returns>
        private static I3MergeRange[] splitMemrgeRangeInDifPage(I3MergeRange m, I3ReportData reportData)
        {
            List <I3MergeRange> list = new List <I3MergeRange>();

            I3PrintArea startArea = getPrintAreaByRowIndex(m.StartRow, reportData);
            I3PrintArea endArea   = getPrintAreaByRowIndex(m.EndRow, reportData);

            //不在数据区,不做处理
            if (startArea == null || endArea == null)
            {
                list.Add(m);
                return(list.ToArray());
            }

            //在同一页,不做处理
            if (startArea.Index == endArea.Index)
            {
                list.Add(m);
                return(list.ToArray());
            }

            //开始拆分
            I3MergeRange m1 = new I3MergeRange(m.StartRow, m.StartCol, startArea.MaxDataAreaRowIndex, m.EndCol);

            if (m1.EndRow > m1.StartRow || m1.EndCol > m1.StartCol)//判断是否是一个有效的合并单元格
            {
                list.Add(m1);
            }
            I3MergeRange m2 = new I3MergeRange(endArea.MinDataAreaRowIndex, m.StartCol, m.EndRow, m.EndCol);
            //m2的样式同m
            I3ReportCell mCell  = reportData.Rows[m.StartRow][m.StartCol];
            I3ReportCell m2Cell = reportData.Rows[m2.StartRow][m2.StartCol];

            m2Cell.MergState = I3MergeState.FirstCell;
            m2Cell.StyleName = mCell.StyleName;
            if (!string.IsNullOrEmpty(mCell.Text))
            {
                m2Cell.Text = "...";
            }
            if (m2.EndRow - m2.StartRow > 0)                                       //后面的部分超过了一行
            {
                I3MergeRange[] newArr = splitMemrgeRangeInDifPage(m2, reportData); //继续拆分
                list.AddRange(newArr);
            }
            else//后面的部分只有一行
            {
                if (m2.EndCol > m2.StartCol)//存在列的合并
                {
                    list.Add(m2);
                }
            }

            return(list.ToArray());
        }
Example #9
0
        /// <summary>
        /// 计算单元格的剪切区域
        /// 如果是合并单元格,不包含合并区域的其他格子
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="cell"></param>
        /// <param name="area"></param>
        /// <param name="scale"></param>
        /// <param name="dataRect"></param>
        /// <param name="mergedCell"></param>
        /// <returns></returns>
        private static RectangleF CalCellClipRect_Scale(I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, float scale, RectangleF dataRect, RectangleF fullRect, RectangleF areaRect)
        {
            RectangleF rect = CalCellClipRect_UnScale(reportDatas, cell, area);

            rect = ScaleAndMoveCellRect(rect, reportDatas, cell, area, scale, dataRect);
            RectangleF clipRect = CalCellClipRect_Large(area, cell, reportDatas, fullRect, dataRect, areaRect);

            rect.Intersect(clipRect);

            return(rect);
        }
        public void OnCellItemMouseLeave(I3ReportCell cell)
        {
            if (cell == this.MouseOnCell)
            {
                this.MouseOnCell = null;
            }

            if (!this.DesignMode && CellItemMouseLeave != null)
            {
                CellItemMouseLeave(this, new I3CellItemEventArgs(cell));
            }
        }
Example #11
0
        //protected virtual TextFormatFlags GetTextFormatFlags(I3ReportCell cell, I3ReportCellStyle style)
        //{
        //    TextFormatFlags sf = TextFormatFlags.Default;

        //    switch (style.Alignment)
        //    {
        //        case StringAlignment.Near:
        //            sf = sf | TextFormatFlags.Left;
        //            break;
        //        case StringAlignment.Center:
        //            sf = sf | TextFormatFlags.HorizontalCenter;
        //            break;
        //        case StringAlignment.Far:
        //            sf = sf | TextFormatFlags.Right;
        //            break;
        //    }
        //    switch (style.LineAlignment)
        //    {
        //        case StringAlignment.Near:
        //            sf = sf | TextFormatFlags.Top;
        //            break;
        //        case StringAlignment.Center:
        //            sf = sf | TextFormatFlags.VerticalCenter;
        //            break;
        //        case StringAlignment.Far:
        //            sf = sf | TextFormatFlags.Bottom;
        //            break;
        //    }
        //    if (!string.IsNullOrEmpty(cell.Text) && cell.Text.IndexOf(NewLineFlag) >= 0)//文本中手工插入了换行符,强制不能进行自动换行
        //    {
        //        //sf.FormatFlags = StringFormatFlags.NoWrap;
        //    }
        //    else
        //    {
        //        if (style.WordWrap)
        //        {
        //            sf = sf | TextFormatFlags.WordBreak;
        //            sf = sf | TextFormatFlags.NoPadding;
        //        }
        //    }

        //    //sf.Trimming = cell.StringTrimming;
        //    //sf.FormatFlags = sf.FormatFlags | StringFormatFlags.NoClip; //上下有显示不全而需要剪切时,指定不剪切
        //    return sf;
        //}

        protected virtual Font GetFont(float scale, I3ReportCell cell, I3ReportCellStyle style)
        {
            float fontSize = 0;

            if (cell.CalFontSize > 0)
            {
                fontSize = cell.CalFontSize;
            }
            else
            {
                fontSize = style.FontSize == 0 ? 13 : style.FontSize;
            }
            fontSize *= scale;
            Font font = new Font(style.FontName, fontSize, style.FontStyle, GraphicsUnit.Pixel);

            return(font);
        }
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (e.Button == MouseButtons.Left)
     {
         #region 左键按下
         if (VScrollVisible)
         {
             int oldValue = vScrollBar.Value;
             int offsetY  = e.Y - mouseDownPoint.Y;
             int newValue = vScrollBar.Value - offsetY;
             newValue         = newValue > vScrollBar.Maximum - vScrollBar.LargeChange ? vScrollBar.Maximum - vScrollBar.LargeChange : newValue;
             newValue         = newValue < 0 ? 0 : newValue;
             vScrollBar.Value = newValue;
             ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, oldValue, newValue);
             OnVerticalScroll(vScrollBar, args);
         }
         if (HScrollVisible)
         {
             int oldValue = hScrollBar.Value;
             int offsetX  = e.X - mouseDownPoint.X;
             int newValue = hScrollBar.Value - offsetX;
             newValue         = newValue > hScrollBar.Maximum - hScrollBar.LargeChange ? hScrollBar.Maximum - hScrollBar.LargeChange : newValue;
             newValue         = newValue < 0 ? 0 : newValue;
             hScrollBar.Value = newValue;
             ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, oldValue, newValue);
             OnHorizontalScroll(vScrollBar, args);
         }
         mouseDownPoint = new Point(e.X, e.Y);
         #endregion
     }
     else
     {
         I3ReportCell cell = TestCell(e.X, e.Y);
         if (cell != lastMoveCell && lastMoveCell != null)
         {
             OnCellItemMouseLeave(lastMoveCell);
         }
         if (cell != lastMoveCell && cell != null)
         {
             OnCellItemMouseIn(cell);
         }
         lastMoveCell = cell;
     }
 }
Example #13
0
        /// <summary>
        /// 重新计算单元格的大小,借以调整行、列的大小
        /// prepareNarrow:是否处理内容缩放
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        private static void ReCalCellSize(I3ReportData reportData, int row, int col, bool prepareNarrow)
        {
            #region 获取单元格、样式、合并区域对象
            I3ReportCell cell = reportData.GetCellItem(row, col);
            if (cell == null || cell.MergState == I3MergeState.Merged)  //单元格为空,或者是被合并的,不需要重新计算
            {
                return;
            }
            I3ReportCellStyle style = reportData.GetCellStyle(cell.StyleName); //没有样式设置,不用重新计算
            if (style == null)
            {
                return;
            }
            I3MergeRange range = cell.MergState == I3MergeState.FirstCell ? reportData.GetMergeRange(row, col) : null;
            if (range == null)
            {
                range = new I3MergeRange((short)row, (short)col, (short)row, (short)col);
            }
            #endregion

            #region 得到默认宽度、高度
            int width  = 0;
            int height = 0;
            for (int i = range.StartRow; i <= range.EndRow; i++)
            {
                height += reportData[i].Height;
            }
            for (int i = range.StartCol; i <= range.EndCol; i++)
            {
                width += reportData.Cols[i].Width;
            }
            if (width == 0 || height == 0)
            {
                return;
            }
            #endregion


            II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(reportData[row][col]);
            SizeF           needSize = renderer.CalCellNeedSize(width, height, style, cell);
            if (needSize != SizeF.Empty)
            {
                renderer.AdjustCellSize(width, height, needSize, style, cell, range, reportData, prepareNarrow);
            }
        }
Example #14
0
        protected virtual StringFormat GetStringFormat(I3ReportCell cell, I3ReportCellStyle style)
        {
            StringFormat sf = StringFormat.GenericDefault;

            sf.Alignment     = style.Alignment;
            sf.LineAlignment = style.LineAlignment;
            sf.Trimming      = cell.StringTrimming;
            if (!string.IsNullOrEmpty(cell.Text) && cell.Text.IndexOf(NewLineFlag) >= 0)//文本中手工插入了换行符,强制不能进行自动换行
            {
                sf.FormatFlags = StringFormatFlags.NoWrap;
            }
            else
            {
                sf.FormatFlags = style.WordWrap ? (StringFormatFlags)0 : StringFormatFlags.NoWrap;
            }
            sf.FormatFlags = sf.FormatFlags | StringFormatFlags.NoClip; //上下有显示不全而需要剪切时,指定不剪切
            return(sf);
        }
Example #15
0
        protected string GetText(I3ReportCell cell, I3PrintArea area)
        {
            if (string.IsNullOrEmpty(cell.Text))
            {
                return(cell.Text);
            }

            string text = cell.Text;

            if (text.IndexOf(PageIndexFlag) >= 0)
            {
                text = text.Replace(PageIndexFlag, (area.Index + 1).ToString());
            }
            if (text.IndexOf(PageCountFlag) >= 0)
            {
                text = text.Replace(PageCountFlag, area.Parent.Dic.Count.ToString());
            }
            return(text);
        }
Example #16
0
        /// <summary>
        /// 单元格为合并单元格时,获取合并单元格的第一个格子
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        public I3ReportCell GetMergedStartedCell(int row, int col)
        {
            I3ReportCell cell = this.GetCellItem(row, col);

            if (cell == null || cell.MergState != I3MergeState.Merged)
            {
                return(null);
            }

            foreach (I3MergeRange range in MergeRanges)
            {
                if (range.StartRow <= row && row <= range.EndRow && range.StartCol <= col && col <= range.EndCol)
                {
                    return(this.GetCellItem(range.StartRow, range.StartCol));
                }
            }

            return(null);
        }
Example #17
0
        /// <summary>
        /// 将此单元格的位置用I3MergeRange表示
        /// 为合并单元格时,返回合并区域
        /// </summary>
        public I3MergeRange GetRange_Mode1(I3ReportData reportData)
        {
            I3MergeRange range = null;

            switch (this.MergState)
            {
            case I3MergeState.Merged:
                I3ReportCell startCell = reportData.GetMergedStartedCell(this.Row, this.Col);
                range = reportData.GetMergeRange(startCell.Row, startCell.Col);
                break;

            case I3MergeState.FirstCell:
                range = reportData.GetMergeRange(this.Row, this.Col);
                break;

            default:
                range = new I3MergeRange((short)this.Row, (short)this.Col, (short)this.Row, (short)this.Col);
                break;
            }

            return(range);
        }
        private string getStyleKey(I3ReportCell cellData, I3ReportCellStyle cs, bool hasReturnInText, bool isLastRow, bool isLastCol)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(cs.TopBorder == null ? "nullTopBorder" : cs.TopBorder.ToString());
            sb.Append(cs.LeftBorder == null ? "nullLeftBorder" : cs.LeftBorder.ToString());
            sb.Append(cs.RightBorder == null ? "nullRightBorder" : cs.RightBorder.ToString());
            sb.Append(cs.BottomBorder == null ? "nullBottomBorder" : cs.BottomBorder.ToString());
            sb.Append(cs.Alignment);
            sb.Append(cs.LineAlignment);
            double fontSize = cs.AdjustSize == I3AdjustSize.缩小内容 && cellData.HasCalFontSize ? (double)cellData.CalFontSize : (double)cs.FontSize;

            sb.Append(fontSize);
            sb.Append(cs.FontName);
            sb.Append(cs.FontColor);
            sb.Append(cs.FontStyle);
            sb.Append(cs.WordWrap || hasReturnInText);
            sb.Append(isLastRow);
            sb.Append(isLastCol);
            sb.Append(cs.AdjustSize);
            return(sb.ToString().GetHashCode().ToString());
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            if (this.DesignMode || reportDatas == null)
            {
                return;
            }


            int pageIndex = TestPageIndex(e.X, e.Y);

            if (pageIndex >= 0)
            {
                //OnPageClicked(pageIndex);

                I3ReportCell cell = TestCell(pageIndex, e.X, e.Y);
                if (cell != null)
                {
                    OnCellItemDoubleClicked(cell);
                }
            }
        }
        /// <summary>
        /// 测试单元格
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private I3ReportCell TestCell(int pageIndex, int x, int y)
        {
            if (reportDatas == null || CellItemEventMode == ReportPrint.I3CellItemEventMode.None)
            {
                return(null);
            }

            I3ReportData reportData = reportDatas.GetReportDataByAreaIndex(pageIndex);
            int          row        = TestRow(pageIndex, x, y);
            int          col        = TestCol(pageIndex, x, y);

            if (row < 0 || col < 0)
            {
                return(null);
            }

            I3ReportCell cell = reportData[row][col];

            cell = cell.MergState == I3MergeState.Merged ? reportData.GetMergedStartedCell(row, col) : cell;
            switch (CellItemEventMode)
            {
            case I3CellItemEventMode.CellRect:
                return(cell);

            case I3CellItemEventMode.ContentRect:
                I3PrintArea     area        = reportDatas.PrintAreas.Dic[pageIndex];
                RectangleF      fullRect    = GetAreaPaperRect(area);
                RectangleF      dataRect    = GetAreaContentRect(area);
                RectangleF      rect        = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, dataRect, null);
                II3CellRenderer renderer    = I3CellRendererBuilder.GetRenderer(cell);
                RectangleF      contentRect = renderer.DrawContent(this.CreateGraphics(), Scale, reportData, cell, rect, reportData.GetCellStyle(cell.StyleName), area, false);
                RectangleF      testRect    = new RectangleF(x, y, 1, 1);
                return(contentRect.IntersectsWith(testRect) ? cell : null);

            default:
                return(null);
            }
        }
        /// <summary>
        /// 测试行
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private int TestRow(int pageIndex, int x, int y)
        {
            if (reportDatas == null || pageIndex < 0)
            {
                return(-1);
            }

            I3PrintArea area     = reportDatas.PrintAreas.Dic[pageIndex];
            RectangleF  fullRect = GetAreaPaperRect(area);
            RectangleF  dataRect = GetAreaContentRect(area);

            foreach (int row in area.AllRows)
            {
                int          firstCol = area.AllCols[0];
                I3ReportCell cell     = area.ReportData[row][firstCol];
                RectangleF   rect     = I3ReportPrintController.CalCellClipRect_Scale(reportDatas, cell, area, Scale, dataRect, fullRect);
                if (y >= rect.Top && y <= rect.Bottom)
                {
                    return(row);
                }
            }

            return(-1);
        }
        /// <summary>
        /// 测试列
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private int TestCol(int pageIndex, int x, int y)
        {
            if (reportDatas == null || pageIndex < 0)
            {
                return(-1);
            }

            I3PrintArea area     = reportDatas.PrintAreas.Dic[pageIndex];
            RectangleF  fullRect = GetAreaPaperRect(area);
            RectangleF  dataRect = GetAreaContentRect(area);

            foreach (int col in area.AllCols)
            {
                int          firstRow = area.AllRows[0];
                I3ReportCell cell     = area.ReportData[firstRow][col];
                RectangleF   rect     = I3ReportPrintController.CalCellClipRect_Scale(reportDatas, cell, area, Scale, dataRect, fullRect);
                if (x >= rect.Left && x <= rect.Right)
                {
                    return(col);
                }
            }

            return(-1);
        }
Example #23
0
        /// <summary>
        /// 转换为图片单元格,复制所有属性(目的是为了在ReportData经过json转换后,找回Cell中丢失的单元格类型信息,要求I3ReportImageCell代码中的属性,全部写在I3ReportCell中)
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        public I3ReportImageCell ConvertToImageItem(int row, int col)
        {
            I3ReportCell old = GetCellItem(row, col);

            if (old != null && old is I3ReportImageCell)
            {
                return(old as I3ReportImageCell);
            }

            I3ReportImageCell item = null;

            if (old == null)
            {
                item = new I3ReportImageCell(row, col);
            }
            else
            {
                string json = I3JsonConvert.ToJson(old);
                item = (I3ReportImageCell)I3JsonConvert.FromJson(json, typeof(I3ReportImageCell));
            }
            this[row][col] = item;

            return(item);
        }
Example #24
0
 public I3CellItemEventArgs(I3ReportCell cell)
 {
     this.cell = cell;
 }
        /// <summary>
        /// 右上角
        /// </summary>
        /// <param name="text"></param>
        private void DrawString2(string text, Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style, I3PrintArea area)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            StringFormat sf    = GetStringFormat(cell, style);
            Brush        brush = new SolidBrush(style.FontColor);
            Font         font  = GetFont(scale, cell, style);

            try
            {
                #region 计算文本绘制区域
                SizeF      sizeF = g.MeasureString(text, font, (int)rect.Width, sf);
                RectangleF r     = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
                r.X     += r.Width - 3 - sizeF.Width; //居右
                r.Width  = sizeF.Width;
                r.Y     += 5;                         //居上
                r.Height = sizeF.Height;
                #endregion

                if (!r.IsEmpty)
                {
                    g.DrawString(text, font, brush, r, sf);
                }
            }
            finally
            {
                font.Dispose();
                brush.Dispose();
                sf.Dispose();
            }
        }
 public override void AdjustCellSize(int width, int height, SizeF needSizeF, I3ReportCellStyle style, I3ReportCell cell, I3MergeRange range, I3ReportData reportData, bool prepareNarrow)
 {
     //不做处理
 }
 public override SizeF CalCellNeedSize(int orgWidth, int orgHeight, I3ReportCellStyle style, I3ReportCell cell)
 {
     return(SizeF.Empty);  //返回空,表示不需要做大小调整
 }
        /// <summary>
        /// 斜中间
        /// </summary>
        /// <param name="text"></param>
        private void DrawString3(string text, Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style, I3PrintArea area)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            StringFormat sf    = GetStringFormat(cell, style);
            Brush        brush = new SolidBrush(style.FontColor);
            Font         font  = GetFont(scale, cell, style);

            try
            {
                char[] chars       = text.ToCharArray();
                float  posx        = rect.Right - 3;
                float  xsplit      = 1;
                float  posy        = rect.Bottom;
                float  totalHeigth = GetTotalHeight(chars, g, font, sf);
                float  ysplit      = chars.Length == 0 ? 0 : (rect.Height / 2 - totalHeigth) / (chars.Length - 1);

                for (int i = chars.Length - 1; i >= 0; i--)
                {
                    string     str   = chars[i].ToString();
                    SizeF      sizeF = g.MeasureString(str, font, (int)rect.Width, sf);
                    RectangleF r     = new RectangleF(posx - sizeF.Width, posy - sizeF.Height, sizeF.Width, sizeF.Height);

                    if (!r.IsEmpty)
                    {
                        g.DrawString(str, font, brush, r, sf);
                    }

                    posx = posx - sizeF.Width - xsplit;
                    posy = posy - sizeF.Height - ysplit;
                }
            }
            finally
            {
                font.Dispose();
                brush.Dispose();
                sf.Dispose();
            }
        }
        public override RectangleF DrawContent(Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style, I3PrintArea area, bool draw)
        {
            string text = GetText(cell, area);

            if (!draw || string.IsNullOrEmpty(text))
            {
                return(RectangleF.Empty);
            }

            string[] values = text.Split(new char[] { '|', ',', ';' });


            if (values.Length > 2)
            {
                DrawLine2(g, rect);
                DrawString1(values[0], g, scale, reportData, cell, rect, style, area);
                DrawString2(values[1], g, scale, reportData, cell, rect, style, area);
                DrawString3(values[2], g, scale, reportData, cell, rect, style, area);
            }
            else
            {
                DrawLine1(g, rect);
                DrawString1(values[0], g, scale, reportData, cell, rect, style, area);
                if (values.Length > 1)
                {
                    DrawString2(values[1], g, scale, reportData, cell, rect, style, area);
                }
            }

            return(RectangleF.Empty);
        }
        private HSSFCellStyle createStyle(HSSFWorkbook workbook, I3ReportCell cellData, I3ReportCellStyle cs, Dictionary <string, IFont> fontDic, bool hasReturnInText, bool isLastRow, bool isLastCol)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();

            //设置边框格式
            //top
            if (cs.TopBorder == null || cs.TopBorder.Width <= 0)
            {
                style.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
            }
            else if (cs.TopBorder.Width >= 2)
            {
                style.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium;//粗实线
            }
            else
            {
                style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;//细实线
            }
            //left
            if (cs.LeftBorder == null || cs.LeftBorder.Width <= 0)
            {
                style.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
            }
            else if (cs.LeftBorder.Width >= 2)
            {
                style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
            }
            else
            {
                style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            }
            //right  //有边框行、列,右、下不用设置
            //if (isLastCol)
            //{
            //    if (cs.RightBorder == null || cs.RightBorder.Width <= 0)
            //    {
            //        style.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
            //    }
            //    else if (cs.RightBorder.Width >= 2)
            //    {
            //        style.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
            //    }
            //    else
            //    {
            //        style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            //    }
            //}
            //bottom
            //if (isLastRow)
            //{
            //    if (cs.BottomBorder == null || cs.BottomBorder.Width <= 0)
            //    {
            //        style.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
            //    }
            //    else if (cs.BottomBorder.Width >= 2)
            //    {
            //        style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
            //    }
            //    else
            //    {
            //        style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            //    }
            //}

            //边框颜色
            style.LeftBorderColor   = HSSFColor.Black.Index;
            style.RightBorderColor  = HSSFColor.Black.Index;
            style.BottomBorderColor = HSSFColor.Black.Index;
            style.TopBorderColor    = HSSFColor.Black.Index;

            //居中
            switch (cs.Alignment) //水平
            {
            case StringAlignment.Center:
                style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
                break;

            case StringAlignment.Far:
                style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Right;
                break;

            default:
                style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
                break;
            }
            switch (cs.LineAlignment)  //垂直
            {
            case StringAlignment.Center:
                style.VerticalAlignment = VerticalAlignment.Center;
                break;

            case StringAlignment.Far:
                style.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            default:
                style.VerticalAlignment = VerticalAlignment.Top;
                break;
            }

            //字体   //判断了自动缩小
            double fontSize = cs.AdjustSize == I3AdjustSize.缩小内容 && cellData.HasCalFontSize ? (double)cellData.CalFontSize : (double)cs.FontSize;
            var    fontHash = string.Format("{0}{1}{2}{3}", cs.FontName, fontSize, cs.FontColor.ToArgb(), cs.FontStyle).GetHashCode().ToString();

            if (fontDic.ContainsKey(fontHash))
            {
                style.SetFont(fontDic[fontHash]);
            }
            else
            {
                IFont font = workbook.CreateFont();
                font.FontName = cs.FontName;
                fontSize      = fontSize * (double)10 / (double)13;
                //fontSize = cs.FontSize * (double)72 / (double)96;
                font.FontHeightInPoints = (short)fontSize;
                style.SetFont(font);
                fontDic.Add(fontHash, font);
            }

            //自动换行
            style.WrapText = cs.WordWrap || hasReturnInText;

            //锁定
            style.IsLocked = cellData.Lock;

            return(style);
        }