private void toolStripButton15_Click(object sender, EventArgs e) { using (FarPoint.Win.Spread.Design.BorderEditor borderedit = new FarPoint.Win.Spread.Design.BorderEditor(fpSpread1)) { borderedit.Shown += new EventHandler(borderedit_Shown); DesignHelper.LocalizationCHS(borderedit); if (sheet.SelectionCount == 0) { borderedit.StartColumn = sheet.ActiveColumnIndex; borderedit.ColumnCount = 1; borderedit.StartRow = sheet.ActiveRowIndex; borderedit.RowCount = 1; } else { CellRange range = sheet.GetSelection(0); //选中区域 if (range != null) { borderedit.StartColumn = range.Column; borderedit.ColumnCount = range.ColumnCount; borderedit.StartRow = range.Row; borderedit.RowCount = range.RowCount; } } borderedit.ShowDialog(); } btn_save.Enabled = true; }
private void tool_borderSet_Click(object sender, EventArgs e) { using (FarPoint.Win.Spread.Design.BorderEditor borderedit = new FarPoint.Win.Spread.Design.BorderEditor(fpSpread1)) { borderedit.Shown += new EventHandler(borderedit_Shown); DesignHelper.LocalizationCHS(borderedit); if (borderedit.ShowDialog() == DialogResult.OK) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { List <CellStruct> list = DesignHelper.GetListCellStruct(cell, dt); foreach (CellStruct cellStruct in list) { if (cell.Border == null) { cellStruct.DrawInfo.BoundaryLine.SetNoBoundary(); } else { cellStruct.DrawInfo.BoundaryLine.UpperBoundaryLine = cell.Border.Inset.Top == 1; cellStruct.DrawInfo.BoundaryLine.LowerBoundaryLine = cell.Border.Inset.Bottom == 1; cellStruct.DrawInfo.BoundaryLine.LeftBoundaryLine = cell.Border.Inset.Left == 1; cellStruct.DrawInfo.BoundaryLine.RightBooundaryLine = cell.Border.Inset.Right == 1; } } } } } }
private void InitContent(Text text, int index) { try { FarPoint.Win.IBorder border = new FarPoint.Win.LineBorder(Color.Black, 1, text.Attribute.BoundaryLine.LeftBoundaryLine, text.Attribute.BoundaryLine.UpperBoundaryLine, text.Attribute.BoundaryLine.RightBooundaryLine, text.Attribute.BoundaryLine.LowerBoundaryLine); int X = text.OriginalLocation.Y1 - 1 + index; int Y = text.OriginalLocation.X1 - 1; SizeF sizef = report.GraphicsBuffer.MeasureString(text.CellText, text.Attribute.Font); if (sizef.Height > sheet.Rows[X].Height && text.RowSpan == 1) { sheet.Rows[X].Height = sizef.Height; } sheet.Cells[X, Y].Text = text.CellText; sheet.AddSpanCell(X, Y, text.RowSpan, text.ColumnSpan); sheet.Cells[X, Y].Font = text.Attribute.Font; sheet.Cells[X, Y].Border = border; sheet.Cells[X, Y].HorizontalAlignment = DesignHelper.ConvertStringAlignmentToHAlignment(text.Attribute.Valign.LineAlignment); sheet.Cells[X, Y].VerticalAlignment = DesignHelper.ConvertStringAlignmentToVAlignment(text.Attribute.Valign.Alignment); sheet.Cells[X, Y].Tag = text.Attribute.Diagonal; } catch { throw new CellLocationInvalidExcption(text.ToString()); } }
private void 右对齐ToolStripMenuItem_Click(object sender, EventArgs e) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { cell.HorizontalAlignment = CellHorizontalAlignment.Right; btn_save.Enabled = true; } }
private void 对齐ToolStripMenuItem_Click(object sender, EventArgs e) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { cell.VerticalAlignment = CellVerticalAlignment.Bottom; btn_save.Enabled = true; } }
private void 对齐ToolStripMenuItem_Click(object sender, EventArgs e) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { List <CellStruct> list = DesignHelper.GetListCellStruct(cell, dt); cell.VerticalAlignment = CellVerticalAlignment.Bottom; foreach (CellStruct cellStruct in list) { cellStruct.DrawInfo.Format.Alignment = DesignHelper.ConvertVAlignmentToStringAlignment(CellVerticalAlignment.Bottom); } tool_Save.Enabled = true; } }
private void 右对齐ToolStripMenuItem_Click(object sender, EventArgs e) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { List <CellStruct> list = DesignHelper.GetListCellStruct(cell, dt); cell.HorizontalAlignment = CellHorizontalAlignment.Right; foreach (CellStruct cellStruct in list) { cellStruct.DrawInfo.Format.LineAlignment = DesignHelper.ConvertHAlignmentToStringAlignment(CellHorizontalAlignment.Right); } tool_Save.Enabled = true; } }
//字体设置 private void FontSet(object sender, EventArgs e) { using (FontDialog f = new FontDialog()) { if (f.ShowDialog() == DialogResult.OK) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { cell.Font = f.Font; btn_save.Enabled = true; } } } }
//取消合并单元格 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 tool_cancelBorder_Click(object sender, EventArgs e) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { FarPoint.Win.BevelBorder border = new FarPoint.Win.BevelBorder(FarPoint.Win.BevelBorderType.Raised, Color.Black, Color.Black, 1, false, false, false, false); cell.Border = border; List <CellStruct> list = DesignHelper.GetListCellStruct(cell, dt); foreach (CellStruct cellStruct in list) { cellStruct.DrawInfo.BoundaryLine.SetNoBoundary(); } 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; } }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Delete) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { cell.Text = ""; List <CellStruct> list = DesignHelper.GetListCellStruct(cell, dt); foreach (CellStruct cellStruct in list) { cellStruct.Context = ""; } tool_Save.Enabled = true; } } return(base.ProcessCmdKey(ref msg, keyData)); }
private void tool_FontSet_Click(object sender, EventArgs e) { using (FontDialog f = new FontDialog()) { if (f.ShowDialog() == DialogResult.OK) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { List <CellStruct> list = DesignHelper.GetListCellStruct(cell, dt); foreach (CellStruct cellStruct in list) { cellStruct.DrawInfo.Font = f.Font; } cell.Font = f.Font; tool_Save.Enabled = true; } } } }
private void toolStripButton17_Click(object sender, EventArgs e) { Cell cell = DesignHelper.GetSelectedCell(sheet); if (cell != null) { if (cell.Font == null) { cell.Font = new Font("宋体", 9); } if (cell.Font.Underline) { cell.Font = new Font(cell.Font.FontFamily, cell.Font.Size, cell.Font.Style ^ FontStyle.Underline); } else { cell.Font = new Font(cell.Font.FontFamily, cell.Font.Size, cell.Font.Style | FontStyle.Underline); } btn_save.Enabled = true; } }
//插入列 private void InsertCol(object sender, EventArgs e) { using (ColumnNameInputDlg dlg = new ColumnNameInputDlg("", "", report.OriginalData.Columns)) { if (dlg.ShowDialog() == DialogResult.OK) { if (DesignHelper.ContainColumnName(report, dlg.IColumnText, "")) { Function.Alert("已经存在当前内部名称,插入列失败", "提示"); return; } ReportColumn newColumn = new ReportColumn(dlg.IColumnText); newColumn.Attibutes.NameZh_cn = dlg.EColumnText; int columnIndex = sheet.ActiveColumnIndex; sheet.Columns.Add(columnIndex, 1); sheet.ColumnHeader.Cells[0, columnIndex].Text = newColumn.Attibutes.NameZh_cn; sheet.ColumnHeader.Cells[1, columnIndex].Text = newColumn.ColumnName; newColumn.ColumnWidth = Convert.ToInt32(sheet.Columns[columnIndex].Width); report.Columns.Insert(columnIndex, newColumn); btn_save.Enabled = true; } } }
private void SetColName(object sender, EventArgs e) { int columnIndex = sheet.ActiveColumnIndex; using (ColumnNameInputDlg dlg = new ColumnNameInputDlg(sheet.ColumnHeader.Cells[0, columnIndex].Text, sheet.ColumnHeader.Cells[1, columnIndex].Text, report.OriginalData.Columns)) { if (dlg.ShowDialog() == DialogResult.OK) { if (DesignHelper.ContainColumnName(report, dlg.IColumnText, sheet.ColumnHeader.Cells[1, columnIndex].Text)) { Function.Alert("列中已经存在了当前内部名称,修改失败", "提示"); return; } sheet.ColumnHeader.Cells[0, columnIndex].Text = dlg.EColumnText; sheet.ColumnHeader.Cells[1, columnIndex].Text = dlg.IColumnText; report.Columns.SetColumnName(report.Columns[columnIndex], dlg.IColumnText); //report.Columns[columnIndex].ColumnName = report.Columns[columnIndex].Attibutes.NameZh_cn = dlg.EColumnText; sheet.Columns[columnIndex].Tag = dlg.IColumnText; btn_save.Enabled = true; } } }
private void Save() { List <ReportColumn> listReportColumn = new List <ReportColumn>(); foreach (Column col in sheet.Columns) { if (col.Label.ToLower() == "rowgroup") { continue; } ReportColumn reportColumn = report.Columns[col.Label]; listReportColumn.Add(reportColumn); } report.Columns.Clear(); foreach (ReportColumn reportColumn in listReportColumn) { report.Columns.Add(reportColumn); } report.Texts.Clear(); report.Bands.ClearEchoDic(); int index = 0; int bandIndex = 0; int count = 0; for (int i = 0; i < sheet.RowCount; i++) { if (sheet.Rows[i].Tag != null) { count = 0; switch (sheet.Rows[i].Tag.ToString()) { case "标题": bandIndex = 1; index = startHeadIndex; break; case "表头": bandIndex = 2; index = startTitileIndex; break; case "表体": bandIndex = 3; index = startBodyIndex; break; case "页汇": bandIndex = 4; index = startPageIndex; break; case "表脚": bandIndex = 5; index = startFootIndex; break; } //初始化 report.Bands.SetBindRowNum(bandIndex, 0); continue; } count++; if (sheet.Cells[i, sheet.ColumnCount - 1].Text != "True") { report.Bands.SetBindRowEcho(bandIndex, i - index + 1, false); } report.Bands.SetBindRowNum(bandIndex, count); for (int j = 0; j < sheet.ColumnCount; j++) { if (sheet.Cells[i, j].CellType is FarPoint.Win.Spread.CellType.CheckBoxCellType) { continue; } DataRow[] rows = dtSpan.Select(string.Format("{0} >= minY and {0} <= maxY and {1} >= minX and {1} <= maxX", i, j)); if (rows.Length == 0) { //不在合并单元格中 Text text = new Text(); text.BandIndex = bandIndex; text.Context = sheet.Cells[i, j].Text; text.Location.X1 = j + 1; text.Location.Y1 = i + 1 - index; text.Location.X2 = j + sheet.Cells[i, j].ColumnSpan; text.Location.Y2 = i + sheet.Cells[i, j].RowSpan - index; SpecialLine line = specialLineInfo.GetSpecialLine(sheet.Cells[i, j]); if (line != null) { text.Attribute.Diagonal = line.LineType; } DesignHelper.SetTextPropertys(sheet.Cells[i, j], text); report.Texts.Add(text); DataRow row = dtSpan.NewRow(); row["minX"] = j; row["minY"] = i; row["maxX"] = j + sheet.Cells[i, j].ColumnSpan - 1; row["maxY"] = i + sheet.Cells[i, j].RowSpan - 1; dtSpan.Rows.Add(row); } } } report.WriteRpt(); dtSpan.Clear(); btn_save.Enabled = false; }