//重绘单元格
        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);
        }
예제 #2
0
        private void setCellStyle(HSSFWorkbook workbook, ISheet sheet, ICell cell, I3PrintArea area, I3ReportCell cellData,
                                  Dictionary <string, HSSFCellStyle> styleDic, Dictionary <string, IFont> fontDic, bool hasReturnInText, bool isLastRow, bool isLastCol,
                                  HSSFCellStyle emptyStyle)
        {
            I3ReportCellStyle cs = null;

            if (cellData.MergState == I3MergeState.Merged)
            {
                cellData = area.ReportData.GetMergedStartedCell(cellData.Row, cellData.Col);
            }
            cs = area.ReportData.GetCellStyle(cellData.StyleName);
            if (cs == null)
            {
                cell.CellStyle = emptyStyle;
                return;
            }

            string        styleKey = getStyleKey(cellData, cs, hasReturnInText, isLastRow, isLastCol);
            HSSFCellStyle style    = null;

            if (styleDic.ContainsKey(styleKey))
            {
                style = styleDic[styleKey];
            }
            else
            {
                style = createStyle(workbook, cellData, cs, fontDic, hasReturnInText, isLastRow, isLastCol);
                styleDic.Add(styleKey, style);
            }

            cell.CellStyle = style;
        }
예제 #3
0
        /// <summary>
        /// 打印页码
        /// </summary>
        private static void PaintPageIndex(Graphics g, float scale, RectangleF fullRect, RectangleF dataRect,
                                           I3ReportDatas reportDatas, I3PrintArea area, bool paintPageIndex, int index)
        {
            if (!paintPageIndex)
            {
                return;
            }

            int currentIndex = index + 1 + reportDatas.PageIndexStart - 1;

            if (currentIndex > 0)//当前的页码必须大于0才打印
            {
                string text = string.Format("第{0}页/共{1}页", currentIndex, reportDatas.TotalPageCount);
                g.SetClip(fullRect);
                float fontSize = 13 * scale;
                using (Font font = new Font("宋体", fontSize))
                {
                    StringFormat stringFormat = StringFormat.GenericDefault;
                    stringFormat.Alignment     = StringAlignment.Near;
                    stringFormat.LineAlignment = StringAlignment.Near;
                    stringFormat.Trimming      = StringTrimming.None;
                    stringFormat.FormatFlags   = (StringFormatFlags)0;
                    SizeF      sizeF    = g.MeasureString(text, font, 5000, stringFormat);
                    RectangleF textRect = new RectangleF(0, 0, sizeF.Width + 2, sizeF.Height + 2);
                    textRect.Y = fullRect.Y + 20 * scale;
                    textRect.X = fullRect.X + fullRect.Width - 50 * scale - textRect.Width;
                    g.SetClip(textRect);
                    g.DrawString(text, font, Brushes.Black, textRect.X + 1, textRect.Y + 1);
                }
            }
        }
예제 #4
0
        private static I3PrintAreas CalPrintAreasByCols(I3ReportData reportData, I3PrintAreas rowAreas)
        {
            I3PageSetting setting    = reportData.PageSetting;
            float         paperWidth = setting.PaperContentRect.Width;

            I3PrintAreas printAreas = new I3PrintAreas();

            foreach (int row in rowAreas.Dic.Keys)
            {
                I3PrintArea rowArea    = rowAreas.Dic[row];
                float       totalWidth = rowArea.Width;
                List <int>  cols       = new List <int>();
                for (int j = 0; j < reportData.ColCount; j++)
                {
                    if (reportData.Cols[j].Type != I3RowColType.数据 || reportData.Cols[j].Type == I3RowColType.None)
                    {
                        continue;
                    }
                    int colWidth = reportData.Cols[j].Width;

                    #region 在此列前分页
                    //列后分页,条件:已有列被添加,前面一列的列后分页属性=true,已有列的总宽度>0
                    bool breakBeforeThisCol = cols.Count > 0 && reportData.Cols[cols[cols.Count - 1]].PageBreak && totalWidth > rowArea.Width;
                    //尺寸超过
                    breakBeforeThisCol = breakBeforeThisCol || (setting.ColsPagerStyle == PagerStyle.纸张尺寸分页 && totalWidth + colWidth > paperWidth);
                    //列数超过
                    breakBeforeThisCol = breakBeforeThisCol || (setting.ColsPagerStyle == PagerStyle.数据行列数分页 && cols.Count >= setting.ColsPerPage);

                    if (breakBeforeThisCol)
                    {
                        I3PrintArea area = rowArea.Clone().AddCols(cols);
                        area.Width = totalWidth;
                        printAreas.Add(printAreas.Dic.Count, area);
                        totalWidth = rowArea.Width + colWidth;
                        cols.Clear();
                        cols.Add(j);
                        continue;
                    }
                    #endregion

                    //不分页
                    totalWidth += colWidth;
                    cols.Add(j);
                }

                //最后有些列未能分页
                if (cols.Count > 0)
                {
                    I3PrintArea area = rowArea.Clone().AddCols(cols);
                    area.Height = totalWidth;
                    printAreas.Add(printAreas.Dic.Count, area);
                }
            }
            return(printAreas);
        }
예제 #5
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());
        }
