public void AddTitle(string title, Model.Style style) { //Word段落 Word.Paragraph p; p = document.Content.Paragraphs.Add(ref nothing); //设置段落中的内容文本 p.Range.Text = title; if (style != null) { object bContinuousPrev = false;//是否为大圆点 true 大圆点 object a = 1; object oName = ""; object listFormat = Word.WdDefaultListBehavior.wdWord10ListBehavior; p.Range.Font.Name = style.Font; p.Range.Font.Size = style.Size == 0 ? p.Range.Font.Size : style.Size; p.Range.Font.Color = style.FontColor; p.Range.Font.Bold = style.FontStyle == System.Drawing.FontStyle.Bold ? 1 : 0; if (style.LineSpac > 0) { p.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceAtLeast; //行距最小值 p.LineSpacing = style.LineSpac; //行距28磅 } p.CharacterUnitFirstLineIndent = style.Indent == 0 ? p.CharacterUnitFirstLineIndent : style.Indent; //缩进2字符 //Word.ListGallery l = application.ListGalleries[Word.WdListGalleryType.wdOutlineNumberGallery]; //l.ListTemplates[ref a].ListLevels[1].NumberFormat = style.NumberFormat; Word.ListTemplate it = application.ActiveDocument.ListTemplates.Add(ref bContinuousPrev, ref oName); it.ListLevels[1].NumberFormat = style.NumberFormat; //application.ActiveDocument. //p.Range.ListFormat.ListTemplate..ApplyListTemplate(l, ref bContinuousPrev, ref a, ref listFormat); } //添加到末尾 p.Range.InsertParagraphAfter(); }
private void SetTableStyle(int tableindex, Model.Style style) { object prop = "网格型"; application.Selection.Tables[tableindex].set_Style(ref prop); application.Selection.Tables[tableindex].ApplyStyleHeadingRows = true; application.Selection.Tables[tableindex].ApplyStyleLastRow = false; application.Selection.Tables[tableindex].ApplyStyleFirstColumn = true; application.Selection.Tables[tableindex].ApplyStyleLastColumn = false; application.Selection.Tables[tableindex].ApplyStyleRowBands = true; application.Selection.Tables[tableindex].ApplyStyleColumnBands = false; application.Selection.Tables[tableindex].Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone; application.Selection.Tables[tableindex].Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone; application.Selection.Tables[tableindex].Borders[Word.WdBorderType.wdBorderVertical].LineStyle = Word.WdLineStyle.wdLineStyleNone; //application.Selection.Tables[tableindex].Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter; application.Selection.Tables[tableindex].PreferredWidthType = Word.WdPreferredWidthType.wdPreferredWidthPoints; application.Selection.Tables[tableindex].PreferredWidth = application.CentimetersToPoints(15.6f); application.Selection.Tables[tableindex].Rows.WrapAroundText = 1; application.Selection.Tables[tableindex].Range.Font.Name = style.Font; application.Selection.Tables[tableindex].Range.Font.Name = style.Font; application.Selection.Tables[tableindex].Range.Font.Size = style.Size; application.Selection.Tables[tableindex].Range.Font.Color = style.FontColor; application.Selection.Tables[tableindex].Range.Font.Bold = style.FontStyle == System.Drawing.FontStyle.Bold ? 1 : 0; }
public void AddTable(string content, Model.Style style) { object defaultTableBehavior = Word.WdDefaultTableBehavior.wdWord9TableBehavior; object autofitbehavior = Word.WdAutoFitBehavior.wdAutoFitFixed; GoToTheEnd(); Word.Table tablea = null; if (!string.IsNullOrWhiteSpace(content)) { tablea = application.ActiveDocument.Tables.Add(application.Selection.Range, 1, 3, ref defaultTableBehavior, ref autofitbehavior); application.Selection.ParagraphFormat.SpaceBefore = 0f; application.Selection.ParagraphFormat.SpaceAfterAuto = 0; application.Selection.ParagraphFormat.FirstLineIndent = application.CentimetersToPoints(0.3f); GoToTheEnd(); } var tableb = application.ActiveDocument.Tables.Add(application.Selection.Range, 1, 2, ref defaultTableBehavior, ref autofitbehavior); application.Selection.ParagraphFormat.SpaceBefore = 0f; application.Selection.ParagraphFormat.SpaceAfterAuto = 0; application.Selection.ParagraphFormat.FirstLineIndent = application.CentimetersToPoints(0.3f); SetTableStyle(1, style); application.Selection.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast; application.Selection.Rows.Height = application.CentimetersToPoints(1f); application.Selection.Columns.PreferredWidthType = Word.WdPreferredWidthType.wdPreferredWidthAuto; application.Selection.Columns.PreferredWidth = 0; application.Selection.Cells.PreferredWidthType = Word.WdPreferredWidthType.wdPreferredWidthAuto; application.Selection.Cells.PreferredWidth = 0; application.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter; if (tablea != null) { var cella = tablea.Cell(1, 1); cella.Width = 60f; cella.Range.Text = "抄送:"; var celld = tablea.Cell(1, 2); celld.Range.Text = content; } var cellc = tableb.Cell(1, 2); cellc.Range.Text = DateTime.Today.ToString("yyyy年MM月dd日") + "印发"; //cellc.Range.ShapeRange.Align(Microsoft.Office.Core.MsoAlignCmd.msoAlignRights, 0); cellc.Range.FitTextWidth = application.CentimetersToPoints(4.00f); var cellb = tableb.Cell(1, 1); cellb.Range.Text = "国网重庆市电力公司永川供电分公司办公室"; cellb.Range.ShapeRange.Align(Microsoft.Office.Core.MsoAlignCmd.msoAlignLefts, 0); //cellb.Range.FitTextWidth = application.CentimetersToPoints(1.22f); //row = application.Selection.Tables[1].Rows[2]; //row.Cells[1].Range.Text = "国网重庆市电力公司永川供电分公司办公室"; //row.Cells[1].Range.Application.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify; //row.Cells[2].Range.Text = DateTime.Today.ToString("yyyy年MM月dd日")+"印发"; //row.Cells[2].Range.Application.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; }
public void AddContent(string content, Model.Style style) { Word.Paragraph p; p = document.Content.Paragraphs.Add(ref nothing); p.Range.Text = content; if (style != null) { p.Range.Font.Name = style.Font; p.Range.Font.Size = style.Size == 0 ? p.Range.Font.Size : style.Size; if (style.LineSpac > 0) { p.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceAtLeast; //行距最小值 p.LineSpacing = style.LineSpac; //行距28磅 } p.Format.Alignment = style.Align; p.Range.Font.Color = style.FontColor; p.Range.Font.Bold = style.FontStyle == System.Drawing.FontStyle.Bold ? 1 : 0; p.CharacterUnitFirstLineIndent = style.Indent == 0 ? p.CharacterUnitFirstLineIndent : style.Indent; //缩进2字符 p.Range.Font.Scaling = style.Scaling == 0 ? 100 : style.Scaling; } p.Range.InsertParagraphAfter(); }
public Form2() { InitializeComponent(); DDLSource source = new DDLSource() { Text = "新增", Index = 0 }; //comboBox1.ValueMember = "Index"; //comboBox1.DisplayMember = "Text"; //comboBox1.Items.Add(source); dDLSourceBindingSource.DataSource = source; load1(); load2(); return; WordUtil word = new WordUtil(); var style = new Model.Style { FontName = "抄送", Font = "方正仿宋_GBK", Size = 14f }; word.AddTable("x x x x x x x x,x x x x x x x x。", style); word.SaveAndClose("D:\\1234.doc"); _notice = new Notice(); Title t = new Title() { ID = 1, Parent = 0, TContent = new Content() { ConContent = "一级标题", ConType = "一级标题", TitleIndex = 0 } }; Title t1 = new Title() { ID = 2, Parent = 0, TContent = new Content() { ConContent = "一级标题", ConType = "一级标题", TitleIndex = 1 } }; Title tt = new Title() { ID = 3, Parent = 1, TContent = new Content() { ConContent = "二级标题", ConType = "二级标题", TitleIndex = 0 } }; Title tt1 = new Title() { ID = 4, Parent = 1, TContent = new Content() { ConContent = "二级标题", ConType = "二级标题", TitleIndex = 1 } }; Title ttt = new Title() { ID = 5, Parent = 3, TContent = new Content() { ConContent = "三级标题", ConType = "三级标题", TitleIndex = 0 } }; Title ttt1 = new Title() { ID = 6, Parent = 4, TContent = new Content() { ConContent = "三级标题", ConType = "三级标题", TitleIndex = 1 } }; _notice.Zhenwen = new List <Title>(); _notice.Zhenwen.Add(t); _notice.Zhenwen.Add(t1); _notice.Zhenwen.Add(tt); _notice.Zhenwen.Add(tt1); _notice.Zhenwen.Add(ttt); _notice.Zhenwen.Add(ttt1); InitTree(null); }