public static bool InsertText(string strText, System.Drawing.Font font, Alignment alignment, bool isAftre, int startNum, int endNum)
{
try
{
Word.Range rng = oDoc.Content;
object start = startNum;
object end = endNum;
rng = oDoc.Range(ref start, ref end);
if (isAftre == true)
{
strText += "\r\n";
}
rng.Text = strText;
rng.Font.Name = font.Name;
rng.Font.Size = font.Size;
if (font.Style == FontStyle.Bold) { rng.Font.Bold = 1; } //设置单元格中字体为粗体
if (alignment == Alignment.居中)
{ rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; }
else if (alignment == Alignment.左对齐)
{ rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; }
else if (alignment == Alignment.右对齐)
{ rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; }
return true;
}
catch (Exception)
{
return false;
}
}
本文转自黄聪博客园博客,原文链接:http://www.cnblogs.com/huangcong/archive/2010/03/26/1697048.html,如需转载请自行联系原作者