예제 #6
0
        private static I3PrintAreas CalPrintAreasByRows(I3ReportData reportData)
        {
            I3PageSetting setting     = reportData.PageSetting;
            float         paperHeight = setting.PaperContentRect.Height;
            I3PrintArea   defaultArea = GetDefaultRowPrintArea(reportData);

            //先按行划分
            I3PrintAreas rowPrintAreas = new I3PrintAreas();
            float        totalHeight   = defaultArea.Height;
            List <int>   rows          = new List <int>();

            for (int i = 0; i < reportData.RowCount; i++)
            {
                if (reportData[i].Type != I3RowColType.数据 || reportData[i].Type == I3RowColType.None)
                {
                    continue;
                }
                int rowHeight = reportData[i].Height;

                #region 在此行前分页
                //已有行被添加,前面一行的行后分页属性=true,已有行的总高度>0
                bool breakBeforeThisRow = rows.Count > 0 && reportData[rows[rows.Count - 1]].PageBreak && totalHeight > defaultArea.Height;
                //尺寸超过  条件:加上当前行后超过
                breakBeforeThisRow = breakBeforeThisRow || (setting.RowsPagerStyle == PagerStyle.纸张尺寸分页 && totalHeight + rowHeight > paperHeight);
                //行数超过
                breakBeforeThisRow = breakBeforeThisRow || (setting.RowsPagerStyle == PagerStyle.数据行列数分页 && rows.Count >= setting.RowsPerPage);

                if (breakBeforeThisRow)
                {
                    I3PrintArea area = defaultArea.Clone().AddRows(rows);
                    area.Height = totalHeight;
                    rowPrintAreas.Add(rowPrintAreas.Dic.Count, area);
                    totalHeight = defaultArea.Height + rowHeight;
                    rows.Clear();
                    rows.Add(i);  //不能用i--,如果某行大于整页宽度,会死循环
                    continue;
                }
                #endregion

                //不分页
                totalHeight += rowHeight;
                rows.Add(i);
            }

            //最后有些行未能分页
            if (rows.Count > 0)
            {
                I3PrintArea area = defaultArea.Clone().AddRows(rows);
                area.Height = totalHeight;
                rowPrintAreas.Add(rowPrintAreas.Dic.Count, area);
            }

            return(rowPrintAreas);
        }
예제 #7
0
        /// <summary>
        /// 创建副本
        /// </summary>
        /// <returns></returns>
        public I3PrintArea Clone()
        {
            I3PrintArea area = new I3PrintArea();

            CopyList(this.headerRows, area.headerRows);
            CopyList(this.footerRows, area.footerRows);
            CopyList(this.dataRows, area.dataRows);
            CopyList(this.headerCols, area.headerCols);
            CopyList(this.footerCols, area.footerCols);
            CopyList(this.dataCols, area.dataCols);
            area.width  = this.width;
            area.height = this.height;
            return(area);
        }
예제 #8
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);
        }
        /// <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);
        }
예제 #12
0
        /// <summary>
        /// 计算实际内容页面的绘制区域(经过缩放后)  (可能不会占满内容区域,也可能超过)
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="area"></param>
        /// <param name="dataRect"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private static RectangleF CalAreaDrawRect_Scale(I3ReportDatas reportDatas, I3PrintArea area, RectangleF dataRect, float scale)
        {
            RectangleF rect = new RectangleF(0, 0, 0, 0);

            foreach (int row in area.DataRows.Keys)
            {
                rect.Height += area.ReportData[row].Height;
            }
            foreach (int col in area.DataCols.Keys)
            {
                rect.Width += area.ReportData.Cols[col].Width;
            }


            rect.X     *= scale;
            rect.Width *= scale;
            rect.X     += dataRect.X;

            rect.Y      *= scale;
            rect.Height *= scale;
            rect.Y      += dataRect.Y;

            return(rect);
        }
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            using (Brush brush = new SolidBrush(this.BackColor))
            {
                e.Graphics.FillRectangle(brush, new Rectangle(0, 0, this.Width, this.Height));
            }
            if (this.DesignMode || reportDatas == null)
            {
                return;
            }
            RectangleF oldClip = e.Graphics.ClipBounds;

            RectangleF clientRect      = new RectangleF(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight);
            bool       firstPageShowed = false;

            for (int index = 0; index < reportDatas.PrintAreas.Dic.Count; index++)
            {
                #region 纸张区域
                I3PrintArea area      = reportDatas.PrintAreas.Dic[index];
                RectangleF  paperRect = GetAreaPaperRect(area);
                if (!paperRect.IntersectsWith(oldClip) || !paperRect.IntersectsWith(clientRect))
                {
                    continue;
                }
                if (!firstPageShowed)
                {
                    firstPageShowed = true;
                    CurPageIndex    = index;
                }
                #endregion

                #region 内容区域
                RectangleF contentRect = GetAreaContentRect(area);
                //内容区域不用作剪切区域判断,(非内容区域也需要绘制)
                #endregion

                #region 绘制
                I3ReportPrintController.PrintAreaToGraphics(e.Graphics, Scale, paperRect, contentRect, reportDatas, area, PaintPageIndex2, index);
                e.Graphics.SetClip(oldClip);
                #endregion

                #region 缩略图页码
                if (PaintPageIndex)
                {
                    string text = string.Format("{0}/{1}", index + 1, reportDatas.PrintAreas.Dic.Count);
                    //缩略图页面还是显示本数据的
                    //string text = string.Format("{0}/{1}", index + 1 + reportData.PageIndexStart - 1, reportData.TotalPageCount);
                    e.Graphics.SetClip(paperRect);
                    using (Font font = new Font("宋体", 10))
                    {
                        StringFormat stringFormat = StringFormat.GenericDefault;
                        stringFormat.Alignment     = StringAlignment.Near;
                        stringFormat.LineAlignment = StringAlignment.Near;
                        stringFormat.Trimming      = StringTrimming.None;
                        stringFormat.FormatFlags   = (StringFormatFlags)0;
                        SizeF      sizeF    = e.Graphics.MeasureString(text, font, 200, stringFormat);
                        RectangleF textRect = new RectangleF(0, 0, sizeF.Width, sizeF.Height);
                        textRect.Y = paperRect.Y + paperRect.Height - 2 - sizeF.Height;
                        textRect.X = paperRect.X + paperRect.Width - 2 - sizeF.Width;
                        e.Graphics.SetClip(textRect);
                        e.Graphics.DrawString(text, font, Brushes.Red, textRect);
                    }
                }
                #endregion


                #region FoucesedCell、MouseOnCell
                if (HighlightFoucesedCell && this.FoucesedCell != null)
                {
                    if (new List <int>(area.AllRows).IndexOf(this.FoucesedCell.Row) >= 0 && new List <int>(area.AllCols).IndexOf(this.FoucesedCell.Col) >= 0)
                    {
                        RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, this.FoucesedCell, area, Scale, contentRect, null);
                        e.Graphics.SetClip(rect);
                        Pen pen = new Pen(Brushes.Red, 6);
                        e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                    }
                }

                if (HighlightMouseOnCell && this.MouseOnCell != null)
                {
                    if (new List <int>(area.AllRows).IndexOf(this.MouseOnCell.Row) >= 0 && new List <int>(area.AllCols).IndexOf(this.MouseOnCell.Col) >= 0)
                    {
                        RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, this.MouseOnCell, area, Scale, contentRect, null);
                        e.Graphics.SetClip(rect);
                        Pen pen = new Pen(Brushes.Blue, 6);
                        e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                    }
                }
                #endregion

                e.Graphics.SetClip(oldClip);
            }
        }
