public ResumeFormatObject() { WdColor niceBlueWord = (WdColor)14911564; // RGB is 76, 136, 227 Brush niceBlueBrush = new SolidColorBrush(Color.FromRgb(76, 136, 227)); NameColorWord = niceBlueWord; NameColorBrush = niceBlueBrush; NameFontName = "Segoe UI Light"; NameFontSize = 24; TagLineColorWord = WdColor.wdColorBlack; TagLineColorBrush = Brushes.Black; TagLineFontName = "Segoe UI Light"; TagLineFontSize = 16; HeaderColorWord = niceBlueWord; HeaderColorBrush = niceBlueBrush; HeaderFontName = "Segoe UI Light"; HeaderFontSize = 16; HeaderMargin = new Thickness(0, 10, 0, 10); CategoryColorWord = WdColor.wdColorBlack; CategoryColorBrush = Brushes.Black; CategoryFontName = "Segoe UI Semibold"; CategoryFontSize = 11; JobInfoColorWord = WdColor.wdColorBlack; JobInfoColorBrush = Brushes.Black; JobInfoFontName = "Segoe UI Semibold"; JobInfoFontSize = 12; BodyFontName = "Segoe UI"; BodyFontSize = 11; }
private void TextFormat(string value, ref Application app, WdColor wdColor) { object matchCase = false; object matchWholeWord = true; object matchWildCards = false; object matchSoundsLike = false; object matchAllWordForms = false; object forward = true; object format = false; object matchKashida = false; object matchDiacritics = false; object matchAlefHamza = false; object matchControl = false; object read_only = false; object visible = true; object replace = 2; object wrap = 1; object v1 = (object)value; app.Selection.Find.Execute(value); Range range = app.Selection.Range; range.Font.Color = wdColor; // app.Selection.Find.Execute(ref v1, ref matchCase, ref matchWholeWord, // ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref vReplace, ref replace, // ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl); }
/// <summary> /// Get RGB-color from WdColor /// </summary> /// <param name="wdColor">source color</param> /// <param name="doc">document, where this color from (for appropriate color theme)</param> public static Color GetRGBColor(WdColor wdColor, Document doc) { // separate 1st byte (the most significant) and 3 others to different vars int color = ((int)wdColor) & ((int)0xFFFFFF); int colorType = (int)(((uint)wdColor) >> 24); if (colorType == RGB) { // simple color in OLE format (it's just a BGR - blue, green, red) // let's use standard color translator from system.drawing return(ColorTranslator.FromOle(color)); } else if (colorType == Automatic) { // standard contrast color. In my case I was needed color. But I don't know the proper way to understand which one (black or white) I need to choose. return(Color.White); } else if (colorType == System) { // In ActiveX controls in documents, and in VBA (for UserForm controls, for example) special values for system colours // (for some reason lost in the mists of time these are also called OLE Colors) ranging from 0x80000000 to 0x80000018. // I used system dll function to retrieve system color and then used standard color translator int sysColor = GetSysColor(color); return(ColorTranslator.FromOle(sysColor)); } else if (colorType >= ThemeLow && colorType <= ThemeHigh) { // color based on doc's color theme return(GetThemedColor(colorType, color, doc)); } throw new Exception("Unknown color type"); }
private static bool CreateTable(Document admReleaseNotes, Range rangeWhere, WdColor color, string before, Range rangeToCopy) { if (!IsRangeEmpty(rangeToCopy)) { rangeWhere.InsertParagraphAfter(); rangeWhere = admReleaseNotes.Range(rangeWhere.End, rangeWhere.End); var table = admReleaseNotes.Tables.Add(rangeWhere, 2, 1); table.Cell(1, 1).Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(1, 1).Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(1, 1).Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(1, 1).Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(2, 1).Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(2, 1).Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(2, 1).Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle; table.Cell(2, 1).Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle; table.Shading.BackgroundPatternColor = color; table.Cell(1, 1).Range.Text = before; rangeToCopy.HighlightColorIndex = WdColorIndex.wdNoHighlight; //rangeToCopy.Shading.BackgroundPatternColorIndex = WdColorIndex.wdNoHighlight; rangeToCopy.Copy(); table.Cell(2, 1).Range.Paste(); return(true); } return(false); }
private void BuildFormula(string text, WdColor color = WdColor.wdColorBlack) { Range range = document.Paragraphs[1].Range; range.Text += text; range.Font.Color = color; document.OMaths.Add(range); }
public Paragraph WriteText(string text, int bold, float size, WdColor color) { Word.Paragraph wpPara = WriteText(text); wpPara.Range.Font.Bold = bold; wpPara.Range.Font.Size = size; wpPara.Range.Font.Color = color; return(wpPara); }
/// <summary> /// Sets the background color of all even rows in a table. /// </summary> /// <param name="table"></param> /// <param name="color"></param> public void setAlternatingTableRowStyle(Table table, Color backgroundColor, int indexToStartAt = 2) { WdColor newBackgroundColor = (Microsoft.Office.Interop.Word.WdColor)(backgroundColor.R + 0x100 * backgroundColor.G + 0x10000 * backgroundColor.B); for (int i = indexToStartAt; i <= table.Rows.Count; i = i + 2) { table.Rows[i].Shading.BackgroundPatternColor = newBackgroundColor; } }
public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor,float fontsize) { WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); WordApp.Selection.Font.Color =fontcolor;//����������ɫ WordApp.Selection.Font.Size = fontsize;//���������С WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//���ö��뷽ʽ WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }
/// <summary> /// 当前位置处插入文字 /// </summary> /// <param name="context">文字内容</param> /// <param name="fontSize">字体大小</param> /// <param name="fontColor">字体颜色</param> /// <param name="fontBold">粗体</param> /// <param name="familyName">字体</param> /// <param name="align">对齐方向</param> public void InsertText(string context, int fontSize, WdColor fontColor, int fontBold, string familyName, WdParagraphAlignment align) { //设置字体样式以及方向 wordApp.Application.Selection.Font.Size = fontSize; wordApp.Application.Selection.Font.Bold = fontBold; wordApp.Application.Selection.Font.Color = fontColor; wordApp.Selection.Font.Name = familyName; wordApp.Application.Selection.ParagraphFormat.Alignment = align; wordApp.Application.Selection.TypeText(context); }
private void hideFooter(Section sectionInRange) { try { rangeFooter = sectionInRange.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; wdFooterColor = rangeFooter.Font.Color; setRangeFontColor(rangeFooter, WdColor.wdColorWhite); } catch (Exception) { } }
/// <summary> /// Sets the table row style of rows with a specific table row count. /// </summary> /// <param name="table"></param> /// <param name="cellCount"></param> /// <param name="color"></param> public void setStyleOfTableRowsWithCellCount(Table table, int cellCount, Color color) { WdColor newBackgroundColor = (Microsoft.Office.Interop.Word.WdColor)(color.R + 0x100 * color.G + 0x10000 * color.B); foreach (Row row in table.Rows) { if (row.Cells.Count == cellCount) { row.Shading.BackgroundPatternColor = newBackgroundColor; } } }
public void CreateTextSection(string text, int bold = 0, int spaceAfter = 6, int size = 12, WdColor textColor = WdColor.wdColorBlack) { object range = _doc.Bookmarks.get_Item(ref _endOfDoc).Range; var titleSection = _doc.Content.Paragraphs.Add(ref range); titleSection.Range.Text = text; titleSection.Range.Font.Bold = bold; titleSection.Range.Font.Size = size; titleSection.Range.Font.Color = textColor; titleSection.Format.SpaceAfter = spaceAfter; titleSection.Range.InsertParagraphAfter(); }
////////////////////////////////////////// // 复制ClassShading同名参数值 public void clone(ClassShading shd) { this.BackgroundPatternColor = shd.BackgroundPatternColor; // 复制ClassShading同名参数值 this.BackgroundPatternColorIndex = shd.BackgroundPatternColorIndex; // 复制ClassShading同名参数值 //this.Creator = shd.Creator;// 复制ClassShading同名参数值 this.ForegroundPatternColor = shd.ForegroundPatternColor; // 复制ClassShading同名参数值 this.ForegroundPatternColorIndex = shd.ForegroundPatternColorIndex; // 复制ClassShading同名参数值 this.Texture = shd.Texture; // 复制ClassShading同名参数值 return; }
private void hideText(Word.Document myDoc, object iPage, object iEnd) { object missing = System.Reflection.Missing.Value; object objWhat = Word.WdGoToItem.wdGoToPage; object objWhich = Word.WdGoToDirection.wdGoToAbsolute; object objPage = iPage; Word.Range rangePage = myDoc.GoTo(ref objWhat, ref objWhich, ref objPage, ref missing); rangeText = rangePage; wdTextColor = rangePage.Font.Color; rangePage.End = (int)iEnd; rangePage.Font.Color = WdColor.wdColorWhite; }
//////////////////////////////////////////// // 复制ClassBorder对象的内容 public void clone(ClassBorder obd) { this.ArtStyle = obd.ArtStyle; // 进行赋值 this.ArtWidth = obd.ArtWidth; // 进行赋值 this.Color = obd.Color; // 进行赋值 this.ColorIndex = obd.ColorIndex; // 进行赋值 this.Creator = obd.Creator; // 进行赋值 this.Inside = obd.Inside; // 进行赋值 this.LineStyle = obd.LineStyle; // 进行赋值 this.LineWidth = obd.LineWidth; // 进行赋值 this.Visible = obd.Visible; // 进行赋值 return; }
private void executeFindReplace(Selection currentSelect, int n, WdColor color, string keyWord) { object MissingValue = Type.Missing; object FindText, ReplaceWith, Replace;// FindText = keyWord; ReplaceWith = keyWord;//替换文本 Replace = WdReplace.wdReplaceAll; currentSelect.Find.Replacement.Font.Color = color; currentSelect.Find.Replacement.Font.Bold = n; currentSelect.HomeKey(WdUnits.wdStory, Type.Missing); currentSelect.Find.Execute(ref FindText, ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, ref ReplaceWith, ref Replace, ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue); }
////////////////////////// public void clone(ClassBorders obds) { this.AlwaysInFront = obds.AlwaysInFront; this.Count = obds.Count; this.Creator = obds.Creator; this.DistanceFrom = obds.DistanceFrom; this.DistanceFromBottom = obds.DistanceFromBottom; this.DistanceFromLeft = obds.DistanceFromLeft; this.DistanceFromRight = obds.DistanceFromRight; this.DistanceFromTop = obds.DistanceFromTop; 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(); ClassBorder bd = null; for (int i = (int)WdBorderType.wdBorderVertical; i <= (int)WdBorderType.wdBorderTop; i++) { bd = (ClassBorder)obds[(WdBorderType)i]; if (bd != null) { ClassBorder classBd = new ClassBorder(); classBd.clone(bd); m_hashBorder[i] = classBd; } } return; }
//2012.03.21 Thanh add start /// <summary> /// Set font default for document /// </summary> public void SetDefaultFontFormat(int FontSize, bool isBold, WdColor color) { CurrentSelection.ClearFormatting(); CurrentSelection.Font.Name = "Calibri"; CurrentSelection.Font.Size = FontSize; if (isBold) { CurrentSelection.Font.Bold = 1; } else { CurrentSelection.Font.Bold = 0; } CurrentSelection.Font.Color = color; CurrentSelection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle; CurrentSelection.ParagraphFormat.LineSpacing = 10; CurrentSelection.ParagraphFormat.SpaceAfter = 0; CurrentSelection.ParagraphFormat.SpaceBefore = 0; }
//2012.02.06 Thanh add end /// <summary> /// Searches the bookmark by name and places text at the text /// </summary> /// <param name="BookMarkName"></param> /// <param name="BookMarkText"></param> public void WriteToBookMark(string BookMarkName, string BookMarkText, WdColor bgColor) { object missing = System.Reflection.Missing.Value; try { if (WordDoc.Bookmarks.Exists(BookMarkName)) { object oBookMark = (object)BookMarkName; Range oRange = WordDoc.Bookmarks.get_Item(ref oBookMark).Range; oRange.Text = BookMarkText; oRange.Shading.BackgroundPatternColor = bgColor; } } catch (Exception ex) { Memory.Instance.Error = ex; String err = ex.Message; } }
/// <summary> /// Border all rows of table with specific color /// </summary> /// <param name="oTable"></param> /// <param name="color"></param> public void Border_Table(Table oTable, WdColor color) { //for (int i = 1; i <= oTable.Rows.Count; i++) //{ // Border_row(oTable, i, color); //} //oTable.Rows.Borders.InsideColor = color; oTable.Rows.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows.Borders[WdBorderType.wdBorderLeft].Color = color; oTable.Rows.Borders[WdBorderType.wdBorderTop].Color = color; oTable.Rows.Borders[WdBorderType.wdBorderRight].Color = color; oTable.Rows.Borders[WdBorderType.wdBorderBottom].Color = color; oTable.Rows.Borders[WdBorderType.wdBorderHorizontal].Color = color; oTable.Rows.Borders[WdBorderType.wdBorderVertical].Color = color; }
private void hideHeader(Word.Document myDoc, object iPage) { object missing = System.Reflection.Missing.Value; object objWhat = Word.WdGoToItem.wdGoToPage; object objWhich = Word.WdGoToDirection.wdGoToAbsolute; object objPage = iPage; int iSelections = myDoc.Sections.Count; for (int i = 1; i <= iSelections; i++) { Word.Range rangePage = myDoc.Sections[i].Range; Section sectionInRange = myDoc.Sections[i]; rangePage = sectionInRange.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; rangeHeader = rangePage; hideLines(rangePage); wdHeadColor = rangePage.Font.Color; setRangeFontColor(rangePage, WdColor.wdColorWhite); hideFooter(sectionInRange); } //return sectionInRange; }
private void setUpFormatting() { Color niceBlue = Color.FromRgb(76, 136, 227); headerColor = (WdColor)(niceBlue.R + 0x100 * niceBlue.G + 0x10000 * niceBlue.B); }
public void InsertText(string pText, int pFontSize, WdColor pFontColor, int pFontBold, WdParagraphAlignment pAlign) { this._wordApp.Application.Selection.Font.Size = pFontSize; this._wordApp.Application.Selection.Font.Color = pFontColor; this._wordApp.Application.Selection.Font.Bold = pFontBold; this._wordApp.Application.Selection.ParagraphFormat.Alignment = pAlign; this._wordApp.Application.Selection.ParagraphFormat.SpaceBefore = 7f; this._wordApp.Application.Selection.TypeText(pText); }
/// <summary> /// Border range from one range /// </summary> /// <param name="cell1"></param> /// <param name="cell2"></param> public void Border_row(Table range, int rowPosition, WdColor color) { range.Rows[rowPosition].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle; range.Rows[rowPosition].Borders.OutsideLineWidth = WdLineWidth.wdLineWidth100pt; range.Rows[rowPosition].Borders.OutsideColor = color; }
/// <summary> /// Border top line /// </summary> /// <param name="oTable"></param> /// <param name="row"></param> /// <param name="color"></param> public void Border_Row_OnTop(Table oTable, int row, WdColor color) { oTable.Rows[row].Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle; oTable.Rows[row].Borders[WdBorderType.wdBorderTop].Color = color; }
public void SetFontColor(WdColor color) { this.applicationClass.Selection.Font.Color = (color); }
/// <summary> /// 字体颜色设置 /// </summary> public void FontColor(WdColor color) { wordDoc.Range(ref start, ref end).Font.Color = color; }
/// <summary> /// 设置文本格式 /// </summary> /// <param name="aligh"></param> /// <param name="fontname"></param> /// <param name="fontsize"></param> /// <param name="bold"></param> /// <param name="ital"></param> /// <param name="color"></param> public void SetStyles(WdParagraphAlignment aligh, string fontname, float fontsize, int bold, int ital, WdColor color) { wordDoc.Range(ref start, ref end).ParagraphFormat.Alignment = aligh; wordDoc.Range(ref start, ref end).Font.Name = fontname; wordDoc.Range(ref start, ref end).Font.Size = fontsize; wordDoc.Range(ref start, ref end).Font.Bold = bold; wordDoc.Range(ref start, ref end).Font.Italic = ital; wordDoc.Range(ref start, ref end).Font.Color = color; }
/// <summary> /// 将文本插入到单元格 /// </summary> /// <param name="tNo"></param> /// <param name="row"></param> /// <param name="col"></param> /// <param name="content"></param> /// <param name="aligh"></param> /// <param name="startMod"></param> /// <param name="endMod"></param> /// <param name="color"></param> /// <param name="fontname"></param> /// <param name="bold"></param> /// <param name="fontsize"></param> /// <param name="ital"></param> private void InsertContToCell(int tNo, int row, int col, string content, WdParagraphAlignment aligh, int startMod, int endMod, WdColor color, string fontname, int bold, float fontsize, int ital) { start = wordDoc.Content.End - 1; wordDoc.Tables[tNo].Cell(row, col).Range.Text = content; end = wordDoc.Content.End - endMod; start = int.Parse(end.ToString()) - startMod; SetStyles(aligh, fontname, fontsize, bold, ital, color); }
/// <summary> /// 插入文本 /// </summary> /// <param name="aligh"></param> /// <param name="content"></param> /// <param name="fontsize"></param> /// <param name="bold"></param> /// <param name="fontname"></param> /// <param name="ital"></param> private void InsertContent2(WdParagraphAlignment aligh, string content, float fontsize, int bold, string fontname, int ital, WdColor color) { start = wordDoc.Content.End - 1; end = start; wordDoc.Range(ref start, ref end).InsertAfter(content); end = wordDoc.Content.End; //设置样式 SetStyles(aligh, fontname, fontsize, bold, ital, color); start = wordDoc.Content.End - 1; end = start; }
private void setRangeFontColor(Range range, WdColor color) { range.Font.Color = color; }
/// <summary> /// Shading range from one range /// </summary> /// <param name="cell1"></param> /// <param name="cell2"></param> public void Shading_row(Table range, int rowPosition, WdColor color) { range.Rows[rowPosition].Shading.BackgroundPatternColor = color; }
public void InsertText(string Text, int FontSize, WdColor FontColor, int FontBold, WdParagraphAlignment TextAlignment, string FontName) { WordApp.Application.Selection.Font.Size = FontSize; //字体大小 WordApp.Application.Selection.Font.Bold = FontBold; //是否粗体,0-否,1-是 WordApp.Application.Selection.Font.Color = FontColor; //字体颜色 WordApp.Application.Selection.ParagraphFormat.Alignment = TextAlignment;//字体排布 WordApp.Application.Selection.Font.Name = FontName; //字体名称 WordApp.Application.Selection.TypeText(Text); //文字内容 }