Exemple #1
0
 public void DrawCellStruct(Point point, CellStruct cellStruct)
 {
     if (cellStruct != null && cellStruct != CellStruct.Empty)
     {
         // 画一个CELL,分为划线与写入文本内容
         DrawCellLine(point, cellStruct.DrawInfo);
         DrawCellContext(point, cellStruct.Context, cellStruct.DrawInfo);
     }
 }
Exemple #2
0
        private void CalcRect(int pageIndex, DataTable pagetable)
        {
            //依据rowHeight columnInfo 计算point size excelInfo等信息
            PageInfo info = pageList[pageIndex - 1];
            //info.PageRowHeight
            List <int> rowPointList = new List <int>();

            rowPointList.Add(0);
            for (int rowIndex = 0; rowIndex < info.PageRowHeight.Count; rowIndex++)
            {
                rowPointList.Add(info.PageRowHeight[rowIndex] + rowPointList[rowIndex]);
            }

            int[] colArray = null;
            if (info.ContainCols.Count != 0)
            {
                colArray = new int[info.ContainCols.Count];
                info.ContainCols.CopyTo(colArray);
            }
            else
            {
                colArray = new int[columnInfo.Count];
                columnInfo.Keys.CopyTo(colArray, 0);
            }
            List <int> colPointList = new List <int>();

            colPointList.Add(0);
            for (int colIndex = 0; colIndex < colArray.Length; colIndex++)
            {
                colPointList.Add(ColumnInfo[colArray[colIndex]].GetPagingWidth(info.HpageIndex)
                                 + colPointList[colIndex]);
            }

            CellStruct tempCell = null;

            for (int rowIndex = 0; rowIndex < pagetable.Rows.Count; rowIndex++)
            {
                for (int colIndex = 0; colIndex < pagetable.Columns.Count; colIndex++)
                {
                    tempCell = pagetable.Rows[rowIndex][colIndex] as CellStruct;
                    if (tempCell == null || tempCell == CellStruct.Empty)
                    {
                        continue;
                    }
                    tempCell.DrawInfo.Point = new Point(colPointList[colIndex], rowPointList[rowIndex]);
                    tempCell.SetExcelPoint(rowIndex, colIndex);

                    //如何:处理被分页拆分的合并行列问题
                    //横向分页折分
                    //纵向分页折分[可暂不处理]

                    tempCell.DrawInfo.Size = new Size(GetPageColWidth(info.HpageIndex, colIndex, tempCell.ExcelInfo.ColMerge, colArray),
                                                      GetPageRowHeight(rowIndex, tempCell.ExcelInfo.RowMerge, info.PageRowHeight));
                }
            }
        }
Exemple #3
0
        private void SynBandCellData(PageInfo info, DataRow row, DataRow newRow, List <int> column)
        {
            CellStruct cellStruct = null;
            CellStruct tempStruct = null;
            int        index      = 0;

            foreach (int columnName in column)
            {
                cellStruct = row[columnName.ToString()] as CellStruct;
                if (cellStruct is MacrsCellStruct)
                {
                    cellStruct = (cellStruct as MacrsCellStruct).ReplaceMacrs(info.PageMacrs);
                }
                if (!CellStruct.IsNullOrEmpty(cellStruct))
                {
                    if (cellStruct.ExcelInfo.ColMerge > column.Count - index)
                    {
                        cellStruct = cellStruct.Clone();
                        cellStruct.ExcelInfo.ColMerge = column.Count - index;
                    }
                }
                if (index == 0 && CellStruct.IsNullOrEmpty(cellStruct))
                {
                    //查询该CellStruct之前是否有列合并Cell
                    for (int i = columnName - 1; i > 0; i--)
                    {
                        tempStruct = row[i.ToString()] as CellStruct;
                        if (!CellStruct.IsNullOrEmpty(tempStruct))
                        {
                            if (tempStruct.ExcelInfo.ColMerge > columnName - i)
                            {
                                cellStruct = tempStruct.Clone();
                                cellStruct.ExcelInfo.ColMerge -= columnName - i;
                                if (cellStruct.ExcelInfo.ColMerge > column.Count)
                                {
                                    cellStruct.ExcelInfo.ColMerge = column.Count;
                                }
                            }
                            break;
                        }
                    }
                }



                if (cellStruct is FunCellStruct)
                {
                    string funResult = info.FunResults[cellStruct.Context];
                    cellStruct         = cellStruct.Clone();
                    cellStruct.Context = funResult;
                }
                newRow[columnName.ToString()] = cellStruct;
                index++;
            }
        }
        private void fpSpread1_Change(object sender, FarPoint.Win.Spread.ChangeEventArgs e)
        {
            CellStruct cellStruct = dt.Rows[e.Row][e.Column] as CellStruct;

            if (!CellStruct.IsNullOrEmpty(cellStruct))
            {
                cellStruct.Context       = sheet.Cells[e.Row, e.Column].Text;
                dt.Rows[e.Row][e.Column] = cellStruct;
                tool_Save.Enabled        = true;
            }
        }
 private void fpSpread1_CellDoubleClick(object sender, CellClickEventArgs e)
 {
     Com.Bing.Forms.InputDialog dlg = new Com.Bing.Forms.InputDialog("编辑文本", fpSpread1.ActiveSheet.ActiveCell.Text, true, true);
     if (dlg.ShowDialog() == DialogResult.OK)
     {
         sheet.ActiveCell.Text = dlg.TextResult;
         CellStruct cellStruct = dt.Rows[e.Row][e.Column] as CellStruct;
         if (!CellStruct.IsNullOrEmpty(cellStruct))
         {
             cellStruct.Context = dlg.TextResult;
         }
         tool_Save.Enabled = true;
     }
 }