예제 #14
0
        /// <summary>
        /// 计算剪切区域
        /// 如果是合并单元格,不包含整个合并区域,只包含单元格本身
        /// 必须经过平移、缩放放才有意义
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="cell"></param>
        /// <param name="area"></param>
        /// <returns></returns>
        private static RectangleF CalCellClipRect_UnScale(I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area)
        {
            int          row     = cell.Row;
            int          col     = cell.Col;
            I3RowColType rowType = area.ReportData[row].Type;
            I3RowColType colType = area.ReportData.Cols[col].Type;

            RectangleF rect = new RectangleF(0F, 0F, 0F, 0F);

            #region Y
            IList <int> rows = null;
            switch (rowType)
            {
            case I3RowColType.页眉:
                rows = area.HeaderRows.Keys;
                break;

            case I3RowColType.页脚:
                rows = area.FooterRows.Keys;
                break;

            default:
                rows = area.DataRows.Keys;
                break;
            }
            foreach (int i in rows)
            {
                if (i < row)
                {
                    rect.Y += area.ReportData[i].Height;
                }
            }
            #endregion

            rect.Height = area.ReportData[cell.Row].Height;

            #region X
            IList <int> cols = null;
            switch (colType)
            {
            case I3RowColType.页眉:
                cols = area.HeaderCols.Keys;
                break;

            case I3RowColType.页脚:
                cols = area.FooterCols.Keys;
                break;

            default:
                cols = area.DataCols.Keys;
                break;
            }
            foreach (int i in cols)
            {
                if (i < col)
                {
                    rect.X += area.ReportData.Cols[i].Width;
                }
            }
            #endregion

            rect.Width = area.ReportData.Cols[cell.Col].Width;

            return(rect);
        }
