/// <summary> /// 将文本插入到单元格 /// </summary> /// <param name="tNo"></param> /// <param name="aligh"></param> /// <param name="row"></param> /// <param name="col"></param> /// <param name="content"></param> /// <param name="fontname"></param> /// <param name="fontsize"></param> /// <param name="bold"></param> /// <param name="ital"></param> private void InsertContToCell(int tNo, WdParagraphAlignment aligh, int row, int col, string content, string fontname, float fontsize, int bold, int ital) { wordDoc.Tables[tNo].Cell(row, col).Range.Text = content; end = wordDoc.Content.End; SetStyles(aligh, fontname, fontsize, bold, ital); }
public XElement CreateParagraphElement(Paragraph paragraph) { var paragraphStyle = ((Style)paragraph.get_Style()).NameLocal; WdParagraphAlignment alignment = paragraph.Alignment; var alignattr = ParagraphAlignmentParser.GetClass(alignment) ?? ""; var clas = alignattr; if (paragraphStyle == TableHeader) { } else if (paragraphStyle == TableSubhead) { clas += " highlight"; } else if (paragraphStyle == TableSubheadAlternate) { clas += " highlight"; } else if (paragraphStyle == TableTextAlternate) { clas += " small"; } else if (paragraphStyle == TableText) { clas += " small"; } var root = new XElement("p"); root.SetAttributeValue("class", clas); root = CharacterTransformer.GetCharacterStyledElement(root, paragraph, CharacterStyleFactory.GetCharacterStyles(), false); return(root); }
private void SetTextTable(Cell cell, string text, WdParagraphAlignment aligment) { cell.Range.Text = text; cell.Range.Font.Name = "Times New Roman"; cell.Range.Font.Size = 14; cell.Range.ParagraphFormat.Alignment = aligment; }
/// <summary> /// 设置文本格式 /// </summary> /// <param name="aligh">对齐方式</param> /// <param name="fontname">字体名称</param> /// <param name="fontsize">大小</param> /// <param name="bold">粗细</param> /// <param name="ital">斜体</param> public void SetStyles(WdParagraphAlignment aligh, string fontname, float fontsize, int bold, int ital) { 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; }
/// <summary> /// 插入页脚 /// </summary> /// <param name="text"></param> /// <param name="align"></param> public void SetFooter(string text, WdParagraphAlignment align) { this.m_WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; this.m_WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryFooter; this.m_WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(text); //插入文本 this.m_WordApp.Selection.ParagraphFormat.Alignment = align; //设置对齐方式 this.m_WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; // 跳出页眉设置 }
private void SetParaText(int bold, int size, string text, WdParagraphAlignment wAlign) { m_wordApp.Selection.Font.Bold = bold; m_wordApp.Selection.Font.Color = WdColor.wdColorBlack; m_wordApp.Selection.Font.Size = size; m_wordApp.Selection.ParagraphFormat.Alignment = wAlign; m_wordApp.Selection.TypeText(text); }
public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign) { WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;//����������ɫ WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//��������� WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }
/// <summary> /// 添加段落 /// </summary> /// <param name="tt"></param> /// <returns></returns> public Paragraph AddParagraph(WdParagraphAlignment tt) { object r = document.Words.Last; ((Range)r).ParagraphFormat.Alignment = tt; Paragraph tem = document.Paragraphs.Add(ref r); tem.Alignment = tt; return(tem); }
/// <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); }
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; }
public void AddText(Document aDoc, string Text, int Bold, int Italic, WdParagraphAlignment Alignment) { oRng = aDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara = aDoc.Content.Paragraphs.Add(ref oRng); oPara.Range.Text = Text; oPara.Range.Font.Bold = Bold; oPara.Range.Font.Italic = Italic; oPara.Format.Alignment = Alignment; oPara.Format.SpaceAfter = SpaceAfter; oPara.Range.InsertParagraphAfter(); }
private void inputText(string input = "", WdParagraphAlignment param = WdParagraphAlignment.wdAlignParagraphLeft, int bold = 0, int size = 12, int italic = 0, WdUnderline underline = WdUnderline.wdUnderlineNone) { var paragraph = emptyline(1); paragraph.Format.Alignment = param; paragraph.Range.Font.Bold = bold; paragraph.Range.Text = input; paragraph.Range.Font.Size = size; paragraph.Range.Font.Italic = italic; paragraph.Range.Font.Underline = underline; }
/// <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 InsertContent(WdParagraphAlignment aligh, string content, float fontsize, int bold, string fontname, int ital) { wordDoc.Range(ref start, ref end).InsertAfter(content); end = wordDoc.Content.End; //设置样式 SetStyles(aligh, fontname, fontsize, bold, ital); start = wordDoc.Content.End - 1; end = start; }
// 复制保存WORD.ParagraphFormat同名参数值 public void clone(Word.ParagraphFormat srcParaFormat) { this.Alignment = srcParaFormat.Alignment; // 复制保存WORD.ParagraphFormat同名参数值 this.AutoAdjustRightIndent = srcParaFormat.AutoAdjustRightIndent; // 复制保存WORD.ParagraphFormat同名参数值 this.BaseLineAlignment = srcParaFormat.BaseLineAlignment; // 复制保存WORD.ParagraphFormat同名参数值 //this.Borders.clone(srcParaFormat.Borders);// 复制保存WORD.ParagraphFormat同名参数值 this.CharacterUnitFirstLineIndent = srcParaFormat.CharacterUnitFirstLineIndent; // 复制保存WORD.ParagraphFormat同名参数值 this.CharacterUnitLeftIndent = srcParaFormat.CharacterUnitLeftIndent; // 复制保存WORD.ParagraphFormat同名参数值 this.CharacterUnitRightIndent = srcParaFormat.CharacterUnitRightIndent; // 复制保存WORD.ParagraphFormat同名参数值 this.DisableLineHeightGrid = srcParaFormat.DisableLineHeightGrid; // 复制保存WORD.ParagraphFormat同名参数值 this.FarEastLineBreakControl = srcParaFormat.FarEastLineBreakControl; // 复制保存WORD.ParagraphFormat同名参数值 this.FirstLineIndent = srcParaFormat.FirstLineIndent; // 复制保存WORD.ParagraphFormat同名参数值 this.HalfWidthPunctuationOnTopOfLine = srcParaFormat.HalfWidthPunctuationOnTopOfLine; // 复制保存WORD.ParagraphFormat同名参数值 this.HangingPunctuation = srcParaFormat.HangingPunctuation; // 复制保存WORD.ParagraphFormat同名参数值 this.Hyphenation = srcParaFormat.Hyphenation; // 复制保存WORD.ParagraphFormat同名参数值 this.KeepTogether = srcParaFormat.KeepTogether; // 复制保存WORD.ParagraphFormat同名参数值 this.KeepWithNext = srcParaFormat.KeepWithNext; // 复制保存WORD.ParagraphFormat同名参数值 this.LeftIndent = srcParaFormat.LeftIndent; // 复制保存WORD.ParagraphFormat同名参数值 this.LineSpacing = srcParaFormat.LineSpacing; // 复制保存WORD.ParagraphFormat同名参数值 this.LineSpacingRule = srcParaFormat.LineSpacingRule; // 复制保存WORD.ParagraphFormat同名参数值 this.LineUnitAfter = srcParaFormat.LineUnitAfter; // 复制保存WORD.ParagraphFormat同名参数值 this.LineUnitBefore = srcParaFormat.LineUnitBefore; // 复制保存WORD.ParagraphFormat同名参数值 this.MirrorIndents = srcParaFormat.MirrorIndents; // 复制保存WORD.ParagraphFormat同名参数值 this.OutlineLevel = srcParaFormat.OutlineLevel; // 复制保存WORD.ParagraphFormat同名参数值 this.NoLineNumber = srcParaFormat.NoLineNumber; // 复制保存WORD.ParagraphFormat同名参数值 this.PageBreakBefore = srcParaFormat.PageBreakBefore; // 复制保存WORD.ParagraphFormat同名参数值 this.ReadingOrder = srcParaFormat.ReadingOrder; // 复制保存WORD.ParagraphFormat同名参数值 this.RightIndent = srcParaFormat.RightIndent; // 复制保存WORD.ParagraphFormat同名参数值 // this.Shading = srcParaFormat.Shading; //this.Shading.clone(srcParaFormat.Shading); this.SpaceAfter = srcParaFormat.SpaceAfter; // 复制保存WORD.ParagraphFormat同名参数值 this.SpaceAfterAuto = srcParaFormat.SpaceAfterAuto; // 复制保存WORD.ParagraphFormat同名参数值 this.SpaceBefore = srcParaFormat.SpaceBefore; // 复制保存WORD.ParagraphFormat同名参数值 this.SpaceBeforeAuto = srcParaFormat.SpaceBeforeAuto; // 复制保存WORD.ParagraphFormat同名参数值 // this.TabStops = srcParaFormat.TabStops; this.TextboxTightWrap = srcParaFormat.TextboxTightWrap; // 复制保存WORD.ParagraphFormat同名参数值 this.WidowControl = srcParaFormat.WidowControl; // 复制保存WORD.ParagraphFormat同名参数值 this.WordWrap = srcParaFormat.WordWrap; // 复制保存WORD.ParagraphFormat同名参数值 return; }
public static string GetClass(WdParagraphAlignment alignment) { switch (alignment) { case WdParagraphAlignment.wdAlignParagraphCenter: return("aligncenter"); case WdParagraphAlignment.wdAlignParagraphLeft: return(""); case WdParagraphAlignment.wdAlignParagraphRight: return("alignright"); default: return(null); } }
static void CreatePara(Document d, string text, WdParagraphAlignment alignment = WdParagraphAlignment.wdAlignParagraphLeft, bool bold = false, float fs = 11f) { object missing = Missing.Value; var p = d.Content.Paragraphs.Add(ref missing); p.LineSpacing = 1.5f; p.Range.Font.Name = "Consolas"; p.Range.Font.Size = fs; p.Range.Font.Bold = bold ? 1 : 0; p.Range.Text = text; if (text.Contains(":")) { object objStart = p.Range.Start; object objEnd = p.Range.Start + text.IndexOf(":"); var rngBold = d.Range(ref objStart, ref objEnd); rngBold.Bold = 1; } p.Alignment = alignment; p.Range.InsertParagraphAfter(); }
//private static void AddHeader1(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign) //{ // Object oMissing = System.Reflection.Missing.Value; // WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; // WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; // Microsoft.Office.Interop.Word.Shape textBox = WordApp.ActiveDocument.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationVertical, 150, 10, 40, 40); // textBox.TextFrame.TextRange.Text = HeaderText; // WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; //} private static void AddFooterWord(Application WordApp, string fileId, WdParagraphAlignment wdAlign, Document document) { // TODO: add footer to every page. look into using document.sections() something float pageHeight = (float)document.ActiveWindow.Selection.PageSetup.PageHeight; Object oMissing = System.Reflection.Missing.Value; WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryFooter; Microsoft.Office.Interop.Word.Shape tagLineLabel = WordApp.ActiveDocument.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 100, pageHeight - 25, 150, 25); tagLineLabel.TextFrame.TextRange.Text = "Printed with \u2764 by Preasy"; tagLineLabel.Line.Visible = MsoTriState.msoFalse; Microsoft.Office.Interop.Word.Shape fileIdLabel = WordApp.ActiveDocument.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 20, pageHeight - 25, 75, 25); fileIdLabel.TextFrame.TextRange.Text = fileId; fileIdLabel.Line.Visible = MsoTriState.msoFalse; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }
public void InsertPicture(string picturePath, float width, float hight, WdParagraphAlignment align) { object unite = MSWord.WdUnits.wdStory; Object Nothing = Missing.Value; Application.Selection.EndKey(ref unite, ref Nothing); //将光标移动到文档末尾 //要向Word文档中插入图片的位置 Object range = wordDoc.Paragraphs.Last.Range; //定义该插入的图片是否为外部链接 Object linkToFile = false; //默认,这里貌似设置为bool类型更清晰一些 //定义要插入的图片是否随Word文档一起保存 Object saveWithDocument = true; //默认 //使用InlineShapes.AddPicture方法(【即“嵌入型”】)插入图片 InlineShape shape = wordDoc.InlineShapes.AddPicture(picturePath, ref linkToFile, ref saveWithDocument, ref range); wordApp.Selection.ParagraphFormat.Alignment = align;// //设置图片宽高的绝对大小 if (width != -1) { wordDoc.InlineShapes[1].Width = width; } if (hight != -1) { wordDoc.InlineShapes[1].Height = hight; } try { wordDoc.Paragraphs.Last.Range.set_Style("正文"); } catch (Exception ex) { wordDoc.Paragraphs.Last.Range.set_Style("Normal"); } shape.Borders.Enable = 12; //shape.ConvertToShape().WrapFormat.Type = MSWord.WdWrapType.wdWrapSquare;//四周环绕的方式 }
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); }
public void SetFont(float fontSize, WdParagraphAlignment alignment) { wordDoc.Paragraphs.Last.Range.Font.Size = fontSize; wordDoc.Paragraphs.Last.Range.Font.Name = "微软雅黑"; wordDoc.Paragraphs.Last.Range.ParagraphFormat.Alignment = alignment; }
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); //文字内容 }
/// <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); }
/// <summary> /// 设置单元格内容 /// </summary> /// <param name="_c"></param> /// <param name="v"></param> /// <param name="align">对齐方式</param> public void SetCellValue(Cell _c, string v, WdParagraphAlignment align) { wordApp.Selection.ParagraphFormat.Alignment = align; _c.Range.Text = v; }
public static void PrintWord(string docPath, PrintJobModel printJob) { try { Microsoft.Office.Interop.Word.Document document; //System.Windows.Forms.MessageBox.Show("Just before word.Document.Open"); document = word.Documents.Open(FileName: docPath); Debug.WriteLine(document.ActiveWindow.Selection.PageSetup.PageHeight); //String HeaderText = "# 028 9461"; String HeaderText = "# " + printJob.Id.ToString(); WdParagraphAlignment wdAlign = WdParagraphAlignment.wdAlignParagraphLeft; //AddFooterWord(word, HeaderText, wdAlign, document); { //System.Windows.Forms.MessageBox.Show("Just before word.Document.PrintOut()"); //bool manualDuplexPrint = false; //switch (printJob.Print_Feature) //{ // case "SINGLESIDE": // manualDuplexPrint = false; // break; // case "DOUBLESIDE": // manualDuplexPrint = true; // break; // default: // System.Windows.Forms.MessageBox.Show("In PrintDocument switch case: Default"); // break; //} } string tempDir = @"C:\ProgramData\Preasy\"; string tempDocumentPath = tempDir + printJob.Id.ToString() + @"w2pinterop.pdf"; try { //document.SaveAs2(FileName: tempDocumentPath, FileFormat: WdSaveFormat.wdFormatPDF); document.SaveAs(FileName: tempDocumentPath, FileFormat: WdSaveFormat.wdFormatPDF); //System.Windows.Forms.MessageBox.Show("Saving as pdf"); //document.ExportAsFixedFormat(OutputFileName: tempDocumentPath, ExportFormat: WdExportFormat.wdExportFormatPDF, OpenAfterExport: false, OptimizeFor: WdExportOptimizeFor.wdExportOptimizeForPrint); } catch (Exception e) { Console.WriteLine("Message: " + e.Message); System.Windows.Forms.MessageBox.Show(e.Message); //System.Windows.Forms.MessageBox.Show("Data: " + e.Data); //System.Windows.Forms.MessageBox.Show("InnerException: " + e.InnerException); } //document.PrintOut(OutputFileName: tempDocumentPath, PrintToFile: true); object saveOption = WdSaveOptions.wdDoNotSaveChanges; object originalFormat = WdOriginalFormat.wdOriginalDocumentFormat; object routeDocument = false; document.Close(ref saveOption, ref originalFormat, ref routeDocument); File.Delete(docPath); int i = 0; while (!IsFileReady(tempDocumentPath)) { Debug.WriteLine(i.ToString()); i += 1; } PrintPdf(tempDocumentPath, printJob); File.Delete(tempDocumentPath); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); Console.WriteLine("{0} Exception caught.", e); //word.Quit(); } finally { //word.Quit(); } }
private static void AddPara(_Document oDoc, string text, int size = 10, int bold = 0, WdLineSpacing spacing = WdLineSpacing.wdLineSpaceSingle, WdParagraphAlignment alignment = WdParagraphAlignment.wdAlignParagraphCenter) { Paragraph oPara1 = oDoc.Content.Paragraphs.Add(); oPara1.Range.Text = text; oPara1.Range.Font.Bold = 0; oPara1.Range.Font.Size = 10; oPara1.Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle; oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; oPara1.SpaceAfter = 0; oPara1.Range.InsertParagraphAfter(); }
/// <summary> /// 设置单元格的文本和对齐方式 /// </summary> /// <param name="cell">单元格</param> /// <param name="text">文本</param> /// <param name="align">对齐方式</param> public void SetCellText(Cell cell, string text, WdParagraphAlignment align) { cell.Range.Text = text; cell.Range.ParagraphFormat.Alignment = align; }
public static void AddPAragraph(Paragraph paragraph, string text, int spaceBefore, int spaceAfter, int flagFontBold, int fontSize, WdParagraphAlignment paragraphAlignment, WdColorIndex highlightColor = WdColorIndex.wdAuto) { paragraph.Range.Text = text; paragraph.Format.SpaceBefore = spaceBefore; paragraph.Format.SpaceAfter = spaceAfter; paragraph.Range.Font.Bold = flagFontBold; paragraph.Range.Font.Size = fontSize; paragraph.Range.HighlightColorIndex = highlightColor; paragraph.Format.Alignment = paragraphAlignment; paragraph.Range.InsertParagraphAfter(); }
public void SetAlignment(WdParagraphAlignment alignment) { pWnd.Selection.ParagraphFormat.Alignment = alignment; }
private void SetCellText(int bold, int size, string text, WdParagraphAlignment wAlign, WdCellVerticalAlignment vAlign) { m_wordApp.Selection.Cells.VerticalAlignment = vAlign; SetParaText(bold, size, text, wAlign); }
public int decodeFromString(Hashtable hashFeatures) { if (hashFeatures == null || hashFeatures.Count == 0) { return(1); } String strVal = ""; int nVal = 0, nDefaultVal = 0; float fVal = 0.0f; strVal = (String)hashFeatures["ParaFmt_AddSpaceBetweenFarEastAndAlpha"]; if (int.TryParse(strVal, out nVal)) { AddSpaceBetweenFarEastAndAlpha = nVal; } else { AddSpaceBetweenFarEastAndAlpha = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_AddSpaceBetweenFarEastAndDigit"]; if (int.TryParse(strVal, out nVal)) { AddSpaceBetweenFarEastAndDigit = nVal; } else { AddSpaceBetweenFarEastAndDigit = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_Alignment"]; if (int.TryParse(strVal, out nVal)) { Alignment = (WdParagraphAlignment)nVal; } else { Alignment = WdParagraphAlignment.wdAlignParagraphDistribute; } strVal = (String)hashFeatures["ParaFmt_AutoAdjustRightIndent"]; if (int.TryParse(strVal, out nVal)) { AutoAdjustRightIndent = nVal; } else { AutoAdjustRightIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_BaseLineAlignment"]; if (int.TryParse(strVal, out nVal)) { BaseLineAlignment = (WdBaselineAlignment)nVal; } else { BaseLineAlignment = WdBaselineAlignment.wdBaselineAlignAuto; } strVal = (String)hashFeatures["ParaFmt_CharacterUnitFirstLineIndent"]; if (float.TryParse(strVal, out fVal)) { CharacterUnitFirstLineIndent = fVal; } else { CharacterUnitFirstLineIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_CharacterUnitLeftIndent"]; if (float.TryParse(strVal, out fVal)) { CharacterUnitLeftIndent = fVal; } else { CharacterUnitLeftIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_CharacterUnitRightIndent"]; if (float.TryParse(strVal, out fVal)) { CharacterUnitRightIndent = fVal; } else { CharacterUnitRightIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_DisableLineHeightGrid"]; if (int.TryParse(strVal, out nVal)) { DisableLineHeightGrid = nVal; } else { DisableLineHeightGrid = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_FarEastLineBreakControl"]; if (int.TryParse(strVal, out nVal)) { FarEastLineBreakControl = nVal; } else { FarEastLineBreakControl = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_FirstLineIndent"]; if (float.TryParse(strVal, out fVal)) { FirstLineIndent = fVal; } else { FirstLineIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_HalfWidthPunctuationOnTopOfLine"]; if (int.TryParse(strVal, out nVal)) { HalfWidthPunctuationOnTopOfLine = nVal; } else { HalfWidthPunctuationOnTopOfLine = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_HangingPunctuation"]; if (int.TryParse(strVal, out nVal)) { HangingPunctuation = nVal; } else { HangingPunctuation = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_Hyphenation"]; if (int.TryParse(strVal, out nVal)) { Hyphenation = nVal; } else { Hyphenation = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_KeepTogether"]; if (int.TryParse(strVal, out nVal)) { KeepTogether = nVal; } else { KeepTogether = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_KeepWithNext"]; if (int.TryParse(strVal, out nVal)) { KeepWithNext = nVal; } else { KeepWithNext = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_LeftIndent"]; if (float.TryParse(strVal, out fVal)) { LeftIndent = fVal; } else { LeftIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_LineSpacing"]; if (float.TryParse(strVal, out fVal)) { LineSpacing = fVal; } else { LineSpacing = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_LineSpacingRule"]; if (int.TryParse(strVal, out nVal)) { LineSpacingRule = (WdLineSpacing)nVal; } else { LineSpacingRule = WdLineSpacing.wdLineSpaceSingle; } strVal = (String)hashFeatures["ParaFmt_LineUnitAfter"]; if (float.TryParse(strVal, out fVal)) { LineUnitAfter = fVal; } else { LineUnitAfter = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_LineUnitBefore"]; if (float.TryParse(strVal, out fVal)) { LineUnitBefore = fVal; } else { LineUnitBefore = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_MirrorIndents"]; if (int.TryParse(strVal, out nVal)) { MirrorIndents = nVal; } else { MirrorIndents = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_NoLineNumber"]; if (int.TryParse(strVal, out nVal)) { NoLineNumber = nVal; } else { NoLineNumber = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_OutlineLevel"]; if (int.TryParse(strVal, out nVal)) { OutlineLevel = (WdOutlineLevel)nVal; } else { OutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText; } strVal = (String)hashFeatures["ParaFmt_PageBreakBefore"]; if (int.TryParse(strVal, out nVal)) { PageBreakBefore = nVal; } else { PageBreakBefore = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_ReadingOrder"]; if (int.TryParse(strVal, out nVal)) { ReadingOrder = (WdReadingOrder)nVal; } else { ReadingOrder = WdReadingOrder.wdReadingOrderLtr; } strVal = (String)hashFeatures["ParaFmt_RightIndent"]; if (float.TryParse(strVal, out fVal)) { RightIndent = fVal; } else { RightIndent = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_SpaceAfter"]; if (float.TryParse(strVal, out fVal)) { SpaceAfter = fVal; } else { SpaceAfter = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_SpaceAfterAuto"]; if (int.TryParse(strVal, out nVal)) { SpaceAfterAuto = nVal; } else { SpaceAfterAuto = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_SpaceBefore"]; if (float.TryParse(strVal, out fVal)) { SpaceBefore = fVal; } else { SpaceBefore = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_SpaceBeforeAuto"]; if (int.TryParse(strVal, out nVal)) { SpaceBeforeAuto = nVal; } else { SpaceBeforeAuto = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_TextboxTightWrap"]; if (int.TryParse(strVal, out nVal)) { TextboxTightWrap = (WdTextboxTightWrap)nVal; } else { TextboxTightWrap = WdTextboxTightWrap.wdTightNone; } strVal = (String)hashFeatures["ParaFmt_WidowControl"]; if (int.TryParse(strVal, out nVal)) { WidowControl = nVal; } else { WidowControl = nDefaultVal; } strVal = (String)hashFeatures["ParaFmt_WordWrap"]; if (int.TryParse(strVal, out nVal)) { WordWrap = nVal; } else { WordWrap = nDefaultVal; } return(0); }
/// <summary> /// Método para criar novos parágrafos no documento Word /// </summary> /// <param name="text">Texto a ser adicionado no parágrafo</param> /// <param name="spaceBefore">Formatação do parágrafo. Espaçamento a ser adicionado antes do parágraço</param> /// <param name="spaceAfter">Formatação do parágrafo. Espaçamento a ser adicionado depois do parágraço</param> /// <param name="flagFontBold">Formatação da fonte. Inteiro que identifica se o texto deve estar em negrito. 0 - Texto normal; 1 - Texto em negrito</param> /// <param name="fontSize">Formatação da fonte. Tamanho da fonte presente no parágrafo</param> /// <param name="paragraphAlignment">Formatação do parágrafo. Alinhamento a sser utilizado para o parágrafo a ser adicionado</param> /// <param name="doc">Documento a ser inserido o parágrafo</param> /// <param name="missing"></param> public static void AddPAragraph(string text, int spaceBefore, int spaceAfter, int flagFontBold, int fontSize, WdParagraphAlignment paragraphAlignment, Document doc, ref object missing) { Paragraph paragraph = doc.Content.Paragraphs.Add(ref missing); paragraph.Range.Text = text; paragraph.Format.SpaceBefore = spaceBefore; paragraph.Format.SpaceAfter = spaceAfter; paragraph.Range.Font.Bold = flagFontBold; paragraph.Range.Font.Size = fontSize; paragraph.Format.Alignment = paragraphAlignment; paragraph.Range.InsertParagraphAfter(); }
public void Write(Range range, string text, float fontsize = 14, int bold = 0, int italic = 0, WdParagraphAlignment alignment = WdParagraphAlignment.wdAlignParagraphJustify, WdUnderline underline = WdUnderline.wdUnderlineNone, float before = 0, float after = 0) { range.Font.Name = "Times New Roman"; range.Text = text; range.Bold = bold; range.Italic = italic; range.Underline = underline; range.ParagraphFormat.SpaceBefore = before; range.ParagraphFormat.SpaceAfter = after; range.ParagraphFormat.Alignment = alignment; range.Font.Size = fontsize; }
/// <summary> /// 设置单元格内容 /// </summary> /// <param name="wordApp">word程序</param> /// <param name="cell">单元格</param> /// <param name="text">内容</param> /// <param name="align">对齐方式</param> public static void SetCellValue(Microsoft.Office.Interop.Word.Application wordApp, Cell cell, string text, WdParagraphAlignment align) { wordApp.Selection.ParagraphFormat.Alignment = align; cell.Range.Text = text; }