private void SynCellRowMergeUpCell(int rowIndex, int endIndex, DataRow dataRow, DataRow newRow, List <int> list) { CellStruct cellStruct = null; foreach (int colName in list) { cellStruct = dataRow[colName.ToString()] as CellStruct; if (CellStruct.IsNullOrEmpty(cellStruct)) { CellStruct tempCell = null; //向上找 for (int i = rowIndex - 1; i >= 0; i--) { tempCell = bodyData.Rows[i][colName.ToString()] as CellStruct; if (!CellStruct.IsNullOrEmpty(tempCell)) { if (tempCell.ExcelInfo.RowMerge > rowIndex - i) { int tempMerge = tempCell.ExcelInfo.RowMerge - (rowIndex - i); if (tempMerge > endIndex - rowIndex) { tempMerge = endIndex - rowIndex; } cellStruct = tempCell.Clone(); cellStruct.ExcelInfo.RowMerge = tempMerge; break; } } } } newRow[colName.ToString()] = cellStruct; } }
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; } }
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 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); }
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++; } }
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()); } }
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; } }
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; } } } }