예제 #15
0
        /// <summary>
        /// 在画布的指定区域绘制内容
        /// fullRect、dataRect都要求是缩放、平移过后的,在画面上的正确区域(由于来源可能是控件、纸张,因此需要调用处计算好后传进来)
        /// </summary>
        /// <param name="graphicsKey"></param>
        /// <param name="g"></param>
        /// <param name="scale"></param>
        /// <param name="fullRect">页面的完整绘制区域</param>
        /// <param name="dataRect">页面的内容区域(去除页边距)</param>
        /// <param name="reportData"></param>
        /// <param name="area"></param>
        public static void PrintAreaToGraphics(Graphics g, float scale, RectangleF fullRect, RectangleF dataRect,
                                               I3ReportDatas reportDatas, I3PrintArea area, bool paintPageIndex, int index)
        {
            //求剪切区域
            RectangleF clipRect = fullRect;

            clipRect.Intersect(g.ClipBounds);
            RectangleF areaRect = CalAreaDrawRect_Scale(reportDatas, area, dataRect, scale);  //先准备好避免重复计算

            clipRect.Intersect(areaRect);

            //画整个背景
            g.FillRectangle(Brushes.White, fullRect);

            if (clipRect.IsEmpty)
            {
                PaintPageIndex(g, scale, fullRect, dataRect, reportDatas, area, paintPageIndex, index);
                PaintPageHeader(g, scale, fullRect, dataRect, reportDatas, area, paintPageIndex, index);
                return;
            }

            #region 先画背景和内容
            foreach (int row in area.AllRows)
            {
                #region 行测试
                //2017.04.26 为加快绘制速度,合并单元格不单独处理,以绘制合并首格为准
                //因此需要去掉行、列测试,因为有可能只需要重绘合并单元格,但合并首格不丰重绘区域内
                //if (reportData.Rows[row].Type == I3RowColType.None)
                //{
                //    continue;
                //}
                //I3ReportCell testCell = reportData.GetCellItem(row, 0);
                //RectangleF testRect = CalCellClipRect_Scale(reportData, testCell, area, scale, dataRect, fullRect, areaRect);
                //if (testRect.Bottom < clipRect.Top || testRect.Top > clipRect.Bottom)
                //{
                //    continue;
                //}
                #endregion


                foreach (int col in area.AllCols)
                {
                    #region 列测试
                    //if (reportData.Cols[col].Type == I3RowColType.None)
                    //{
                    //    continue;
                    //}
                    //testCell = reportData.GetCellItem(0, col);
                    //testRect = CalCellClipRect_Scale(reportData, testCell, area, scale, dataRect, fullRect, areaRect);
                    //if (testRect.Right < clipRect.Left || testRect.Left > clipRect.Right)
                    //{
                    //    continue;
                    //}
                    #endregion


                    I3ReportCell cell = area.ReportData.GetCellItem(row, col);
                    //2017.04.26 为加快绘制速度,合并单元格不单独处理
                    if (cell.MergState != I3MergeState.Merged)
                    {
                        //内容
                        g.SetClip(clipRect);
                        DrawCell(g, fullRect, dataRect, areaRect, scale, reportDatas, cell, area, null, true, false, true);

                        //边框  //在这里画边框,缩放时有的边框线会显示不出来
                        //g.SetClip(clipRect);
                        //DrawCell(g, fullRect, dataRect, areaRect, scale, reportDatas, cell, area, null, false, true, false);
                    }
                }
            }
            #endregion

            #region 画边框  //在这里画边框,合并单元格跨页时,会将第2页的线条多画在第1页的末尾,因此必须拆分一下合并单元格
            foreach (int row in area.AllRows)
            {
                foreach (int col in area.AllCols)
                {
                    I3ReportCell cell = area.ReportData.GetCellItem(row, col);
                    //2017.04.26 为加快绘制速度,合并单元格不单独处理
                    if (cell.MergState != I3MergeState.Merged)
                    {
                        //边框
                        g.SetClip(clipRect);
                        DrawCell(g, fullRect, dataRect, areaRect, scale, reportDatas, cell, area, null, false, true, false);
                    }
                }
            }
            #endregion


            #region 页码、页眉
            PaintPageIndex(g, scale, fullRect, dataRect, reportDatas, area, paintPageIndex, index);
            PaintPageHeader(g, scale, fullRect, dataRect, reportDatas, area, paintPageIndex, index);
            #endregion


            #region 111
            //2017.04.26 为加快绘制速度,将画边框放到上面的代码中,减少行、列测试
            //再画边框
            //foreach (int row in area.AllRows)
            //{
            //    #region 行测试
            //    if (reportData.Rows[row].Type == I3RowColType.None)
            //    {
            //        continue;
            //    }
            //    I3ReportCell testCell = reportData.GetCellItem(row, 0);
            //    RectangleF testRect = CalCellClipRect_Scale(reportData, testCell, area, scale, dataRect, fullRect, areaRect);
            //    if (testRect.Bottom < clipRect.Top || testRect.Top > clipRect.Bottom)
            //    {
            //        continue;
            //    }
            //    #endregion

            //    foreach (int col in area.AllCols)
            //    {
            //        #region 列测试
            //        if (reportData.Cols[col].Type == I3RowColType.None)
            //        {
            //            continue;
            //        }
            //        testCell = reportData.GetCellItem(0, col);
            //        testRect = CalCellClipRect_Scale(reportData, testCell, area, scale, dataRect, fullRect, areaRect);
            //        if (testRect.Right < clipRect.Left || testRect.Left > clipRect.Right)
            //        {
            //            continue;
            //        }
            //        #endregion

            //        I3ReportCell cell = reportData.GetCellItem(row, col);
            //        g.SetClip(clipRect);
            //        DrawCell(g, fullRect, dataRect, areaRect, scale, reportData, cell, area, null, false, true, false);
            //    }
            //}
            #endregion
        }
예제 #16
0
 public new void Add(int index, I3PrintArea area)
 {
     area.Index  = index;
     area.Parent = this;
     this.Dic.Add(index, area);
 }
예제 #17
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);
        }
예제 #18
0
        private static RectangleF ScaleAndMoveCellRect(RectangleF rect, I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, float scale, RectangleF dataRect)
        {
            #region 缩放
            rect.X      *= scale;
            rect.Y      *= scale;
            rect.Width  *= scale;
            rect.Height *= scale;
            #endregion

            #region 将Y位置根据行的类型移动
            float headerHeight = 0;
            foreach (int i in area.HeaderRows.Keys)
            {
                headerHeight += area.ReportData[i].Height;
            }
            switch (area.ReportData[cell.Row].Type)
            {
            case I3RowColType.页眉:
                rect.Y += dataRect.Y - headerHeight;
                break;

            case I3RowColType.页脚:
                rect.Y += dataRect.Y + dataRect.Height;
                break;

            default:
                rect.Y += dataRect.Y;
                break;
            }
            #endregion

            #region 将X位置根据列的类型移动
            float headerWidth = 0;
            foreach (int i in area.HeaderCols.Keys)
            {
                headerWidth += area.ReportData.Cols[i].Width;
            }
            switch (area.ReportData.Cols[cell.Col].Type)
            {
            case I3RowColType.页眉:
                rect.X += dataRect.X - headerWidth;
                break;

            case I3RowColType.页脚:
                rect.X += dataRect.X + dataRect.Width;
                break;

            default:
                rect.X += dataRect.X;
                break;
            }
            #endregion

            return(rect);
        }
        /// <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();
            }
        }
예제 #20
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>
        public static RectangleF CalCellClipRect_Scale(I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, float scale, RectangleF dataRect, RectangleF fullRect)
        {
            RectangleF areaRect = CalAreaDrawRect_Scale(reportDatas, area, dataRect, scale);
            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);
        }
