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;
}
}