/// <summary> /// 清除表格 /// </summary> void ClearTable() { Worksheet sheet = _excel.ActiveSheet; if (sheet == null) { return; } List <string> recText = new List <string>(); List <object> recInst = new List <object>(); int idx = 0; RptTextInst inst; Dt.Cells.Data.Cell cell = null; _selectedTable = null; using (_excel.Defer()) { _excel.DecorationRange = null; foreach (SheetTable tbl in sheet.GetTables()) { CellRange range = tbl.Range; int maxRow = range.Row + range.RowCount; int maxCol = range.Column + range.ColumnCount; for (int i = range.Row; i < maxRow; i++) { for (int j = range.Column; j < maxCol; j++) { cell = sheet[i, j]; recText.Add((cell.Text.StartsWith("Column") && cell.Tag == null) ? null : cell.Text); recInst.Add(cell.Tag); } } sheet.RemoveTable(tbl); idx = 0; for (int i = range.Row; i < maxRow; i++) { for (int j = range.Column; j < maxCol; j++) { sheet[i, j].Text = recText[idx]; sheet[i, j].Tag = recInst[idx]; inst = sheet[i, j].Tag as RptTextInst; if (inst == null) { sheet[i, j].StyleName = ""; } else { Kit.RunSync(() => { (inst.Item as RptText).ApplyStyle(sheet[i, j]); }); } idx++; } } recText.Clear(); recInst.Clear(); } } }
/// <summary> /// 加载RptText,一般用于加载报表顶级的RptText /// </summary> /// <param name="p_txt"></param> void LoadText(RptText p_txt) { Dt.Cells.Data.Cell cell = _owner.Excel.Sheets[(int)p_txt.Part.PartType].Cells[p_txt.Row, p_txt.Col]; cell.RowSpan = p_txt.RowSpan; cell.ColumnSpan = p_txt.ColSpan; cell.Value = p_txt.Data.Str("val"); p_txt.ApplyStyle(cell); }
/// <summary> /// 加载图表 /// </summary> /// <param name="p_chart"></param> void LoadChart(RptChart p_chart) { Dt.Cells.Data.Cell chartCell = _owner.Excel.Sheets[0].Cells[p_chart.Row, p_chart.Col]; chartCell.RowSpan = p_chart.RowSpan; chartCell.ColumnSpan = p_chart.ColSpan; chartCell.Background = new SolidColorBrush(Color.FromArgb(0XCC, 0XFF, 0XFD, 0XC5)); chartCell.VerticalAlignment = CellVerticalAlignment.Center; chartCell.HorizontalAlignment = CellHorizontalAlignment.Center; chartCell.FontFamily = Res.IconFont; chartCell.FontSize = 40; chartCell.Text = "\uE08D"; }
void SetBorder(Cell cell, BorderLine border) { if (border == null) { cell.BorderLeft = cell.BorderTop = cell.BorderRight = cell.BorderBottom = null; } else { cell.BorderLeft = border.Clone() as BorderLine; cell.BorderTop = border.Clone() as BorderLine; cell.BorderRight = border.Clone() as BorderLine; cell.BorderBottom = border.Clone() as BorderLine; } }
void OnInsertText(object sender, Mi e) { Worksheet sheet = _owner.Excel.ActiveSheet; CellRange range = sheet.Selections[0]; Dt.Cells.Data.Cell cell = sheet[range.Row, range.Column]; //合并单元格 if (range.RowCount > 1 || range.ColumnCount > 1) { cell.RowSpan = range.RowCount; cell.ColumnSpan = range.ColumnCount; } _owner.Info.ExecuteCmd(RptCmds.InsertText, new InsertCmdArgs(new RptText(_owner.GetContainer()), range)); }
/// <summary> /// 加载table的行单元格,不进行样式清除工作 /// </summary> /// <param name="p_tblRow"></param> /// <param name="p_rowIdx"></param> /// <param name="p_colIdx"></param> void LoadTblRow(RptTblPartRow p_tblRow, int p_rowIdx, int p_colIdx) { int colIdx = p_colIdx; Worksheet ws = _owner.Excel.Sheets[0]; for (int i = 0; i < p_tblRow.Cells.Count; i++) { RptText txt = p_tblRow.Cells[i]; txt.Row = p_rowIdx; txt.Col = colIdx++; Dt.Cells.Data.Cell cell = ws[txt.Row, txt.Col]; cell.Value = txt.Data.Str("val"); txt.ApplyStyle(cell); } }