/// <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); } }
/// <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); } }