예제 #21
0
        /// <summary>
        /// 将单元格输出到画布上
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        private static void DrawCell(Graphics g, RectangleF fullRect, RectangleF dataRect, RectangleF areaRect, float scale, I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, I3ReportCell mergedCell,
                                     bool drawBackground, bool drawBorder, bool drawContect)
        {
            #region 合并单元格中的格子处理
            if (cell != null && cell.MergState == I3MergeState.Merged)
            {
                //2017.04.26 为加快绘制速度,合并单元格不处理
                return;
                //I3ReportCell firstCell = reportData.GetMergedStartedCell(cell.Row, cell.Col);
                //if (firstCell != null)
                //{
                //    DrawCell(g, fullRect, dataRect, areaRect, scale, reportData, firstCell, area, cell, drawBackground, drawBorder, drawContect);
                //}
                //return;
            }
            #endregion

            #region 绘制区域、剪切区域
            RectangleF cellDrawRect = CalCellDrawRect_Scale(reportDatas, cell, area, scale, dataRect, mergedCell);
            if (cellDrawRect.IsEmpty)
            {
                return;
            }

            //2017.04.26 为加快绘制速度,不做单元格剪切区域计算,直接使用原始的剪切区域
            //I3ReportCell destCell = mergedCell == null ? cell : mergedCell;  //计算剪切区域使用真实单元格
            //RectangleF clipRect = CalCellClipRect_Scale(reportData, destCell, area, scale, dataRect, fullRect, areaRect);
            ////destCell.SetCellRect(graphicsKey, clipRect);
            //clipRect.Intersect(g.ClipBounds);
            //if (clipRect.IsEmpty)
            //{
            //    return;
            //}

            //g.SetClip(clipRect);
            #endregion

            #region 样式
            I3ReportCellStyle style = area.ReportData.GetCellStyle(cell.StyleName);
            if (style == null)
            {
                return;
            }
            #endregion

            II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(cell);
            RectangleF      oldClip  = g.ClipBounds;

            //背景
            if (drawBackground)
            {
                g.SetClip(oldClip);
                g.FillRectangle(Brushes.White, cellDrawRect);
                renderer.DrawBackground(g, scale, area.ReportData, cell, cellDrawRect, style);
            }

            //边框
            if (drawBorder)
            {
                RectangleF borderClipRect = oldClip;  //扩大避免边框画不全
                borderClipRect.Inflate(1, 1);
                g.SetClip(borderClipRect);
                renderer.DrawCellBorder(g, scale, area.ReportData, cell, cellDrawRect, style);
            }

            //内容
            if (drawContect)
            {
                g.SetClip(oldClip);
                renderer.DrawContent(g, scale, area.ReportData, cell, cellDrawRect, style, area, true);
            }
        }