Exemple #6
0
        private void SynCellRowMergeDownCell(int rowIndex, int endIndex, DataRow dataRow, DataRow newRow, List <int> list)
        {
            CellStruct cellStruct = null;

            foreach (int columnName in list)
            {
                cellStruct = dataRow[columnName.ToString()] as CellStruct;
                if (cellStruct.ExcelInfo.RowMerge > endIndex - rowIndex)
                {
                    cellStruct = cellStruct.Clone();
                    cellStruct.ExcelInfo.RowMerge = endIndex - rowIndex;
                }
                newRow[columnName.ToString()] = cellStruct;
            }
        }
        //取消合并单元格
        private void tool_CancelMerge_Click(object sender, EventArgs e)
        {
            CellRange range = sheet.GetSelection(0);

            if (range != null)
            {
                CellStruct orginalCellStrct = dt.Rows[range.Row][range.Column] as CellStruct;
                int        x = orginalCellStrct.DrawInfo.Point.X;
                int        y = orginalCellStrct.DrawInfo.Point.Y;
                for (int i = range.Row; i < range.Row + range.RowCount; i++)
                {
                    int height = Convert.ToInt32(sheet.Rows[i].Height);
                    for (int j = range.Column; j < range.Column + range.ColumnCount; j++)
                    {
                        sheet.RemoveSpanCell(i, j);
                        //CellStruct cellStruct = dt.Rows[i][j] as CellStruct;
                        CellStruct cellStruct = new CellStruct("", null, null);
                        cellStruct.Context = sheet.Cells[i, j].Text;
                        DrawInfo drawInfo = new DrawInfo();

                        if (sheet.Cells[i, j].Border != null)
                        {
                            drawInfo.BoundaryLine.UpperBoundaryLine  = sheet.Cells[i, j].Border.Inset.Top == 1;
                            drawInfo.BoundaryLine.LowerBoundaryLine  = sheet.Cells[i, j].Border.Inset.Bottom == 1;
                            drawInfo.BoundaryLine.LeftBoundaryLine   = sheet.Cells[i, j].Border.Inset.Left == 1;
                            drawInfo.BoundaryLine.RightBooundaryLine = sheet.Cells[i, j].Border.Inset.Right == 1;
                        }

                        int width = Convert.ToInt32(sheet.Columns[j].Width);
                        drawInfo.Size  = new Size(width, height);
                        drawInfo.Point = new Point(x, y);
                        x += width;

                        drawInfo.Format.LineAlignment = DesignHelper.ConvertHAlignmentToStringAlignment(sheet.Cells[i, j].HorizontalAlignment);
                        drawInfo.Format.Alignment     = DesignHelper.ConvertVAlignmentToStringAlignment(sheet.Cells[i, j].VerticalAlignment);

                        drawInfo.Font = sheet.Cells[i, j].Font;

                        cellStruct.DrawInfo = drawInfo;

                        cellStruct.ExcelInfo = new ExcelInfo(1, 1);

                        dt.Rows[i][j] = cellStruct;
                    }
                    y += height;
                }
            }
        }
        private void InitSheetView()
        {
            try
            {
                sheet.ColumnCount = pageInfo.ContainCols.Count;
                sheet.RowCount    = dt.Rows.Count;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        CellStruct cellStruct = dt.Rows[i][j] as CellStruct;
                        if (!CellStruct.IsNullOrEmpty(cellStruct))
                        {
                            //文本内容
                            sheet.Cells[i, j].Text = cellStruct.Context;
                            //字体信息
                            sheet.Cells[i, j].Font = cellStruct.DrawInfo.Font;
                            //边框信息
                            FarPoint.Win.IBorder border = new FarPoint.Win.LineBorder(Color.Black, 1,
                                                                                      cellStruct.DrawInfo.BoundaryLine.LeftBoundaryLine,
                                                                                      cellStruct.DrawInfo.BoundaryLine.UpperBoundaryLine,
                                                                                      cellStruct.DrawInfo.BoundaryLine.RightBooundaryLine,
                                                                                      cellStruct.DrawInfo.BoundaryLine.LowerBoundaryLine);

                            sheet.Cells[i, j].Border = border;
                            //合并信息
                            sheet.Cells[i, j].RowSpan    = cellStruct.ExcelInfo.RowMerge;
                            sheet.Cells[i, j].ColumnSpan = cellStruct.ExcelInfo.ColMerge;

                            //对齐方式
                            sheet.Cells[i, j].HorizontalAlignment = DesignHelper.ConvertStringAlignmentToHAlignment(cellStruct.DrawInfo.Format.LineAlignment);
                            sheet.Cells[i, j].VerticalAlignment   = DesignHelper.ConvertStringAlignmentToVAlignment(cellStruct.DrawInfo.Format.Alignment);
                        }
                    }
                    sheet.Rows[i].Height = pageInfo.PageRowHeight[i];
                }
                for (int i = 0; i < pageInfo.ColumnInfo.Length; i++)
                {
                    sheet.Columns[i].Width = pageInfo.ColumnInfo[i].Width;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public CellStruct ReplaceMacrs(Dictionary <string, string> list)
        {
            string          replaceContext = this.Context;
            MatchCollection matches        = Regex.Matches(Context, @"\[\w+\]");

            foreach (System.Text.RegularExpressions.Match m in matches)
            {
                string key = Regex.Match(m.Value, @"(?<=\[)\w+(?=\])").Value;
                string val = "";
                list.TryGetValue(key, out val);
                replaceContext = replaceContext.Replace(m.Value, val);
            }

            CellStruct newCellStruct = this.Clone();

            newCellStruct.Context = replaceContext;
            return(newCellStruct);
        }
Exemple #10
0
        public static List <CellStruct> GetListCellStruct(Cell cell, DataTable dt)
        {
            List <CellStruct> list = new List <CellStruct>();

            if (cell != null)
            {
                for (int i = cell.Row.Index; i <= cell.Row.Index2; i++)
                {
                    for (int j = cell.Column.Index; j <= cell.Column.Index2; j++)
                    {
                        CellStruct cellStruct = dt.Rows[i][j] as CellStruct;
                        if (!CellStruct.IsNullOrEmpty(cellStruct))
                        {
                            list.Add(cellStruct);
                        }
                    }
                }
            }
            return(list);
        }
Exemple #11
0
        private void SynTextCellData(PageInfo info, DataRow row, DataRow newRow, List <int> column)
        {
            CellStruct cellStruct = null;
            int        index      = 0;

            foreach (int columnName in column)
            {
                cellStruct = row[columnName.ToString()] as CellStruct;

                if (!CellStruct.IsNullOrEmpty(cellStruct) && cellStruct.ExcelInfo.ColMerge > column.Count - index)
                {
                    cellStruct = cellStruct.Clone();
                    cellStruct.ExcelInfo.ColMerge = column.Count - index;
                }
                if (cellStruct is MacrsCellStruct)
                {
                    cellStruct = (cellStruct as MacrsCellStruct).ReplaceMacrs(info.PageMacrs);
                }
                newRow[columnName.ToString()] = cellStruct;
                index++;
            }
        }
Exemple #12
0
 public void DrawCellStruct(CellStruct cellStruct)
 {
     DrawCellStruct(Point.Empty, cellStruct);
 }
 public static bool IsNullOrEmpty(CellStruct tempCell)
 {
     return(tempCell == null || tempCell == Empty);
 }
        public void Analyse()
        {
            //出求最大行能占的最大高度 以及行Index
            int maxHeight   = 0;
            int maxRowIndex = -1;
            int totalHeightExMaxHeightRow = 0;

            for (int index = 0; index < drawStruct.ExBodyHeight.Count; index++)
            {
                if (drawStruct.ExBodyHeight[index] > maxHeight)
                {
                    maxHeight   = drawStruct.ExBodyHeight[index];
                    maxRowIndex = index;
                }
                totalHeightExMaxHeightRow += drawStruct.ExBodyHeight[index];
            }
            totalHeightExMaxHeightRow -= maxHeight;
            int maxRowEnableHeight = report.AreaHeight - totalHeightExMaxHeightRow;

            drawStruct.ExBodyHeight.ChangeHeight(maxRowIndex, maxRowEnableHeight);

            //求最大行高的宏变量 、 具体值 以及最大列宽 , 最大行高必须要宏变量扩展,否则不处理。
            MacrsCellStruct cellStruct = drawStruct.GetExFunCellStruct(maxRowIndex);

            if (CellStruct.IsNullOrEmpty(cellStruct))
            {
                throw new BigTextAnalyseException("大文本字段分隔失败,请手动处理!");
            }
            //最大可能行高需要加上Cell向下合并的行数
            for (int index = maxRowIndex + 1; index < cellStruct.ExcelInfo.RowMerge + maxRowIndex; index++)
            {
                maxRowEnableHeight += drawStruct.ExBodyHeight[index];
            }

            int colWidth      = 0;
            int mergeColIndex = 0;

            //计算可行列宽
            foreach (int columnName in drawStruct.ColumnInfo.Keys)
            {
                if (columnName > cellStruct.ExcelInfo.ExcelPoint.Y)
                {
                    mergeColIndex++;
                    colWidth += drawStruct.ColumnInfo[columnName].Width;
                }
                if (mergeColIndex == cellStruct.ExcelInfo.ColMerge)
                {
                    break;
                }
            }

            string macrsKey = System.Text.RegularExpressions.Regex.Match(cellStruct.Context, @"(?<=\[).*(?=\])").Value;
            string macrsVal = report.Data.MacorsVerbCollection[macrsKey, 1];

            Text macrsText = null;

            foreach (Text text in report.Texts)
            {
                if (text.MContext == cellStruct.Context)
                {
                    macrsText = text;
                    break;
                }
            }

            List <string> spliteContents = GetPartition(macrsVal, macrsText.Attribute.Font, colWidth, maxRowEnableHeight);

            PageInfo pageInfo = null;

            foreach (string marcsSplitVal in spliteContents)
            {
                pageInfo = new PageInfo();
                pageInfo.StartRowIndex = 0;
                pageInfo.EndRowIndex   = drawStruct.ExBodyHeight.Count;
                drawStruct.ExBodyHeight.Init(pageInfo.PageRowHeight);
                drawStruct.PageList.Add(pageInfo);
                drawStruct.VerifyPageColumn(pageInfo);
                //pageInfo.PageMacrs =
                Dictionary <string, string> tempMacrs = report.Data.MacorsVerbCollection.GetPageMacrs(1);
                foreach (KeyValuePair <string, string> entry in tempMacrs)
                {
                    pageInfo.PageMacrs[entry.Key] = entry.Value;
                }
                pageInfo.PageMacrs[macrsKey] = marcsSplitVal;
            }
        }
Exemple #15
0
 internal void AddBody(CellStruct cellStruct, int rowIndex, int columnIndex, int rowHeight)
 {
     bodyData.Rows[rowIndex][columnIndex] = cellStruct;
     bodyRowHeight[rowIndex] = rowHeight;
 }
Exemple #16
0
        private void GetPageBodyData(int page, DataTable pageData, PageInfo pageInfo)
        {
            DataRow newRow = null;

            for (int rowIndex = pageInfo.StartRowIndex; rowIndex < pageInfo.EndRowIndex; rowIndex++)
            {
                newRow = pageData.NewRow();
                pageData.Rows.Add(newRow);
                if (rowIndex != 0 && rowIndex == pageInfo.StartRowIndex && pageList[page - 2].EndRowIndex == pageInfo.StartRowIndex)
                {
                    SynCellRowMergeUpCell(rowIndex, pageInfo.EndRowIndex, bodyData.Rows[rowIndex], newRow, pageInfo.ContainCols);
                }
                else
                {
                    bool hasExceedRowMarge = false;
                    foreach (int columnName in pageInfo.ContainCols)
                    {
                        CellStruct cellStruct = bodyData.Rows[rowIndex][columnName.ToString()] as CellStruct;
                        if (cellStruct.ExcelInfo.RowMerge > pageInfo.EndRowIndex - rowIndex)
                        {
                            hasExceedRowMarge = true;
                            break;
                        }
                    }
                    if (hasExceedRowMarge)
                    {
                        //包含向下合并的行
                        SynCellRowMergeDownCell(rowIndex, pageInfo.EndRowIndex,
                                                bodyData.Rows[rowIndex], newRow, pageInfo.ContainCols);
                    }
                    else
                    {
                        SynCellData(bodyData.Rows[rowIndex], newRow, pageInfo.ContainCols);
                    }
                }
            }
            //空白行添加
            InsertEmptyRow(pageData, pageInfo);

            //表体最后一行Cell(必需)需要有下边框线
            int rowCount = pageData.Rows.Count - 1;

            if (rowCount < 0)
            {
                return;
            }
            foreach (DataColumn column in pageData.Columns)
            {
                CellStruct cellStruct = pageData.Rows[rowCount][column] as CellStruct;
                if (!CellStruct.IsNullOrEmpty(cellStruct))
                {
                    //有左右边框的才加入下边线
                    //if (cellStruct.DrawInfo.BoundaryLine.LeftBoundaryLine && cellStruct.DrawInfo.BoundaryLine.RightBooundaryLine)
                    //有左边框的才加入下边线
                    if (cellStruct.DrawInfo.BoundaryLine.LeftBoundaryLine)
                    {
                        cellStruct.DrawInfo.BoundaryLine.LowerBoundaryLine = true;
                    }
                }
            }
        }
Exemple #17
0
        public void Send(StringBuilder vbaContext, bool b)
        {
            if (!WholeData.Invalid)
            {
                return;
            }
            //vba整体设置字串
            vbaContext.AppendLine(WholeData.WholeInfo.ToString());

            SetColumnWidth.EchoRatio = WholeData.ExcelSizeF.Width;
            //vba整体的列设置
            int columnIndex = 1;

            foreach (int key in WholeData.ColumnInfo.Keys)
            {
                SetColumnWidth excelColumnWidth = new SetColumnWidth();
                excelColumnWidth.ColumnIndex = columnIndex;
                excelColumnWidth.ColumnWidth = WholeData.ColumnInfo[key].Width;
                vbaContext.AppendLine(excelColumnWidth.ToString());
                columnIndex++;
            }
            SetRowHeight.EchoRatio = WholeData.ExcelSizeF.Height;
            int rowCount = 1;



            foreach (PageInfo info in WholeData.PageList)
            {
                foreach (int height in info.PageRowHeight)
                {
                    SetRowHeight excelRowHeight = new SetRowHeight();
                    excelRowHeight.RowIndex  = rowCount;
                    excelRowHeight.RowHeight = height;
                    vbaContext.AppendLine(excelRowHeight.ToString());
                    rowCount++;
                }
            }

            Point      location   = Point.Empty;
            CellStruct cellStruct = null;

            //整张页发送
            for (int pageIndex = 1; pageIndex <= WholeData.PageCount; pageIndex++)
            {
                //List<int> list = WholeData.ExBodyHeight;

                DataTable pageTable = WholeData.GetPageData(pageIndex);
                for (int rowIndex = 0; rowIndex < pageTable.Rows.Count; rowIndex++)
                {
                    columnIndex = 0;
                    foreach (DataColumn column in pageTable.Columns)
                    {
                        cellStruct = pageTable.Rows[rowIndex][column] as CellStruct;
                        if (!CellStruct.IsNullOrEmpty(cellStruct))
                        {
                            vbaContext.AppendLine((cellStruct).ToExcelString(
                                                      location));
                        }
                        columnIndex++;
                    }
                }
                if (WholeData.PageList[pageIndex - 1].IsCrosswisePage && InHorizontalPage(pageIndex, WholeData.PageList))
                {
                    location.Offset(0, pageTable.Columns.Count);
                }
                else
                {
                    location.Y = 0;
                    location.Offset(pageTable.Rows.Count, 0);
                }
                SetPaginationFlag paginationFlag = new SetPaginationFlag();
                paginationFlag.Range = string.Format("1,1,{0},{1}", location.Y, location.X);
                vbaContext.AppendLine(paginationFlag.ToString());
            }
        }
Exemple #18
0
 internal void AddExBody(CellStruct cellStruct, int rowIndex, int columnIndex, Dictionary <int, int> rowHeightDict)
 {
     exBodyData.Rows[rowIndex][columnIndex] = cellStruct;
     exBodyHeigth.ChangeHeight(rowIndex, rowHeightDict);
 }