public static void AddBorder(BorderCode borderCode, String where, StringBuilder style) { if (borderCode == null || borderCode.IsEmpty) { return; } if (string.IsNullOrEmpty(where)) { style.Append("border:"); } else { style.Append("border-"); style.Append(where); } style.Append(":"); if (borderCode.LineWidth < 8) { style.Append("thin"); } else { style.Append(GetBorderWidth(borderCode)); } style.Append(' '); style.Append(GetBorderType(borderCode)); style.Append(' '); style.Append(GetColor(borderCode.Color)); style.Append(';'); }
/// <summary> /// Writes a border element /// </summary> /// <param name="name">The name of the element</param> /// <param name="brc">The BorderCode object</param> private void writePictureBorder(string name, BorderCode brc) { _writer.WriteStartElement("w10", name, OpenXmlNamespaces.OfficeWord); _writer.WriteAttributeString("type", getBorderType(brc.brcType)); _writer.WriteAttributeString("width", brc.dptLineWidth.ToString()); _writer.WriteEndElement(); }
protected void appendBorderAttributes(BorderCode brc, XmlNode border) { if (brc.fNil) { XmlAttribute val = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML); val.Value = "nil"; border.Attributes.Append(val); } else { XmlAttribute val = _nodeFactory.CreateAttribute("w", "val", OpenXmlNamespaces.WordprocessingML); val.Value = getBorderType(brc.brcType); border.Attributes.Append(val); XmlAttribute color = _nodeFactory.CreateAttribute("w", "color", OpenXmlNamespaces.WordprocessingML); color.Value = new RGBColor(brc.cv, RGBColor.ByteOrder.RedFirst).SixDigitHexCode; border.Attributes.Append(color); XmlAttribute space = _nodeFactory.CreateAttribute("w", "space", OpenXmlNamespaces.WordprocessingML); space.Value = brc.dptSpace.ToString(); border.Attributes.Append(space); XmlAttribute sz = _nodeFactory.CreateAttribute("w", "sz", OpenXmlNamespaces.WordprocessingML); sz.Value = brc.dptLineWidth.ToString(); border.Attributes.Append(sz); if (brc.fShadow) { XmlAttribute shadow = _nodeFactory.CreateAttribute("w", "shadow", OpenXmlNamespaces.WordprocessingML); shadow.Value = "1"; border.Attributes.Append(shadow); } } }
public static void SetBorder(XmlElement XmlElement, BorderCode borderCode, String where) { if (XmlElement == null) { throw new ArgumentException("XmlElement is null"); } if (borderCode == null || borderCode.BorderType == 0) { return; } if (string.IsNullOrEmpty(where)) { XmlElement.SetAttribute("border-style", GetBorderType(borderCode)); XmlElement.SetAttribute("border-color", GetColor(borderCode.Color)); XmlElement.SetAttribute("border-width", GetBorderWidth(borderCode)); } else { XmlElement.SetAttribute("border-" + where + "-style", GetBorderType(borderCode)); XmlElement.SetAttribute("border-" + where + "-color", GetColor(borderCode.Color)); XmlElement.SetAttribute("border-" + where + "-width", GetBorderWidth(borderCode)); } }
public static void AddTableCellProperties(TableRow tableRow, TableCell tableCell, bool toppest, bool bottomest, bool leftest, bool rightest, StringBuilder style) { style.Append("width:" + (tableCell.GetWidth() / TWIPS_PER_INCH) + "in;"); style.Append("padding-start:" + (tableRow.GetGapHalf() / TWIPS_PER_INCH) + "in;"); style.Append("padding-end:" + (tableRow.GetGapHalf() / TWIPS_PER_INCH) + "in;"); BorderCode top = tableCell.GetBrcTop() != null && tableCell.GetBrcTop().BorderType != 0 ? tableCell .GetBrcTop() : toppest?tableRow.GetTopBorder() : tableRow .GetHorizontalBorder(); BorderCode bottom = tableCell.GetBrcBottom() != null && tableCell.GetBrcBottom().BorderType != 0 ? tableCell .GetBrcBottom() : bottomest?tableRow.GetBottomBorder() : tableRow.GetHorizontalBorder(); BorderCode left = tableCell.GetBrcLeft() != null && tableCell.GetBrcLeft().BorderType != 0 ? tableCell .GetBrcLeft() : leftest?tableRow.GetLeftBorder() : tableRow .GetVerticalBorder(); BorderCode right = tableCell.GetBrcRight() != null && tableCell.GetBrcRight().BorderType != 0 ? tableCell .GetBrcRight() : rightest?tableRow.GetRightBorder() : tableRow.GetVerticalBorder(); AddBorder(bottom, "bottom", style); AddBorder(left, "left", style); AddBorder(right, "right", style); AddBorder(top, "top", style); }
public static String GetBorderWidth(BorderCode borderCode) { int lineWidth = borderCode.LineWidth; int pt = lineWidth / 8; int pte = lineWidth - pt * 8; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(pt); stringBuilder.Append("."); stringBuilder.Append(1000 / 8 * pte); stringBuilder.Append("pt"); return(stringBuilder.ToString()); }
protected PAPAbstractType() { this.field_11_lspd = new LineSpacingDescriptor(); this.field_11_lspd = new LineSpacingDescriptor(); this.field_28_dcs = new DropCapSpecifier(); this.field_32_fWidowControl = true; this.field_41_lvl = 9; this.field_61_brcTop = new BorderCode(); this.field_62_brcLeft = new BorderCode(); this.field_63_brcBottom = new BorderCode(); this.field_64_brcRight = new BorderCode(); this.field_65_brcBetween = new BorderCode(); this.field_66_brcBar = new BorderCode(); this.field_67_shd = new ShadingDescriptor(); this.field_68_anld = new byte[0]; this.field_69_phe = new byte[0]; this.field_72_dttmPropRMark = new DateAndTime(); this.field_74_rgdxaTab = new int[0]; this.field_75_rgtbd = new byte[0]; this.field_76_numrm = new byte[0]; this.field_77_ptap = new byte[0]; }
public static void SetTableCellProperties(TableRow tableRow, TableCell tableCell, XmlElement XmlElement, bool toppest, bool bottomest, bool leftest, bool rightest) { XmlElement.SetAttribute("width", (tableCell.GetWidth() / TWIPS_PER_INCH) + "in"); XmlElement.SetAttribute("padding-start", (tableRow.GetGapHalf() / TWIPS_PER_INCH) + "in"); XmlElement.SetAttribute("padding-end", (tableRow.GetGapHalf() / TWIPS_PER_INCH) + "in"); BorderCode top = tableCell.GetBrcTop() != null && tableCell.GetBrcTop().BorderType != 0 ? tableCell .GetBrcTop() : toppest?tableRow.GetTopBorder() : tableRow .GetHorizontalBorder(); BorderCode bottom = tableCell.GetBrcBottom() != null && tableCell.GetBrcBottom().BorderType != 0 ? tableCell .GetBrcBottom() : bottomest?tableRow.GetBottomBorder() : tableRow.GetHorizontalBorder(); BorderCode left = tableCell.GetBrcLeft() != null && tableCell.GetBrcLeft().BorderType != 0 ? tableCell .GetBrcLeft() : leftest?tableRow.GetLeftBorder() : tableRow .GetVerticalBorder(); BorderCode right = tableCell.GetBrcRight() != null && tableCell.GetBrcRight().BorderType != 0 ? tableCell .GetBrcRight() : rightest?tableRow.GetRightBorder() : tableRow.GetVerticalBorder(); SetBorder(XmlElement, bottom, "bottom"); SetBorder(XmlElement, left, "left"); SetBorder(XmlElement, right, "right"); SetBorder(XmlElement, top, "top"); }
/** * Set the brcTop field for the TAP record. */ public void SetBrcTop(BorderCode field_12_brcTop) { this.field_12_brcTop = field_12_brcTop; }
public static String GetBorderType(BorderCode borderCode) { if (borderCode == null) { throw new ArgumentNullException("borderCode is null"); } switch (borderCode.BorderType) { case 1: case 2: return("solid"); case 3: return("double"); case 5: return("solid"); case 6: return("dotted"); case 7: case 8: return("dashed"); case 9: return("dotted"); case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: return("double"); case 20: return("solid"); case 21: return("double"); case 22: return("dashed"); case 23: return("dashed"); case 24: return("ridge"); case 25: return("grooved"); default: return("solid"); } }
public void Apply(TablePropertyExceptions tapx) { var tblBorders = this._nodeFactory.CreateElement("w", "tblBorders", OpenXmlNamespaces.WordprocessingML); var tblCellMar = this._nodeFactory.CreateElement("w", "tblCellMar", OpenXmlNamespaces.WordprocessingML); var tblLayout = this._nodeFactory.CreateElement("w", "tblLayout", OpenXmlNamespaces.WordprocessingML); var tblpPr = this._nodeFactory.CreateElement("w", "tblpPr", OpenXmlNamespaces.WordprocessingML); var layoutType = this._nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); layoutType.Value = "fixed"; short tblIndent = 0; short gabHalf = 0; short marginLeft = 0; short marginRight = 0; foreach (var sprm in tapx.grpprl) { switch (sprm.OpCode) { case SinglePropertyModifier.OperationCode.sprmTDxaGapHalf: gabHalf = System.BitConverter.ToInt16(sprm.Arguments, 0); break; //table definition case SinglePropertyModifier.OperationCode.sprmTDefTable: var tDef = new SprmTDefTable(sprm.Arguments); //Workaround for retrieving the indent of the table: //In some files there is a indent but no sprmTWidthIndent is set. //For this cases we can calculate the indent of the table by getting the //first boundary of the TDef and adding the padding of the cells tblIndent = System.BitConverter.ToInt16(sprm.Arguments, 1); //add the gabHalf tblIndent += gabHalf; //If there follows a real sprmTWidthIndent, this value will be overwritten break; //preferred table width case SinglePropertyModifier.OperationCode.sprmTTableWidth: var fts = (WidthType)sprm.Arguments[0]; short width = System.BitConverter.ToInt16(sprm.Arguments, 1); var tblW = this._nodeFactory.CreateElement("w", "tblW", OpenXmlNamespaces.WordprocessingML); var w = this._nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); w.Value = width.ToString(); var type = this._nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); type.Value = fts.ToString(); tblW.Attributes.Append(type); tblW.Attributes.Append(w); this._tblPr.AppendChild(tblW); break; //justification case SinglePropertyModifier.OperationCode.sprmTJc: case SinglePropertyModifier.OperationCode.sprmTJcRow: appendValueElement(this._tblPr, "jc", ((Global.JustificationCode)sprm.Arguments[0]).ToString(), true); break; //indent case SinglePropertyModifier.OperationCode.sprmTWidthIndent: tblIndent = System.BitConverter.ToInt16(sprm.Arguments, 1); break; //style case SinglePropertyModifier.OperationCode.sprmTIstd: case SinglePropertyModifier.OperationCode.sprmTIstdPermute: short styleIndex = System.BitConverter.ToInt16(sprm.Arguments, 0); if (this._styles.Styles.Count > styleIndex) { string id = StyleSheetMapping.MakeStyleId(this._styles.Styles[styleIndex]); if (id != "TableNormal") { appendValueElement(this._tblPr, "tblStyle", id, true); } } break; //bidi case SinglePropertyModifier.OperationCode.sprmTFBiDi: case SinglePropertyModifier.OperationCode.sprmTFBiDi90: appendValueElement(this._tblPr, "bidiVisual", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString(), true); break; //table look case SinglePropertyModifier.OperationCode.sprmTTlp: appendValueElement(this._tblPr, "tblLook", string.Format("{0:x4}", System.BitConverter.ToInt16(sprm.Arguments, 2)), true); break; //autofit case SinglePropertyModifier.OperationCode.sprmTFAutofit: if (sprm.Arguments[0] == 1) { layoutType.Value = "auto"; } break; //default cell padding (margin) case SinglePropertyModifier.OperationCode.sprmTCellPadding: case SinglePropertyModifier.OperationCode.sprmTCellPaddingDefault: case SinglePropertyModifier.OperationCode.sprmTCellPaddingOuter: byte grfbrc = sprm.Arguments[2]; short wMar = System.BitConverter.ToInt16(sprm.Arguments, 4); if (Utils.BitmaskToBool((int)grfbrc, 0x01)) { appendDxaElement(tblCellMar, "top", wMar.ToString(), true); } if (Utils.BitmaskToBool((int)grfbrc, 0x02)) { marginLeft = wMar; } if (Utils.BitmaskToBool((int)grfbrc, 0x04)) { appendDxaElement(tblCellMar, "bottom", wMar.ToString(), true); } if (Utils.BitmaskToBool((int)grfbrc, 0x08)) { marginRight = wMar; } break; //row count case SinglePropertyModifier.OperationCode.sprmTCHorzBands: appendValueElement(this._tblPr, "tblStyleRowBandSize", sprm.Arguments[0].ToString(), true); break; //col count case SinglePropertyModifier.OperationCode.sprmTCVertBands: appendValueElement(this._tblPr, "tblStyleColBandSize", sprm.Arguments[0].ToString(), true); break; //overlap case SinglePropertyModifier.OperationCode.sprmTFNoAllowOverlap: bool noOverlap = Utils.ByteToBool(sprm.Arguments[0]); string tblOverlapVal = "overlap"; if (noOverlap) { tblOverlapVal = "never"; } appendValueElement(this._tblPr, "tblOverlap", tblOverlapVal, true); break; //shading case SinglePropertyModifier.OperationCode.sprmTSetShdTable: var desc = new ShadingDescriptor(sprm.Arguments); appendShading(this._tblPr, desc); break; //borders 80 exceptions case SinglePropertyModifier.OperationCode.sprmTTableBorders80: var brc80 = new byte[4]; //top border Array.Copy(sprm.Arguments, 0, brc80, 0, 4); this.brcTop = new BorderCode(brc80); //left Array.Copy(sprm.Arguments, 4, brc80, 0, 4); this.brcLeft = new BorderCode(brc80); //bottom Array.Copy(sprm.Arguments, 8, brc80, 0, 4); this.brcBottom = new BorderCode(brc80); //right Array.Copy(sprm.Arguments, 12, brc80, 0, 4); this.brcRight = new BorderCode(brc80); //inside H Array.Copy(sprm.Arguments, 16, brc80, 0, 4); this.brcHorz = new BorderCode(brc80); //inside V Array.Copy(sprm.Arguments, 20, brc80, 0, 4); this.brcVert = new BorderCode(brc80); break; //border exceptions case SinglePropertyModifier.OperationCode.sprmTTableBorders: var brc = new byte[8]; //top border Array.Copy(sprm.Arguments, 0, brc, 0, 8); this.brcTop = new BorderCode(brc); //left Array.Copy(sprm.Arguments, 8, brc, 0, 8); this.brcLeft = new BorderCode(brc); //bottom Array.Copy(sprm.Arguments, 16, brc, 0, 8); this.brcBottom = new BorderCode(brc); //right Array.Copy(sprm.Arguments, 24, brc, 0, 8); this.brcRight = new BorderCode(brc); //inside H Array.Copy(sprm.Arguments, 32, brc, 0, 8); this.brcHorz = new BorderCode(brc); //inside V Array.Copy(sprm.Arguments, 40, brc, 0, 8); this.brcVert = new BorderCode(brc); break; //floating table properties case SinglePropertyModifier.OperationCode.sprmTPc: byte flag = sprm.Arguments[0]; var pcVert = (Global.VerticalPositionCode)((flag & 0x30) >> 4); var pcHorz = (Global.HorizontalPositionCode)((flag & 0xC0) >> 6); appendValueAttribute(tblpPr, "horzAnchor", pcHorz.ToString()); appendValueAttribute(tblpPr, "vertAnchor", pcVert.ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDxaFromText: appendValueAttribute(tblpPr, "leftFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDxaFromTextRight: appendValueAttribute(tblpPr, "rightFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDyaFromText: appendValueAttribute(tblpPr, "topFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDyaFromTextBottom: appendValueAttribute(tblpPr, "bottomFromText", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDxaAbs: appendValueAttribute(tblpPr, "tblpX", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; case SinglePropertyModifier.OperationCode.sprmTDyaAbs: appendValueAttribute(tblpPr, "tblpY", System.BitConverter.ToInt16(sprm.Arguments, 0).ToString()); break; } } //indent if (tblIndent != 0) { var tblInd = this._nodeFactory.CreateElement("w", "tblInd", OpenXmlNamespaces.WordprocessingML); var tblIndW = this._nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); tblIndW.Value = tblIndent.ToString(); tblInd.Attributes.Append(tblIndW); var tblIndType = this._nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); tblIndType.Value = "dxa"; tblInd.Attributes.Append(tblIndType); this._tblPr.AppendChild(tblInd); } //append floating props if (tblpPr.Attributes.Count > 0) { this._tblPr.AppendChild(tblpPr); } //set borders if (this.brcTop != null) { var topBorder = this._nodeFactory.CreateNode(XmlNodeType.Element, "w", "top", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(this.brcTop, topBorder); addOrSetBorder(this._tblBorders, topBorder); } if (this.brcLeft != null) { var leftBorder = this._nodeFactory.CreateNode(XmlNodeType.Element, "w", "left", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(this.brcLeft, leftBorder); addOrSetBorder(this._tblBorders, leftBorder); } if (this.brcBottom != null) { var bottomBorder = this._nodeFactory.CreateNode(XmlNodeType.Element, "w", "bottom", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(this.brcBottom, bottomBorder); addOrSetBorder(this._tblBorders, bottomBorder); } if (this.brcRight != null) { var rightBorder = this._nodeFactory.CreateNode(XmlNodeType.Element, "w", "right", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(this.brcRight, rightBorder); addOrSetBorder(this._tblBorders, rightBorder); } if (this.brcHorz != null) { var insideHBorder = this._nodeFactory.CreateNode(XmlNodeType.Element, "w", "insideH", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(this.brcHorz, insideHBorder); addOrSetBorder(this._tblBorders, insideHBorder); } if (this.brcVert != null) { var insideVBorder = this._nodeFactory.CreateNode(XmlNodeType.Element, "w", "insideV", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(this.brcVert, insideVBorder); addOrSetBorder(this._tblBorders, insideVBorder); } if (this._tblBorders.ChildNodes.Count > 0) { this._tblPr.AppendChild(this._tblBorders); } //append layout type tblLayout.Attributes.Append(layoutType); this._tblPr.AppendChild(tblLayout); //append margins if (marginLeft == 0 && gabHalf != 0) { appendDxaElement(tblCellMar, "left", gabHalf.ToString(), true); } else { appendDxaElement(tblCellMar, "left", marginLeft.ToString(), true); } if (marginRight == 0 && gabHalf != 0) { appendDxaElement(tblCellMar, "right", gabHalf.ToString(), true); } else { appendDxaElement(tblCellMar, "right", marginRight.ToString(), true); } this._tblPr.AppendChild(tblCellMar); //write Properties if (this._tblPr.ChildNodes.Count > 0 || this._tblPr.Attributes.Count > 0) { this._tblPr.WriteTo(this._writer); } //append the grid this._tblGrid = this._nodeFactory.CreateElement("w", "tblGrid", OpenXmlNamespaces.WordprocessingML); foreach (short colW in this._grid) { var gridCol = this._nodeFactory.CreateElement("w", "gridCol", OpenXmlNamespaces.WordprocessingML); var gridColW = this._nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); gridColW.Value = colW.ToString(); gridCol.Attributes.Append(gridColW); this._tblGrid.AppendChild(gridCol); } this._tblGrid.WriteTo(this._writer); }
/** * Set the brcBetween field for the PAP record. */ public void SetBrcBetween(BorderCode field_65_brcBetween) { this.field_65_brcBetween = field_65_brcBetween; }
/** * Set the brcHorizontal field for the TAP record. */ public void SetBrcHorizontal(BorderCode field_16_brcHorizontal) { this.field_16_brcHorizontal = field_16_brcHorizontal; }
/** * Set the brcVertical field for the TAP record. */ public void SetBrcVertical(BorderCode field_15_brcVertical) { this.field_15_brcVertical = field_15_brcVertical; }
/** * Set the brcRight field for the TAP record. */ public void SetBrcRight(BorderCode field_14_brcRight) { this.field_14_brcRight = field_14_brcRight; }
/** * Set the brcLeft field for the TAP record. */ public void SetBrcLeft(BorderCode field_13_brcLeft) { this.field_13_brcLeft = field_13_brcLeft; }
/** * Set the brcBar field for the PAP record. */ public void SetBrcBar(BorderCode field_66_brcBar) { this.field_66_brcBar = field_66_brcBar; }
/** * Set the brcBottom field for the TAP record. */ public void SetBrcBottom(BorderCode field_11_brcBottom) { this.field_11_brcBottom = field_11_brcBottom; }
public void Apply(TablePropertyExceptions tapx) { //int lastBdr = getLastTabelBorderOccurrence(tapx.grpprl); for (int i = 0; i < tapx.grpprl.Count; i++) { SinglePropertyModifier sprm = tapx.grpprl[i]; switch (sprm.OpCode) { //Table definition SPRM case SinglePropertyModifier.OperationCode.sprmTDefTable: SprmTDefTable tdef = new SprmTDefTable(sprm.Arguments); _tGrid = tdef.rgdxaCenter; _tcDef = tdef.rgTc80[_cellIndex]; appendValueElement(_tcPr, "textDirection", _tcDef.textFlow.ToString(), false); if (_tcDef.vertMerge == Global.VerticalMergeFlag.fvmMerge) { appendValueElement(_tcPr, "vMerge", "continue", false); } else if (_tcDef.vertMerge == Global.VerticalMergeFlag.fvmRestart) { appendValueElement(_tcPr, "vMerge", "restart", false); } else if (_tcDef.vertMerge == Global.VerticalMergeFlag.fvmRestart) { appendValueElement(_tcPr, "vMerge", "restart", false); } appendValueElement(_tcPr, "vAlign", _tcDef.vertAlign.ToString(), false); if (_tcDef.fFitText) { appendValueElement(_tcPr, "tcFitText", "", false); } if (_tcDef.fNoWrap) { appendValueElement(_tcPr, "noWrap", "", true); } //_width = _tcDef.wWidth; _width = (Int16)(tdef.rgdxaCenter[_cellIndex + 1] - tdef.rgdxaCenter[_cellIndex]); _ftsWidth = _tcDef.ftsWidth; //borders // if the sprm has a higher priority than the last sprmTTableBorder sprm in the list //if (i > lastBdr) //{ // _brcTop = _tcDef.brcTop; // _brcLeft = _tcDef.brcLeft; // _brcRight = _tcDef.brcRight; // _brcBottom = _tcDef.brcBottom; //} break; //margins case SinglePropertyModifier.OperationCode.sprmTCellPadding: byte first = sprm.Arguments[0]; byte lim = sprm.Arguments[1]; byte ftsMargin = sprm.Arguments[3]; Int16 wMargin = System.BitConverter.ToInt16(sprm.Arguments, 4); if (_cellIndex >= first && _cellIndex < lim) { BitArray borderBits = new BitArray(new byte[] { sprm.Arguments[2] }); if (borderBits[0] == true) { appendDxaElement(_tcMar, "top", wMargin.ToString(), true); } if (borderBits[1] == true) { appendDxaElement(_tcMar, "left", wMargin.ToString(), true); } if (borderBits[2] == true) { appendDxaElement(_tcMar, "bottom", wMargin.ToString(), true); } if (borderBits[3] == true) { appendDxaElement(_tcMar, "right", wMargin.ToString(), true); } } break; //shading case SinglePropertyModifier.OperationCode.sprmTDefTableShd: //cell shading for cells 0-20 apppendCellShading(sprm.Arguments, _cellIndex); break; case SinglePropertyModifier.OperationCode.sprmTDefTableShd2nd: //cell shading for cells 21-42 apppendCellShading(sprm.Arguments, _cellIndex - 21); break; case SinglePropertyModifier.OperationCode.sprmTDefTableShd3rd: //cell shading for cells 43-62 apppendCellShading(sprm.Arguments, _cellIndex - 43); break; //width case SinglePropertyModifier.OperationCode.sprmTCellWidth: first = sprm.Arguments[0]; lim = sprm.Arguments[1]; if (_cellIndex >= first && _cellIndex < lim) { _ftsWidth = (Global.CellWidthType)sprm.Arguments[2]; _width = System.BitConverter.ToInt16(sprm.Arguments, 3); } break; //vertical alignment case SinglePropertyModifier.OperationCode.sprmTVertAlign: first = sprm.Arguments[0]; lim = sprm.Arguments[1]; if (_cellIndex >= first && _cellIndex < lim) { appendValueElement(_tcPr, "vAlign", ((VerticalCellAlignment)sprm.Arguments[2]).ToString(), true); } break; //Autofit case SinglePropertyModifier.OperationCode.sprmTFitText: first = sprm.Arguments[0]; lim = sprm.Arguments[1]; if (_cellIndex >= first && _cellIndex < lim) { appendValueElement(_tcPr, "tcFitText", sprm.Arguments[2].ToString(), true); } break; //borders (cell definition) case SinglePropertyModifier.OperationCode.sprmTSetBrc: byte min = sprm.Arguments[0]; byte max = sprm.Arguments[1]; int bordersToApply = (int)sprm.Arguments[2]; if (_cellIndex >= min && _cellIndex < max) { byte[] brcBytes = new byte[8]; Array.Copy(sprm.Arguments, 3, brcBytes, 0, 8); BorderCode border = new BorderCode(brcBytes); if (Utils.BitmaskToBool(bordersToApply, 0x01)) { _brcTop = border; } if (Utils.BitmaskToBool(bordersToApply, 0x02)) { _brcLeft = border; } if (Utils.BitmaskToBool(bordersToApply, 0x04)) { _brcBottom = border; } if (Utils.BitmaskToBool(bordersToApply, 0x08)) { _brcRight = border; } } break; } } //width XmlElement tcW = _nodeFactory.CreateElement("w", "tcW", OpenXmlNamespaces.WordprocessingML); XmlAttribute tcWType = _nodeFactory.CreateAttribute("w", "type", OpenXmlNamespaces.WordprocessingML); XmlAttribute tcWVal = _nodeFactory.CreateAttribute("w", "w", OpenXmlNamespaces.WordprocessingML); tcWType.Value = _ftsWidth.ToString(); tcWVal.Value = _width.ToString(); tcW.Attributes.Append(tcWType); tcW.Attributes.Append(tcWVal); _tcPr.AppendChild(tcW); //grid span _gridSpan = 1; if (_width > _grid[_gridIndex]) { //check the number of merged cells int w = _grid[_gridIndex]; for (int i = _gridIndex + 1; i < _grid.Count; i++) { _gridSpan++; w += _grid[i]; if (w >= _width) { break; } } appendValueElement(_tcPr, "gridSpan", _gridSpan.ToString(), true); } //append margins if (_tcMar.ChildNodes.Count > 0) { _tcPr.AppendChild(_tcMar); } //append borders if (_brcTop != null) { XmlNode topBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "top", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(_brcTop, topBorder); addOrSetBorder(_tcBorders, topBorder); } if (_brcLeft != null) { XmlNode leftBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "left", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(_brcLeft, leftBorder); addOrSetBorder(_tcBorders, leftBorder); } if (_brcBottom != null) { XmlNode bottomBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "bottom", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(_brcBottom, bottomBorder); addOrSetBorder(_tcBorders, bottomBorder); } if (_brcRight != null) { XmlNode rightBorder = _nodeFactory.CreateNode(XmlNodeType.Element, "w", "right", OpenXmlNamespaces.WordprocessingML); appendBorderAttributes(_brcRight, rightBorder); addOrSetBorder(_tcBorders, rightBorder); } if (_tcBorders.ChildNodes.Count > 0) { _tcPr.AppendChild(_tcBorders); } //write Properties if (_tcPr.ChildNodes.Count > 0 || _tcPr.Attributes.Count > 0) { _tcPr.WriteTo(_writer); } }
/** * Set the brc field for the CHP record. */ public void SetBrc(BorderCode field_43_brc) { this.field_43_brc = field_43_brc; }