예제 #22
0
        /// <summary>
        /// 打印页眉
        /// </summary>
        private static void PaintPageHeader(Graphics g, float scale, RectangleF fullRect, RectangleF dataRect,
                                            I3ReportDatas reportDatas, I3PrintArea area, bool paintPageIndex, int index)
        {
            //test
            //area.ReportData.PageHeader = I3PageHeader.Default;
            //area.ReportData.PageHeader.Text = "报表打印工具报表打印工具报表打印工具{r}报表打印工具报表打印111报表打印工具报表打印工具报表打印工具报表打印工具报表打印222报表打印工具报表打印工具报表打印工具报表打印工具报表打印333报表打印工具报表打印工具报表打印工具报表打印工具报表打印444报表打印工具报表打印工具报表打印工具报表打印工具报表打印555";

            if (area.ReportData.PageHeader == null || string.IsNullOrEmpty(area.ReportData.PageHeader.Text))
            {
                return;
            }

            I3PageHeader ph    = area.ReportData.PageHeader;
            Font         font  = new Font(ph.FontName, ph.FontSize * scale);
            Brush        brush = new SolidBrush(ph.BrushColor);

            string[] strs = ph.Text.Split(new string[] { NewLineFlag }, StringSplitOptions.None);
            if (strs.Length > 1)//多于2行时强制关闭自动换行功能,由代码来进行控制
            {
                ph.StringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip;
            }


            //毫米转换为像素公式是 y = y * 96 / 25.39999918
            float      marginLeft  = ph.MarginLeft * scale;
            float      marginTop   = ph.MarginTop * scale;
            float      marginRight = ph.MarginRight * scale;
            RectangleF rect        = fullRect;

            rect.X      += marginLeft;
            rect.Width  -= marginLeft;
            rect.Y      += marginTop;
            rect.Height -= marginTop;
            rect.Width  -= marginRight;
            g.SetClip(fullRect);

            try
            {
                //先计算正常位置
                RectangleF        rr       = RectangleF.Empty;
                List <RectangleF> rectList = new List <RectangleF>();
                float             startY   = float.MaxValue; //上线
                float             endY     = float.MinValue; //下线
                foreach (string str in strs)
                {
                    #region 计算文本绘制区域
                    SizeF      sizeF = g.MeasureString(str, font, (int)rect.Width, ph.StringFormat);
                    RectangleF r     = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
                    if (ph.StringFormat.LineAlignment == StringAlignment.Center)
                    {
                        r.X    += r.Width / 2 - sizeF.Width / 2;
                        r.Width = sizeF.Width;
                    }
                    else if (ph.StringFormat.LineAlignment == StringAlignment.Far)
                    {
                        r.X    += r.Width - sizeF.Width;
                        r.Width = sizeF.Width;
                    }
                    else
                    {
                        r.Width = sizeF.Width;
                    }
                    r.Height = sizeF.Height;
                    #endregion

                    rectList.Add(r);
                    startY = Math.Min(startY, r.Y);
                    endY   = Math.Max(endY, r.Y + r.Height);
                }
                float centerY = startY + (endY - startY) / 2;//中线
                float stepY   = endY - startY;

                //再计算换行引起的位置偏移
                int i = -1;
                foreach (string str in strs)
                {
                    i++;
                    RectangleF r = rectList[i];
                    #region 换行位置调整
                    if (strs.Length > 0)//有多行才做调整
                    {
                        r.Y = startY + stepY * i;
                    }
                    #endregion

                    #region 绘制
                    g.DrawString(str, font, brush, r, ph.StringFormat);
                    #endregion

                    #region 相交区域处理
                    if (rr == RectangleF.Empty)
                    {
                        rr = r;
                    }
                    else
                    {
                        rr.Y = Math.Min(rr.Y, r.Y);                              //y取最小值
                        float yEnd = Math.Max(rr.Y + rr.Height, r.Y + r.Height); //yEnd取最大值
                        rr.Height = yEnd - rr.Y;
                        rr.X      = Math.Min(rr.X, r.X);                         //x取最小值
                        float xEnd = Math.Max(rr.X + rr.Width, r.X + r.Width);   //xEnd取最大值
                        rr.Width = xEnd - rr.X;
                    }
                    #endregion
                }
            }
            finally
            {
                font.Dispose();
                brush.Dispose();
            }
        }
        private RectangleF GetAreaContentRect(I3PrintArea area)
        {
            I3ReportData  reportData  = reportDatas.GetReportDataByAreaIndex(area.Index);
            I3PageSetting setting     = reportData.PageSetting;
            float         offsetY     = vScrollBar.Value;
            float         offsetX     = hScrollBar.Value;
            RectangleF    contentRect = new RectangleF(setting.PaperContentRect.X * scale, setting.PaperContentRect.Y * scale, setting.PaperContentRect.Width * scale, setting.PaperContentRect.Height * scale);

            //调整y位置
            for (int i = 0; i < area.Index; i++)
            {
                I3ReportData  rd = reportDatas.GetReportDataByAreaIndex(i);
                I3PageSetting s  = rd.PageSetting;
                contentRect.Y = contentRect.Y + s.PaperRect.Height * scale + pageInterval;
            }
            contentRect.Y = contentRect.Y + pageInterval - offsetY;
            if (!VScrollVisible && !alignTop)
            {
                float totalHeight = 0;
                for (int i = 0; i < reportDatas.PrintAreas.Dic.Count; i++)
                {
                    I3ReportData  rd = reportDatas.GetReportDataByAreaIndex(i);
                    I3PageSetting s  = rd.PageSetting;
                    totalHeight = totalHeight + s.PaperRect.Height * scale + pageInterval;
                }
                contentRect.Y += (int)((this.Height - HScrollHeight - totalHeight) / 2);
            }

            //调整x位置
            contentRect.X = contentRect.X + pageInterval - offsetX;
            //if (!HScrollVisible)
            {
                float totalWidth = setting.PaperRect.Width * scale + pageInterval;
                contentRect.X += (int)((this.Width - VScrollWidth - totalWidth) / 2);
            }

            return(contentRect);

            #region 111
            //I3ReportData reportData = reportDatas.Datas[0];//取第1个报表的页面设置
            //I3PageSetting setting = reportData.PageSetting;
            //float singleHeight = setting.PaperHeightPX * Scale + pageInterval;
            //float singleWidth = setting.PaperWidthPX * Scale + pageInterval;
            //float offsetY = vScrollBar.Value;
            //float offsetX = hScrollBar.Value;

            //RectangleF contentRect = new RectangleF(setting.PaperContentRect.X * scale, setting.PaperContentRect.Y * scale, setting.PaperContentRect.Width * scale, setting.PaperContentRect.Height * scale);
            //contentRect.Y = contentRect.Y + pageInterval + area.Index * singleHeight - offsetY;
            //contentRect.X = contentRect.X + pageInterval - offsetX;
            //if (!VScrollVisible && !alignTop)
            //{
            //    float totalHeight = singleHeight * reportDatas.PrintAreas.Dic.Count + pageInterval;
            //    contentRect.Y += (int)((this.Height - HScrollHeight - totalHeight) / 2);
            //}
            //if (!HScrollVisible)
            //{
            //    float totalWidth = singleWidth + pageInterval;
            //    contentRect.X += (int)((this.Width - VScrollWidth - totalWidth) / 2);
            //}

            //return contentRect;
            #endregion
        }
예제 #24
0
        /// <summary>
        /// 计算输出区域   (以内容输出区域左上角为0,0开始计算、不考虑缩放、页眉页脚平移)
        /// 如果是合并单元格,包含整个合并区域
        /// 必须经过平移、缩放放才有意义
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="reportData"></param>
        /// <param name="cell"></param>
        private static RectangleF CalCellDrawRect_UnScale(I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, I3ReportCell mergedCell)
        {
            //X、Y先求原单元格的
            int          row     = mergedCell == null ? cell.Row : mergedCell.Row;
            int          col     = mergedCell == null ? cell.Col : mergedCell.Col;
            I3RowColType rowType = area.ReportData[row].Type;
            I3RowColType colType = area.ReportData.Cols[col].Type;

            //Width、Heigth求合并的
            I3MergeRange range = cell.GetRange_Mode2(area.ReportData);
            RectangleF   rect  = new RectangleF(0F, 0F, 0F, 0F);

            #region Y
            IList <int> rows = null;
            switch (rowType)
            {
            case I3RowColType.页眉:
                rows = area.HeaderRows.Keys;
                break;

            case I3RowColType.页脚:
                rows = area.FooterRows.Keys;
                break;

            default:
                rows = area.DataRows.Keys;
                break;
            }
            foreach (int i in rows)
            {
                if (i < row)
                {
                    rect.Y += area.ReportData[i].Height;
                }
            }
            #endregion

            #region Height
            for (int i = range.StartRow; i <= range.EndRow; i++)  //高度为合并区域的高度的和
            {
                rect.Height += area.ReportData[i].Height;
            }
            #endregion

            #region X
            IList <int> cols = null;
            switch (colType)
            {
            case I3RowColType.页眉:
                cols = area.HeaderCols.Keys;
                break;

            case I3RowColType.页脚:
                cols = area.FooterCols.Keys;
                break;

            default:
                cols = area.DataCols.Keys;
                break;
            }
            foreach (int i in cols)
            {
                if (i < col)
                {
                    rect.X += area.ReportData.Cols[i].Width;
                }
            }
            #endregion

            #region Width
            for (int i = range.StartCol; i <= range.EndCol; i++)
            {
                rect.Width += area.ReportData.Cols[i].Width;
            }
            #endregion

            #region 画合并单元格的部分时,左移、上移
            if (mergedCell != null)
            {
                for (int i = cell.Row; i < mergedCell.Row; i++)
                {
                    rect.Y -= area.ReportData[i].Height;
                }
                for (int i = cell.Col; i < mergedCell.Col; i++)
                {
                    rect.X -= area.ReportData.Cols[i].Width;
                }
            }
            #endregion

            return(rect);
        }
