/// <summary> /// 添加表格行时候,给每列添加相关的单元格 /// </summary> /// <param name="row">新增的表格行对象</param> private void DoBusinessAboutAddRow(Row row) { Cell cellItem; foreach (Column colItem in this.tbTempObject.MyDocument.ColumnCollection.Values) { cellItem = new Cell(); cellItem.RowID = row.RowID; cellItem.ColumnID = colItem.ColumnID; row.Add(cellItem); } }
/// <summary> /// 添加表格行时候,给每列添加相关的单元格 /// </summary> /// <param name="row">新增的表格行对象</param> private void DoBusinessAboutAddRow(Row row) { Cell cellItem; Column colInfo; foreach (string item in this.dicColumnCollection.Keys) { colInfo = this.dicColumnCollection[item]; cellItem = new Cell(); cellItem.RowID = row.RowID; cellItem.ColumnID = colInfo.ColumnID; row.Add(cellItem); } }
/// <summary> /// 将Table对象复制一份 /// </summary> private void CopyObject(AojTable tbObjectFrom, AojTable tbObjectTo) { #region 表格 tbObjectTo.Name = tbObjectFrom.Name; tbObjectTo.Left = tbObjectFrom.Left; tbObjectTo.Top = tbObjectFrom.Top; tbObjectTo.Width = tbObjectFrom.Width; tbObjectTo.Height = tbObjectFrom.Height; tbObjectTo.MyDocument = new CellDocument(true); #endregion #region 表格列 Column colItem; Column colNewItem; foreach (string strColId in tbObjectFrom.MyDocument.ColumnCollection.Keys) { colItem = tbObjectFrom.MyDocument.ColumnCollection[strColId]; colNewItem = new Column(); colNewItem.ColumnID = colItem.ColumnID; colNewItem.ColumnRatio = colItem.ColumnRatio; colNewItem.ColumnWidth = colItem.ColumnWidth; tbObjectTo.MyDocument.ColumnCollection.Add(strColId, colNewItem); } #endregion #region 表格行 Row rowItem; Row rowNewItem; Cell cellNewItem; foreach (string strRowId in tbObjectFrom.MyDocument.RowCollection.Keys) { rowItem = tbObjectFrom.MyDocument.RowCollection[strRowId]; rowNewItem = new Row(); rowNewItem.RowID = rowItem.RowID; rowNewItem.RowHeight = rowItem.RowHeight; rowNewItem.RowRatio = rowItem.RowRatio; tbObjectTo.MyDocument.RowCollection.Add(strRowId, rowNewItem); #region 单元格 int index = 0; foreach (string strColId in tbObjectFrom.MyDocument.ColumnCollection.Keys) { colItem = tbObjectFrom.MyDocument.ColumnCollection[strColId]; cellNewItem = new Cell(); cellNewItem.ColumnID = colItem.ColumnID; cellNewItem.RowID = rowItem[index].RowID; cellNewItem.Text = rowItem[index].Text; cellNewItem.TextFamilyName = rowItem[index].TextFamilyName; cellNewItem.TextFontSize = rowItem[index].TextFontSize; cellNewItem.TextFontStyle = rowItem[index].TextFontStyle; cellNewItem.TextColor = rowItem[index].TextColor; cellNewItem.ObjectAlignment = rowItem[index].ObjectAlignment; cellNewItem.ObjectLineAlignment = rowItem[index].ObjectLineAlignment; rowNewItem.Add(cellNewItem); ++index; } #endregion } #endregion }
/// <summary> /// 从xml文档中获得对象 /// </summary> public override void OpenFormXML(XmlNode objNode) { if (objNode != null) { #region 对象的相关属性 this.Name = objNode.Attributes["Id"].Value; this.Left = float.Parse(objNode.Attributes["PositionX"].Value); this.Top = float.Parse(objNode.Attributes["PositionY"].Value); this.Width = float.Parse(objNode.Attributes["Width"].Value); this.Height = float.Parse(objNode.Attributes["Height"].Value); #endregion XmlNodeList lstColumn = objNode.SelectNodes("Column"); XmlNodeList lstRow = objNode.SelectNodes("Row"); if (lstColumn != null && lstRow != null) { int columnCount = lstColumn.Count; int rowCount = lstRow.Count; if (columnCount > 0 && rowCount > 0) { Column colItem; Row rowItem; XmlNodeList lstChildNode; Cell cellItem; XmlNode childCellNode; this.myDocument = new CellDocument(true); #region 表格列 foreach (XmlNode nodeColumnItem in lstColumn) { colItem = new Column(); colItem.ColumnID = nodeColumnItem.Attributes["Id"].Value; colItem.ColumnWidth = float.Parse(nodeColumnItem.Attributes["Width"].Value); this.myDocument.AddColumn(colItem.ColumnID, colItem); #region 表格行 foreach (XmlNode nodeRowItem in lstRow) { lstChildNode = nodeRowItem.SelectNodes("Cell"); if (lstChildNode != null && lstChildNode.Count > 0) { if (columnCount == lstChildNode.Count) { rowItem = new Row(); rowItem.RowID = nodeRowItem.Attributes["Id"].Value; rowItem.RowHeight = float.Parse(nodeRowItem.Attributes["Height"].Value); this.myDocument.AddRow(rowItem.RowID, rowItem); rowItem.Clear(); #region 单元格 foreach (XmlNode nodeCellItem in lstChildNode) { cellItem = new Cell(); cellItem.ColumnID = colItem.ColumnID; cellItem.RowID = rowItem.RowID; cellItem.Width = colItem.ColumnWidth; cellItem.Height = rowItem.RowHeight; childCellNode = nodeCellItem.SelectSingleNode("Text"); if (childCellNode != null) { cellItem.TextFamilyName = childCellNode.Attributes["FamilyName"].Value; cellItem.TextFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), childCellNode.Attributes["FontStyle"].Value); cellItem.TextFontSize = float.Parse(childCellNode.Attributes["FontSize"].Value); cellItem.TextColor = ColorTranslator.FromHtml(childCellNode.Attributes["Color"].Value); cellItem.Text = childCellNode.InnerText; this.SetStringAlignmentFormat(cellItem, childCellNode.Attributes["Alignment"].Value); } rowItem.Add(cellItem); } #endregion } } } #endregion } #endregion } } //设置表格中每列的比例 this.SetColumnRatioInfo(); //设置表格中每行的比例 this.SetRowRatioInfo(); } }