public HCTableCell(HCStyle AStyle) : this() { FCellData = new HCTableCellData(AStyle); FAlignVert = View.HCAlignVert.cavTop; FBorderSides = new HCBorderSides(); FBorderSides.InClude((byte)BorderSide.cbsLeft); FBorderSides.InClude((byte)BorderSide.cbsTop); FBorderSides.InClude((byte)BorderSide.cbsRight); FBorderSides.InClude((byte)BorderSide.cbsBottom); FBackgroundColor = AStyle.BackgroudColor; FRowSpan = 0; FColSpan = 0; }
public virtual void LoadFromStream(Stream aStream, HCStyle aStyle, ushort aFileVersion) { byte[] vBuffer = BitConverter.GetBytes(FWidth); aStream.Read(vBuffer, 0, vBuffer.Length); FWidth = BitConverter.ToInt32(vBuffer, 0); vBuffer = BitConverter.GetBytes(FHeight); aStream.Read(vBuffer, 0, vBuffer.Length); FHeight = BitConverter.ToInt32(vBuffer, 0); vBuffer = BitConverter.GetBytes(FRowSpan); aStream.Read(vBuffer, 0, vBuffer.Length); FRowSpan = BitConverter.ToInt32(vBuffer, 0); vBuffer = BitConverter.GetBytes(FColSpan); aStream.Read(vBuffer, 0, vBuffer.Length); FColSpan = BitConverter.ToInt32(vBuffer, 0); if (aFileVersion > 11) { byte vByte = 0; vByte = (byte)aStream.ReadByte(); FAlignVert = (View.HCAlignVert)vByte; // 垂直对齐方式 HC.HCLoadColorFromStream(aStream, ref FBackgroundColor); // 背景色 } if (aFileVersion > 13) { FBorderSides.Value = (byte)aStream.ReadByte(); // load FBorderSides } bool vNullData = false; vBuffer = BitConverter.GetBytes(vNullData); aStream.Read(vBuffer, 0, vBuffer.Length); vNullData = BitConverter.ToBoolean(vBuffer, 0); if (!vNullData) { FCellData.LoadFromStream(aStream, aStyle, aFileVersion); FCellData.CellHeight = FHeight; } else if ((FRowSpan < 0) || (FColSpan < 0)) // 修正表格合并处理不准确造成的错误,容错打不开的情况 { FCellData.Dispose(); FCellData = null; } }
public void ParseXml(XmlElement aNode) { FWidth = int.Parse(aNode.Attributes["width"].Value); FHeight = int.Parse(aNode.Attributes["height"].Value); FRowSpan = int.Parse(aNode.Attributes["rowspan"].Value); FColSpan = int.Parse(aNode.Attributes["colspan"].Value); FAlignVert = (HCAlignVert)(byte.Parse(aNode.Attributes["vert"].Value)); FBackgroundColor = HC.GetXmlRGBColor(aNode.Attributes["bkcolor"].Value); HC.SetBorderSideByPro(aNode.Attributes["border"].Value, FBorderSides); if ((FRowSpan < 0) || (FColSpan < 0)) { FCellData.Dispose(); //FCellData = null; } else { FCellData.ParseXml(aNode.SelectSingleNode("items") as XmlElement); } }
public virtual void ParseXml(XmlElement aNode) { FWidth = int.Parse(aNode.Attributes["width"].Value); FHeight = int.Parse(aNode.Attributes["height"].Value); FRowSpan = int.Parse(aNode.Attributes["rowspan"].Value); FColSpan = int.Parse(aNode.Attributes["colspan"].Value); FAlignVert = (HCAlignVert)(byte.Parse(aNode.Attributes["vert"].Value)); FBackgroundColor = HC.HCRGBStringToColor(aNode.Attributes["bkcolor"].Value); HC.SetBorderSideByPro(aNode.Attributes["border"].Value, FBorderSides); if ((FRowSpan < 0) || (FColSpan < 0)) { FCellData.Dispose(); FCellData = null; } else { FCellData.Width = FWidth; // // 不准确的赋值,应该减去2个水平padding,加载时使用无大碍 FCellData.ParseXml(aNode.SelectSingleNode("items") as XmlElement); } }
public void SetHCView(HCView aHCView) { FHCView = aHCView; HCRichData vData = FHCView.ActiveSection.ActiveData; DeTable vTable = vData.GetActiveItem() as DeTable; // 表格 tbxCellHPadding.Text = vTable.CellHPadding.ToString(); tbxCellVPadding.Text = vTable.CellVPadding.ToString(); cbxBorderVisible.Checked = vTable.BorderVisible; tbxBorderWidth.Text = vTable.BorderWidth.ToString(); tbxFixRowFirst.Text = (vTable.FixRow + 1).ToString(); tbxFixRowLast.Text = (vTable.FixRow + vTable.FixRowCount).ToString(); tbxFixColFirst.Text = (vTable.FixCol + 1).ToString(); tbxFixColLast.Text = (vTable.FixCol + vTable.FixColCount).ToString(); // 行 if (vTable.SelectCellRang.StartRow >= 0) { tabRow.Text = "行(" + (vTable.SelectCellRang.StartRow + 1).ToString() + ")"; if (vTable.SelectCellRang.EndRow > 0) { tabRow.Text += " - (" + (vTable.SelectCellRang.EndRow + 1).ToString() + ")"; } tbxRowHeight.Text = vTable.Rows[vTable.SelectCellRang.StartRow].Height.ToString(); // 行高 } else { tabTableInfo.TabPages.Remove(tabRow); } // 单元格 if ((vTable.SelectCellRang.StartRow >= 0) && (vTable.SelectCellRang.StartCol >= 0)) { HCAlignVert vAlignVer = HCAlignVert.cavTop; if (vTable.SelectCellRang.EndRow >= 0) // 多选 { vAlignVer = vTable[vTable.SelectCellRang.StartRow, vTable.SelectCellRang.StartCol].AlignVert; tabCell.Text = "单元格(" + (vTable.SelectCellRang.StartRow + 1).ToString() + "," + (vTable.SelectCellRang.StartCol + 1).ToString() + ") - (" + (vTable.SelectCellRang.EndRow + 1).ToString() + "," + (vTable.SelectCellRang.EndCol + 1).ToString() + ")"; } else { vAlignVer = vTable.GetEditCell().AlignVert; tabCell.Text = "单元格(" + (vTable.SelectCellRang.StartRow + 1).ToString() + "," + (vTable.SelectCellRang.StartCol + 1).ToString() + ")"; } cbbCellAlignVert.SelectedIndex = (int)vAlignVer; } else { tabTableInfo.TabPages.Remove(tabCell); } dgvTable.RowCount = vTable.Propertys.Count + 1; if (vTable.Propertys.Count > 0) { int vRow = 0; foreach (KeyValuePair <string, string> keyValuePair in vTable.Propertys) { dgvTable.Rows[vRow].Cells[0].Value = keyValuePair.Key; dgvTable.Rows[vRow].Cells[1].Value = keyValuePair.Value; vRow++; } } this.ShowDialog(); if (this.DialogResult == System.Windows.Forms.DialogResult.OK) { FHCView.BeginUpdate(); try { // 表格 vTable.CellHPadding = byte.Parse(tbxCellHPadding.Text); vTable.CellVPadding = byte.Parse(tbxCellVPadding.Text); vTable.BorderWidth = byte.Parse(tbxBorderWidth.Text); vTable.BorderVisible = cbxBorderVisible.Checked; vTable.FixRow = (sbyte)(int.Parse(tbxFixRowFirst.Text, 0) - 1); vTable.FixRowCount = (byte)(int.Parse(tbxFixRowLast.Text, 0) - vTable.FixRow); vTable.FixCol = (sbyte)(int.Parse(tbxFixColFirst.Text, 0) - 1); vTable.FixColCount = (byte)(int.Parse(tbxFixColLast.Text, 0) - vTable.FixCol); // 行 if (vTable.SelectCellRang.StartRow >= 0) { int viValue = int.Parse(tbxRowHeight.Text); if (vTable.SelectCellRang.EndRow > 0) { for (int vR = vTable.SelectCellRang.StartRow; vR <= vTable.SelectCellRang.EndRow; vR++) { vTable.Rows[vR].Height = viValue; } } else { vTable.Rows[vTable.SelectCellRang.StartRow].Height = viValue; } } // 单元格 if ((vTable.SelectCellRang.StartRow >= 0) && (vTable.SelectCellRang.StartCol >= 0)) { if (vTable.SelectCellRang.EndCol > 0) { for (int vR = vTable.SelectCellRang.StartRow; vR <= vTable.SelectCellRang.EndRow; vR++) { for (int vC = vTable.SelectCellRang.StartCol; vC <= vTable.SelectCellRang.EndCol; vC++) { vTable[vR, vC].AlignVert = (HCAlignVert)cbbCellAlignVert.SelectedIndex; } } } else { vTable.GetEditCell().AlignVert = (HCAlignVert)cbbCellAlignVert.SelectedIndex; } } vTable.Propertys.Clear(); string vsValue = ""; for (int i = 0; i < dgvTable.RowCount; i++) { if (dgvTable.Rows[i].Cells[0].Value == null) { continue; } if (dgvTable.Rows[i].Cells[1].Value == null) { vsValue = ""; } else { vsValue = dgvTable.Rows[i].Cells[1].Value.ToString(); } if (dgvTable.Rows[i].Cells[0].Value.ToString().Trim() != "") { vTable.Propertys.Add(dgvTable.Rows[i].Cells[0].Value.ToString(), vsValue); } } if (FReFormat) { FHCView.ActiveSection.ReFormatActiveItem(); } } finally { FHCView.EndUpdate(); } } }