예제 #25
0
        private void exportAreaToSheet(I3PrintArea area, HSSFWorkbook workbook, ISheet sheet, ref int rowCount, Dictionary <string, HSSFCellStyle> styleDic, Dictionary <string, IFont> fontDic)
        {
            HSSFCellStyle emptyStyle = createEmptyStyle(workbook);

            //导出行、单元格
            foreach (int rowIndex in area.AllRows)
            {
                //设置行高
                rowCount++;
                IRow        row     = sheet.CreateRow(rowCount - 1);
                I3ReportRow rowData = area.ReportData.Rows[rowIndex];
                if (rowData.PageBreak)  //分页符
                {
                    sheet.SetRowBreak(rowCount - 1);
                }
                double dh = (double)rowData.Height * (double)15.305838;
                dh = dh * (double)1.1;
                int height = (int)Math.Ceiling(dh);
                row.Height = (short)height;

                //设置文本
                int colIndex = -1;
                foreach (I3ReportCell cellData in rowData.Cells)
                {
                    colIndex++;
                    ICell cell            = row.CreateCell(colIndex);
                    bool  hasReturnInText = false;
                    if (cellData.MergState != I3MergeState.Merged)
                    {
                        hasReturnInText = !string.IsNullOrEmpty(cellData.Text) && cellData.Text.IndexOf("{r}") >= 0;
                        if (cellData is I3ReportImageCell)
                        {
                            I3ReportImageCell imageCell = (I3ReportImageCell)cellData;
                            byte[]            bytes     = imageCell.ImageData;
                            if (bytes != null && bytes.Length > 0)
                            {
                                try
                                {
                                    int           pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
                                    HSSFPatriarch patriarch  = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
                                    // 插图片的位置  HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2) 后面再作解释
                                    int row1 = rowCount - 1;
                                    int row2 = rowCount - 1;
                                    int col1 = colIndex;
                                    int col2 = colIndex;
                                    if (cellData.MergState == I3MergeState.FirstCell)
                                    {
                                        I3MergeRange mr = area.ReportData.GetMergeRange(cellData.Row, cellData.Col);
                                        row2 = rowCount - 1 + mr.EndRow - mr.StartRow;
                                        col2 = mr.EndCol;
                                    }
                                    HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, col1, row1, col2, row2);
                                    //把图片插到相应的位置
                                    HSSFPicture pict = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIdx);
                                }
                                catch
                                {
                                }
                            }
                        }
                        else
                        {
                            string text = string.IsNullOrEmpty(cellData.Text) ? "" : cellData.Text.Replace("{r}", "\r\n");
                            //特殊符号....使用替换符如{1级钢筋}{WL}{屈特比}
                            cell.SetCellValue(text);
                        }
                    }

                    //设置样式
                    int  lastRowIndex = area.AllRows[area.AllRows.Length - 1];
                    bool isLastRow    = rowData.Row == lastRowIndex;
                    bool isLastCol    = cellData.Col == area.ReportData.Cols.Length - 1;
                    setCellStyle(workbook, sheet, cell, area, cellData, styleDic, fontDic, hasReturnInText, isLastRow, isLastCol, emptyStyle);

                    //设置合并
                    if (cellData.MergState == I3MergeState.FirstCell)
                    {
                        I3MergeRange     mr = area.ReportData.GetMergeRange(cellData.Row, cellData.Col);
                        CellRangeAddress ra = new CellRangeAddress(rowCount - 1, rowCount - 1 + mr.EndRow - mr.StartRow, mr.StartCol, mr.EndCol);
                        sheet.AddMergedRegion(ra);
                    }
                }
            }
        }
