public void copy2(ref Word.Borders extBorders) { extBorders.AlwaysInFront = this.AlwaysInFront; //extBorders.Count = this.Count; //extBorders.Creator = this.Creator; try { extBorders.DistanceFrom = this.DistanceFrom; extBorders.DistanceFromBottom = this.DistanceFromBottom; extBorders.DistanceFromLeft = this.DistanceFromLeft; extBorders.DistanceFromRight = this.DistanceFromRight; extBorders.DistanceFromTop = this.DistanceFromTop; } catch (System.Exception ex) { } finally { } extBorders.Enable = this.Enable; extBorders.EnableFirstPageInSection = this.EnableFirstPageInSection; extBorders.EnableOtherPagesInSection = this.EnableOtherPagesInSection; //extBorders.HasHorizontal = this.HasHorizontal; //extBorders.HasVertical = this.HasVertical; extBorders.InsideColor = this.InsideColor; extBorders.InsideColorIndex = this.InsideColorIndex; extBorders.InsideLineStyle = this.InsideLineStyle; extBorders.InsideLineWidth = this.InsideLineWidth; extBorders.JoinBorders = this.JoinBorders; extBorders.OutsideColor = this.OutsideColor; extBorders.OutsideColorIndex = this.OutsideColorIndex; extBorders.OutsideLineStyle = this.OutsideLineStyle; extBorders.OutsideLineWidth = this.OutsideLineWidth; extBorders.Shadow = this.Shadow; extBorders.SurroundFooter = this.SurroundFooter; extBorders.SurroundHeader = this.SurroundHeader; ClassBorder classbd = null; for (int i = (int)WdBorderType.wdBorderVertical; i <= (int)WdBorderType.wdBorderTop; i++) { classbd = (ClassBorder)m_hashBorder[(WdBorderType)i]; if (classbd != null) { Word.Border bd = extBorders[(WdBorderType)i]; classbd.copy2(ref bd); } } return; }
// 复制到WORD.ParagraphFormat同名参数值 public void copy2(Word.ParagraphFormat dstParaFmt) { dstParaFmt.Alignment = this.Alignment; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.AutoAdjustRightIndent = this.AutoAdjustRightIndent; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.BaseLineAlignment = this.BaseLineAlignment; // 复制到WORD.ParagraphFormat同名参数值 Word.Borders bds = dstParaFmt.Borders; // 复制到WORD.ParagraphFormat同名参数值 //this.Borders.copy2(ref bds); dstParaFmt.CharacterUnitFirstLineIndent = this.CharacterUnitFirstLineIndent; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.CharacterUnitLeftIndent = this.CharacterUnitLeftIndent; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.CharacterUnitRightIndent = this.CharacterUnitRightIndent; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.DisableLineHeightGrid = this.DisableLineHeightGrid; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.FarEastLineBreakControl = this.FarEastLineBreakControl; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.FirstLineIndent = this.FirstLineIndent; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.HalfWidthPunctuationOnTopOfLine = this.HalfWidthPunctuationOnTopOfLine; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.HangingPunctuation = this.HangingPunctuation; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.Hyphenation = this.Hyphenation; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.KeepTogether = this.KeepTogether; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.KeepWithNext = this.KeepWithNext; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.LeftIndent = this.LeftIndent; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.LineSpacingRule = this.LineSpacingRule; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.LineSpacing = this.LineSpacing; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.LineUnitAfter = this.LineUnitAfter; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.LineUnitBefore = this.LineUnitBefore; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.MirrorIndents = this.MirrorIndents; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.OutlineLevel = this.OutlineLevel; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.NoLineNumber = this.NoLineNumber; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.PageBreakBefore = this.PageBreakBefore; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.ReadingOrder = this.ReadingOrder; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.RightIndent = this.RightIndent; // 复制到WORD.ParagraphFormat同名参数值 // dstParaFmt.Shading = this.Shading; Word.Shading shd = dstParaFmt.Shading;// 复制到WORD.ParagraphFormat同名参数值 //this.Shading.copy2(ref shd); dstParaFmt.SpaceAfter = this.SpaceAfter; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.SpaceAfterAuto = this.SpaceAfterAuto; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.SpaceBefore = this.SpaceBefore; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.SpaceBeforeAuto = this.SpaceBeforeAuto; // 复制到WORD.ParagraphFormat同名参数值 // dstParaFmt.TabStops = this.TabStops; dstParaFmt.TextboxTightWrap = this.TextboxTightWrap; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.WidowControl = this.WidowControl; // 复制到WORD.ParagraphFormat同名参数值 dstParaFmt.WordWrap = this.WordWrap; // 复制到WORD.ParagraphFormat同名参数值 return; }
public void SetCellsBorders(int iCol1, int iCol2, int iRow1, int iRow2, List <BorderInfo> listBorders, int indTable = -1) { GetTableReference(indTable); MSWord.Cell pCell1 = m_pTable.Cell(iRow1, iCol1); if (pCell1 == null) { return; } MSWord.Cell pCell2 = m_pTable.Cell(iRow2, iCol2); if (pCell2 == null) { return; } MSWord.Range r = m_pDoc.Range(pCell1.Range.Start, pCell2.Range.End); r.Select(); m_pSelection = m_pApp.Selection; if (m_pSelection == null) { return; } MSWord.Borders borders = m_pSelection.Borders; for (short index = 0; index < listBorders.Count; index++) { if (listBorders[index].m_type == MSWord.WdBorderType.wdBorderHorizontal && iRow1 == iRow2) { continue; } if (listBorders[index].m_type == MSWord.WdBorderType.wdBorderVertical && iCol1 == iCol2) { continue; } borders[listBorders[index].m_type].LineStyle = listBorders[index].m_style; if (listBorders[index].m_style != MSWord.WdLineStyle.wdLineStyleNone) { borders[listBorders[index].m_type].LineWidth = listBorders[index].m_width; borders[listBorders[index].m_type].Color = listBorders[index].m_color; } } }
public void SetTableBordersColor(long color, int indTable = -1) { GetTableReference(indTable); m_pTable.Select(); m_pSelection = m_pApp.Selection; if (m_pSelection == null) { return; } MSWord.Borders pBorders = m_pSelection.Borders; pBorders.Enable = 1; pBorders[MSWord.WdBorderType.wdBorderBottom].Color = (MSWord.WdColor)color; pBorders[MSWord.WdBorderType.wdBorderHorizontal].Color = (MSWord.WdColor)color; pBorders[MSWord.WdBorderType.wdBorderLeft].Color = (MSWord.WdColor)color; pBorders[MSWord.WdBorderType.wdBorderRight].Color = (MSWord.WdColor)color; pBorders[MSWord.WdBorderType.wdBorderTop].Color = (MSWord.WdColor)color; pBorders[MSWord.WdBorderType.wdBorderVertical].Color = (MSWord.WdColor)color; }
public void ConvertToTable(string strText, int row_cnt = -1, int col_cnt = -1, bool bSetBorders = true, string bookmark = "") { string strReturn = "" + (char)10; bool bUseReturn = false; if (strText.IndexOf(strReturn) >= 0) { bUseReturn = true; } strText = strText.Replace(strReturn, "#enter#"); if (bookmark == "") { if (m_pDoc == null) { m_pDoc = m_pApp.ActiveDocument; } if (m_pDoc == null) { return; } m_pDoc.Select(); m_pSelection = m_pApp.Selection; if (m_pSelection == null) { return; } m_pSelection.Collapse(0); object varInfo = m_pSelection.get_Information(MSWord.WdInformation.wdWithInTable); if (Convert.ToBoolean(varInfo) == true) { m_pDoc.Select(); m_pSelection = m_pApp.Selection; if (m_pSelection == null) { return; } m_pSelection.Collapse(0); } } else { m_pSelection.GoTo(-1, Type.Missing, Type.Missing, bookmark); }; m_pSelection.Font.Bold = 0; m_pSelection.Text = strText; m_pSelection.Paragraphs.SpaceAfter = 0; m_pSelection.Paragraphs.SpaceBefore = 0; m_pSelection.Paragraphs.LineSpacingRule = MSWord.WdLineSpacing.wdLineSpaceSingle; if (row_cnt < 0 && col_cnt < 0) { m_pTable = m_pSelection.ConvertToTable(1, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 0, 0); } else { m_pTable = m_pSelection.ConvertToTable(1, row_cnt, col_cnt, 0, 0, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 0, 0); } // выравниваем талицу (не содержимое!!!) if (m_pTable == null) { return; } MSWord.Rows pRows = m_pSelection.Rows; pRows.AllowBreakAcrossPages = 0; m_pSelection.Collapse(0); MSWord.Borders pBorders = m_pTable.Borders; if (pBorders == null) { return; } if (bSetBorders) { pBorders.Enable = 1; } else { pBorders.Enable = 0; } if (bUseReturn) { m_pTable.Select(); MSWord.Selection sel = m_pApp.Selection; MSWord.Find find = sel.Find; find.ClearFormatting(); MSWord.Replacement replace = find.Replacement; replace.ClearFormatting(); find.Text = "#enter#"; replace.Text = "^p"; find.MatchCase = false; find.MatchWholeWord = false; find.MatchWildcards = false; find.MatchSoundsLike = false; find.MatchAllWordForms = false; find.Wrap = MSWord.WdFindWrap.wdFindContinue; MSWord.WdReplace repl = MSWord.WdReplace.wdReplaceAll; find.Execute(find.Text, find.MatchCase, find.MatchWholeWord, find.MatchWildcards, find.MatchSoundsLike, find.MatchAllWordForms, Type.Missing, find.Wrap, Type.Missing, replace.Text, repl); } }
// 复制Word.Borders的对象到本类 public void clone(Word.Borders obds) { this.AlwaysInFront = obds.AlwaysInFront; // 进行赋值 this.Count = obds.Count; // 进行赋值 this.Creator = obds.Creator; // 进行赋值 try { this.DistanceFrom = obds.DistanceFrom; // 进行赋值 this.DistanceFromBottom = obds.DistanceFromBottom; // 进行赋值 this.DistanceFromLeft = obds.DistanceFromLeft; // 进行赋值 this.DistanceFromRight = obds.DistanceFromRight; // 进行赋值 this.DistanceFromTop = obds.DistanceFromTop; // 进行赋值 } catch (System.Exception ex) { } finally { } this.Enable = obds.Enable; // 进行赋值 this.EnableFirstPageInSection = obds.EnableFirstPageInSection; // 进行赋值 this.EnableOtherPagesInSection = obds.EnableOtherPagesInSection; // 进行赋值 this.HasHorizontal = obds.HasHorizontal; // 进行赋值 this.HasVertical = obds.HasVertical; // 进行赋值 this.InsideColor = obds.InsideColor; // 进行赋值 this.InsideColorIndex = obds.InsideColorIndex; // 进行赋值 this.InsideLineStyle = obds.InsideLineStyle; // 进行赋值 this.InsideLineWidth = obds.InsideLineWidth; // 进行赋值 this.JoinBorders = obds.JoinBorders; // 进行赋值 this.OutsideColor = obds.OutsideColor; // 进行赋值 this.OutsideColorIndex = obds.OutsideColorIndex; // 进行赋值 this.OutsideLineStyle = obds.OutsideLineStyle; // 进行赋值 this.OutsideLineWidth = obds.OutsideLineWidth; // 进行赋值 this.Shadow = obds.Shadow; // 进行赋值 this.SurroundFooter = obds.SurroundFooter; // 进行赋值 this.SurroundHeader = obds.SurroundHeader; // 进行赋值 this.m_hashBorder.Clear(); Border bd = null; // 将Border的各成员进行赋值 for (int i = (int)WdBorderType.wdBorderVertical; i <= (int)WdBorderType.wdBorderTop; i++) { try { bd = (Border)obds[(WdBorderType)i]; } catch (System.Exception ex) { continue; } if (bd != null) { ClassBorder classBd = new ClassBorder(); classBd.clone(bd); m_hashBorder[i] = classBd; } } return; }