예제 #26
0
        public override RectangleF DrawContent(Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, System.Drawing.RectangleF rect, I3ReportCellStyle style, I3PrintArea area, bool draw)
        {
            I3ReportImageCell imageCell = cell as I3ReportImageCell;

            if (imageCell.ImageData == null)
            {
                return(RectangleF.Empty);
            }

            try
            {
                using (MemoryStream stream = new MemoryStream(imageCell.ImageData))
                {
                    using (Bitmap bitmap = new Bitmap(stream))
                    {
                        float width = imageCell.CalWidth > 0 ? imageCell.CalWidth : imageCell.Width;
                        width *= scale;
                        float heigth = imageCell.CalHeight > 0 ? imageCell.CalHeight : imageCell.Height;
                        heigth *= scale;

                        RectangleF destRect = new RectangleF((float)rect.X + (float)rect.Width / 2F - (float)width / 2F,
                                                             (float)rect.Y + (float)rect.Height / 2F - (float)heigth / 2F,
                                                             width,
                                                             heigth);

                        RectangleF srcRect = new RectangleF(0F, 0F, (float)bitmap.Width, (float)bitmap.Height);
                        if (draw && !destRect.IsEmpty)
                        {
                            g.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel);
                        }

                        return(destRect);
                    }
                }
            }
            catch
            {
                RectangleF destRect = new RectangleF((float)rect.X + (float)rect.Width / 2F - (float)100 / 2F,
                                                     (float)rect.Y + (float)rect.Height / 2F - (float)100 / 2F,
                                                     100,
                                                     100);
                return(destRect);
            }
        }
        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);
        }
예제 #28
0
        /// <summary>
        /// 将页面分为9个区间,根据行、列类型获取剪切区域
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="reportData"></param>
        /// <param name="fullRect"></param>
        /// <param name="dataRect"></param>
        /// <param name="areaRect"></param>
        /// <returns></returns>
        private static RectangleF CalCellClipRect_Large(I3PrintArea area, I3ReportCell cell, I3ReportDatas reportDatas, RectangleF fullRect, RectangleF dataRect, RectangleF areaRect)
        {
            float x1 = fullRect.X;
            float x2 = dataRect.X;
            float x3 = dataRect.X + dataRect.Width;
            float x4 = fullRect.X + fullRect.Width;
            float y1 = fullRect.Y;
            float y2 = dataRect.Y;
            float y3 = dataRect.Y + dataRect.Height;
            float y4 = fullRect.Y + fullRect.Height;

            RectangleF result;

            switch (area.ReportData[cell.Row].Type)
            {
            case I3RowColType.页眉:
                switch (area.ReportData.Cols[cell.Col].Type)
                {
                case I3RowColType.页眉:          //左上
                    return(new RectangleF(x1, y1, x2 - x1, y2 - y1));

                case I3RowColType.页脚:          //右上
                    return(new RectangleF(x3, y1, x4 - x3, y2 - y1));

                default:          //中上
                    result       = new RectangleF(x2, y1, x3 - x2, y2 - y1);
                    result.Width = Math.Min(result.Width, areaRect.Width);
                    return(result);
                }

            case I3RowColType.页脚:
                switch (area.ReportData.Cols[cell.Col].Type)
                {
                case I3RowColType.页眉:          //左下
                    return(new RectangleF(x1, y3, x2 - x1, y4 - y3));

                case I3RowColType.页脚:          //右下
                    return(new RectangleF(x3, y3, x4 - x3, y4 - y3));

                default:          //中下
                    result       = new RectangleF(x2, y3, x3 - x2, y4 - y3);
                    result.Width = Math.Min(result.Width, areaRect.Width);
                    return(result);
                }

            default:
                switch (area.ReportData.Cols[cell.Col].Type)
                {
                case I3RowColType.页眉:          //左中
                    result        = new RectangleF(x1, y2, x2 - x1, y3 - y2);
                    result.Height = Math.Min(result.Height, areaRect.Height);
                    return(result);

                case I3RowColType.页脚:          //右中
                    result        = new RectangleF(x3, y2, x4 - x3, y3 - y2);
                    result.Height = Math.Min(result.Height, areaRect.Height);
                    return(result);

                default:          //中中
                    RectangleF dataClipRect = dataRect;
                    dataClipRect.Intersect(areaRect);
                    return(dataClipRect);
                }
            }
        }
        /// <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();
            }
        }
예제 #30
0
        /// <summary>
        /// 获取默认打印区域信息(包含标题行、表头、表尾、页眉、页脚)
        /// </summary>
        /// <param name="area"></param>
        /// <param name="reportData"></param>
        private static I3PrintArea GetDefaultRowPrintArea(I3ReportData reportData)
        {
            I3PrintArea area = new I3PrintArea();

            #region 行
            for (int i = 0; i < reportData.RowCount; i++)
            {
                switch (reportData[i].Type)
                {
                case I3RowColType.页眉:
                    area.HeaderRows.Add(i, i);
                    break;

                case I3RowColType.页脚:
                    area.FooterRows.Add(i, i);
                    break;

                case I3RowColType.标题:
                case I3RowColType.表头:
                case I3RowColType.表尾:
                    area.DataRows.Add(i, i);
                    area.Height += reportData[i].Height;
                    break;

                default:
                    break;
                }
            }
            #endregion

            #region 列
            for (int i = 0; i < reportData.ColCount; i++)
            {
                switch (reportData.Cols[i].Type)
                {
                case I3RowColType.页眉:
                    area.HeaderCols.Add(i, i);
                    break;

                case I3RowColType.页脚:
                    area.FooterCols.Add(i, i);
                    break;

                case I3RowColType.标题:
                case I3RowColType.表头:
                case I3RowColType.表尾:
                    area.DataCols.Add(i, i);
                    area.Width += reportData.Cols[i].Width;
                    break;

                default:
                    break;
                }
            }
            #endregion

            #region 检查
            I3PageSetting setting = reportData.PageSetting;
            if (setting.RowsPagerStyle == PagerStyle.纸张尺寸分页)
            {
                if (area.Width > setting.PaperContentRect.Width)
                {
                    throw new Exception("标题列、表头列、表尾列宽度之和大于纸张可用区域,无法分页!");
                }
                if (area.Height > setting.PaperContentRect.Height)
                {
                    throw new Exception("标题行、表头行、表尾行高度之和大于纸张可用区域,无法分页!");
                }
            }
            #endregion

            return(area);
        }